We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Background color in table

Hello,

I want to create table with background color but one of cell has different color. The best way is to apply color when table is created (without any cell) or at the end when all cells are created. In first option color doesn’t apply. In second option table color is overwritten.
Do you know how can I use table.SetShading only for cells without color?

Thanks,
Monika

@acturisaspose You can use code like the following to achieve what you need:

Document doc = new Document(@"C:\Temp\in.docx");

Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

// Set background of the whole table.
table.SetShading(TextureIndex.TextureNone, Color.Red, Color.Red);

// Set background of the particular cell.
table.Rows[2].Cells[2].CellFormat.Shading.BackgroundPatternColor = Color.Green;
            
doc.Save(@"C:\Temp\out.docx", SaveFormat.Docx);

in.docx (12.7 KB)
out.docx (10.1 KB)