This is a migrated thread and some comments may be shown as answers.

RadFlowDocumentEditor insert list

5 Answers 442 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
zake
Top achievements
Rank 1
zake asked on 10 Dec 2018, 09:40 AM

Please help me, I wanna generate word document contain  bullet and numberring using RadFlowDocumentEditor ? I tried but arrangement is so messi.

if I used section.block, it was success

               var paragraph1 = section.Blocks.AddParagraph();
                paragraph1.Inlines.AddRun("");
                paragraph1.ListId = list.Id;
                paragraph1.ListLevel = 0;

 

001.private void button1_Click(object sender, EventArgs e)
002.        {
003.            RadFlowDocument document = new RadFlowDocument();
004.            //Section section = document.Sections.AddSection();
005. 
006.            DocxFormatProvider provider = new DocxFormatProvider();
007.            RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
008. 
009.            string reportFilePathDir = Path.Combine(Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\")), "OutputTes", "listandtable.docx");
010.            // Start to Generate Monber Doc
011.            using (Stream output = new FileStream(reportFilePathDir, FileMode.OpenOrCreate))
012.            {
013.                //1. Table
014.                GenTableInDoc(document, editor);
015. 
016. 
017.                //2. list
018.                List list = document.Lists.Add(ListTemplateType.NumberedDefault);
019.                 
020.                var paragraphTop = editor.InsertParagraph();
021.                paragraphTop.Inlines.AddRun("Note that the numbering the paragraph.");
022. 
023.                var paragraphTop1 = editor.InsertParagraph();
024.                paragraphTop1.Inlines.AddRun("okeh <p color=\"red\">this is red color</p> <font color=\"red\">This is some text!</font>");
025. 
026. 
027.                var paragraph1 = editor.InsertParagraph();
028.                paragraph1.Inlines.AddRun("Note that the numbering the paragraph.");
029.                paragraph1.ListId = list.Id;
030.                paragraph1.ListLevel = 0;
031. 
032.                var paragraph2 = editor.InsertParagraph();
033.                paragraph2.Inlines.AddRun("Note that the numbering the paragraph.");
034.                paragraph2.ListId = list.Id;
035.                paragraph2.ListLevel = 1;
036. 
037.                var paragraph3 = editor.InsertParagraph();
038.                paragraph3.Inlines.AddRun("Note that the numbering the paragraph.");
039.                paragraph3.ListId = list.Id;
040.                paragraph3.ListLevel = 1;
041. 
042.                var paragraph4 = editor.InsertParagraph();
043.                paragraph4.Inlines.AddRun("Note that the numbering the paragraph.");
044.                paragraph4.ListId = list.Id;
045.                paragraph4.ListLevel = 2;
046. 
047.                var paragraphBottom = editor.InsertParagraph();
048.                paragraphBottom.Inlines.AddRun("Note that the numbering the paragraph.");
049. 
050. 
051.                //3. Table
052.                GenTableInDoc(document, editor);
053. 
054.                //*EXPORT TO WORD
055.                provider.Export(document, output);
056.            }
057. 
058.            MessageBox.Show(this, "ok");
059.        }
060. 
061. 
062.public static void GenTableInDoc(RadFlowDocument document, RadFlowDocumentEditor editor)
063.        {
064.            Style style = new Style("ok", StyleType.Table);
065.            style.CharacterProperties.ForegroundColor.LocalValue = new ThemableColor(System.Windows.Media.Colors.Black);
066.            style.CharacterProperties.FontWeight.LocalValue = FontWeights.Bold;
067.            style.CharacterProperties.FontSize.LocalValue = 9;
068. 
069.            document.StyleRepository.Add(style);
070. 
071.            var section = document.Sections.AddSection();
072. 
073.            Table table = editor.InsertTable();
074.            //Table table = section.Blocks.AddTable();
075.            table.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 100);
076. 
077.            document.StyleRepository.AddBuiltInStyle(BuiltInStyleNames.TableGridStyleId);
078.            table.StyleId = BuiltInStyleNames.TableGridStyleId;
079. 
080.            //header
081.            TableRow rowHeader = table.Rows.AddTableRow();
082.            rowHeader.RepeatOnEveryPage = true;
083. 
084.            //number cell header
085.            TableCell cellNumberHeader = rowHeader.Cells.AddTableCell();
086.            cellNumberHeader.Blocks.AddParagraph().Inlines.AddRun("Header").FontWeight = FontWeights.Bold; cellNumberHeader.Shading.BackgroundColor = new ThemableColor(System.Windows.Media.Colors.LightGray);
087.            cellNumberHeader.RowSpan = 2; cellNumberHeader.ColumnSpan = 1;
088. 
089.            cellNumberHeader = rowHeader.Cells.AddTableCell();
090.            cellNumberHeader.Blocks.AddParagraph().Inlines.AddRun("Header").FontWeight = FontWeights.Bold; cellNumberHeader.Shading.BackgroundColor = new ThemableColor(System.Windows.Media.Colors.LightGray);
091.            cellNumberHeader.RowSpan = 2; cellNumberHeader.ColumnSpan = 1;
092. 
093.            cellNumberHeader = rowHeader.Cells.AddTableCell();
094.            cellNumberHeader.Blocks.AddParagraph().Inlines.AddRun("Header").FontWeight = FontWeights.Bold; cellNumberHeader.Shading.BackgroundColor = new ThemableColor(System.Windows.Media.Colors.LightGray);
095.            cellNumberHeader.RowSpan = 1; cellNumberHeader.ColumnSpan = 3;
096. 
097.            cellNumberHeader = rowHeader.Cells.AddTableCell();
098.            cellNumberHeader.Blocks.AddParagraph().Inlines.AddRun("Header").FontWeight = FontWeights.Bold; cellNumberHeader.Shading.BackgroundColor = new ThemableColor(System.Windows.Media.Colors.LightGray);
099.            cellNumberHeader.RowSpan = 2; cellNumberHeader.ColumnSpan = 1;
100. 
101.            cellNumberHeader = rowHeader.Cells.AddTableCell();
102.            cellNumberHeader.Blocks.AddParagraph().Inlines.AddRun("Header").FontWeight = FontWeights.Bold; cellNumberHeader.Shading.BackgroundColor = new ThemableColor(System.Windows.Media.Colors.LightGray);
103.            cellNumberHeader.RowSpan = 2; cellNumberHeader.ColumnSpan = 1;
104. 
105.            TableRow rowHeader1 = table.Rows.AddTableRow();
106.            rowHeader1.RepeatOnEveryPage = true;
107. 
108.            TableCell c1 = rowHeader1.Cells.AddTableCell();
109.            c1.Blocks.AddParagraph().Inlines.AddRun("Header").FontWeight = FontWeights.Bold; c1.Shading.BackgroundColor = new ThemableColor(System.Windows.Media.Colors.LightGray);
110.            c1 = rowHeader1.Cells.AddTableCell();
111.            c1.Blocks.AddParagraph().Inlines.AddRun("Header").FontWeight = FontWeights.Bold; c1.Shading.BackgroundColor = new ThemableColor(System.Windows.Media.Colors.LightGray);
112.            c1 = rowHeader1.Cells.AddTableCell();
113.            c1.Blocks.AddParagraph().Inlines.AddRun("Header").FontWeight = FontWeights.Bold; c1.Shading.BackgroundColor = new ThemableColor(System.Windows.Media.Colors.LightGray);
114. 
115.            TableRow rowHeader2 = table.Rows.AddTableRow();
116.            TableCell c2 = rowHeader2.Cells.AddTableCell();
117.            c2.Blocks.AddParagraph().Inlines.AddRun("");
118.            c2 = rowHeader2.Cells.AddTableCell();
119.            c2.Blocks.AddParagraph().Inlines.AddRun("");
120.            c2 = rowHeader2.Cells.AddTableCell();
121.            c2.Blocks.AddParagraph().Inlines.AddRun("");
122.            c2 = rowHeader2.Cells.AddTableCell();
123.            c2.Blocks.AddParagraph().Inlines.AddRun("");
124.            c2 = rowHeader2.Cells.AddTableCell();
125.            c2.Blocks.AddParagraph().Inlines.AddRun("");
126.            c2 = rowHeader2.Cells.AddTableCell();
127.            c2.Blocks.AddParagraph().Inlines.AddRun("");
128.            c2 = rowHeader2.Cells.AddTableCell();
129.            c2.Blocks.AddParagraph().Inlines.AddRun("");
130.        }

5 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 12 Dec 2018, 11:48 AM
Hello Zake,

Could you please elaborate more on the exact result you are trying to achieve so I can assist you further. I am currently not sure what the end goal is so I would like to gather more information on the case.

Regards,
Tanya
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
zake
Top achievements
Rank 1
answered on 06 Jan 2019, 10:12 AM

I just had time to see the forum, thank you before for answering.

I attach a picture of what I want.

Note : I only want to use RadFlowDocumentEditor to generate doc like that image,,,, Tks

0
Tanya
Telerik team
answered on 09 Jan 2019, 12:54 PM
Hi Zake,

To ensure you will get the desired results, you will need to insert content in the document using only one of the available approaches - through the model or through the RadFlowDocumentEditor class. With the current implementation, I would suggest you to insert the content of the paragraph using the InsertText() method of the editor. This way, all the changes will be respected as expected.
var paragraph1 = editor.InsertParagraph();
editor.InsertText("Note that the numbering the paragraph.");


Regards,
Tanya
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
zake
Top achievements
Rank 1
answered on 18 Jan 2019, 08:57 AM

tks for the answering,,,

I'm sory but I am still confuse

can you give me some script c# example to get bullet list like my attachment image using radflowdocumenteditor ?

tks before

0
Tanya
Telerik team
answered on 22 Jan 2019, 04:55 PM
Hello Zake,

You can achieve the desired result by replacing the invocation of the AddRun() method of the Paragraph's Inlines collection with the InsertText() method of RadFlowDocumentEditor using the code from the snippet in my previous reply. If you change the way the content is inserted, you will get the result just like shown in the image. 

Regards,
Tanya
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
WordsProcessing
Asked by
zake
Top achievements
Rank 1
Answers by
Tanya
Telerik team
zake
Top achievements
Rank 1
Share this question
or