DocX
DocX copied to clipboard
Add Table Subtotal row BackColor
Hi. I want to add some rows from a DataTable to Docx table. Grouping DataTable by some values (columns) I want to insert Subtotal rows in docx's table. This row has some merged cells and display the subtotal on certain column. This row has also a different back color than the rest of the table's rows. I want to preserve the coloring of rows containing the data by even/odd lines backcolor, even if I insert that subtotal row, or to reset the starting of next rows after subtotal.
Example:

Is there any possibility to do that?
Hi,
When you define a Table, you can set its look, like using alternate row colors: var table = doc.AddTable( 5, 4 ); table.Design = TableDesign.MediumList2; table.TableLook.FirstRow = false; table.TableLook.FirstColumn = false;
When you insert a new row, the color pattern will be kept, no matter where you insert the new row. A solution to have the SubTotal rows in another color could be to set the color you want in the row's cells: var newRow = table.InsertRow( 2 ); foreach( var cell in newRow.Cells ) { cell.FillColor = Color.Blue; }
If it still do not meet your expectation, you may have to color each row's cell the way you want. I don't think even MS Word can do this easily.