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

Using in-built style when programmatically adding table to RadFlowDocument

1 Answer 491 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Sean Bintley
Top achievements
Rank 2
Sean Bintley asked on 09 Feb 2018, 04:07 PM

I'm using a template to generate a document with a table in it. I'm adding the table, from scratch, to the document dynamically. This all exists in an ASP.Net MVC application. The table is being built ok. The only thing is I can't get it to take on the inbuilt Word table style I want. It doesn't matter what style i stry, it's not working.

See code example.

01.private static void BuildScheduleItemsTable(RadFlowDocument document,
02.            RadFlowDocumentEditor editor,
03.            ScheduleOfWork scheduleOfWork,
04.            ScheduleStage scheduleStage = ScheduleStage.Preliminary,
05.            ScheduleRecipient scheduleRecipient = ScheduleRecipient.Customer)
06.        {
07.            List<ScheduleOfWorkItem> scheduleOfWorkItems =
08.                GetScheduleOfWorkItemsFor(scheduleOfWork.ScheduleOfWorkID, scheduleStage);
09.             
10.             
11.            Table table = editor.InsertTable(scheduleOfWorkItems.Count + 1, 5);
12.            table.StyleId = "MediumGrid3-Accent4";
13.            table.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Auto);
14.            table.LayoutType = TableLayoutType.AutoFit;
15. 
16.            // create header row
17.            TableRow headerRow = table.Rows[0];
18.            headerRow.RepeatOnEveryPage = true;           
19.            //headerRow.CanSplit = false;
20.            //headerRow.RepeatOnEveryPage = true; // header row repeats when new page
21.            headerRow.AddHeaderCellAndText("Description", 0);
22.            headerRow.AddHeaderCellAndText("Quantity", 1);
23.            headerRow.AddHeaderCellAndText("Cost", 2);
24.            headerRow.AddHeaderCellAndText("VAT Amount", 3);
25.            headerRow.AddHeaderCellAndText("Total Cost Inc VAT", 4);
26. 
27.            int rowIter = 1;
28.            foreach (ScheduleOfWorkItem scheduleOfWorkItem in scheduleOfWorkItems)
29.            {
30.                TableRow itemRow = table.Rows[rowIter];
31.                //itemRow.CanSplit = false;
32.                itemRow.UpdateDescriptionCell(scheduleOfWorkItem, scheduleRecipient);
33.                itemRow.UpdateQuantityCell(scheduleOfWorkItem);
34.                itemRow.UpdateCostCell(scheduleOfWorkItem);
35.                itemRow.UpdateVatAmountCell(scheduleOfWorkItem);
36.                itemRow.UpdateTotalCostIncVatCell(scheduleOfWorkItem);
37.                rowIter++;
38.            }
39.        }

 

The Update...Cell and AddHeaderCellAndText methods are just methods that create paragraphs and runs inside the cells that were created when the table was created. No matter what I set in table.StyleId it doesn't seem to take effect

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 14 Feb 2018, 10:36 AM
Hello Sean,

Before setting a style to any document element, this style should be registered in the StyleRepository of the document. How you can do that is described in the Styles topic from our documentation. A list of all the styles that are provided and can be used out of the box can be seen through the BuiltInStyleNames class and if you would like to use a different style, you will need to declare it.

As mentioned in the blog post, the conditional table styles are not supported: Add support for Conditional Table Styles. Thus, similar styling cannot be applied to a Table.

Hope this information is helpful.

Regards,
Tanya
Progress Telerik

Tags
WordsProcessing
Asked by
Sean Bintley
Top achievements
Rank 2
Answers by
Tanya
Telerik team
Share this question
or