Free Support Forum - aspose.com

Different paragraphFormat for table header

Hi,

I noticed something that seemed as a strange behavior to me, so I thought I’d get your view on this. I’m creating a simple table and want the header line to have a different shade and use a specific paragraph format then the rest of the table.

I assign a ParagraphFormat and CellFormat right after creating the table, then clear both after the first EndRow(). What I get is that the last header cell is shaded, but the paragraph style is not applied…

I assumed that the EndRow() would also have ended the paragraph… Is there anything I did not do correctly?

I use the following code :
Aspose.Words.Table table;
table = StartTable(builder);

builder.ParagraphFormat.StyleName = USER_STYLE_HEADER;
builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.LightGray;

for (int i=0; i<ds.Tables[0].Columns.Count; ++i) {
builder.InsertCell();
builder.Write(ds.Tables[0].Columns[i].ColumnName);
}
builder.EndRow();

builder.ParagraphFormat.ClearFormatting();
builder.CellFormat.ClearFormatting();

for (int i=0; i<ds.Tables[0].Rows.Count; ++i) {
row = ds.Tables[0].Rows[i];

for (int j=0; j<ds.Tables[0].Columns.Count; ++j) {
builder.InsertCell();
builder.Write(row[j].ToString());
}

builder.EndRow();
}
builder.EndTable();

Thanks,

Dominic.

Using Aspose.Words v.4.4.1.0

I seem to have found a work-around :

builder.MoveToDocumentEnd();
builder.ParagraphFormat.ClearFormatting();
builder.CellFormat.ClearFormatting();


Hi

It is very nice that you have found the solution independently. This occurs because builder.ParagraphFormat.ClearFormatting(); clears formating of the current paragraph. You can also clear the paragraph formating after inserting the first cell of the second row.

Best regards.