Free Support Forum - aspose.com

Probably a newbie question

Greetings
I have just started using Aspose.Word, and while it seems like a fairly good product, I really could use more code examples.

Right now I have a problem with finding out how to change the background color of a table or cell in a worddocument. Is there an easy way to do this?

Hi,

Thank you for your interest in Aspose.Word and your positive report.

Yes, this is pretty easy. There is the Shading class allowing you to set background color of a table cell or paragraph, you can use various shading textures including solid. Here is an example of how to create a table with 4 cells having different shading:


Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.StartTable();

builder.InsertCell();

builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;

builder.CellFormat.Shading.BackgroundPatternColor = Color.Blue;

builder.CellFormat.Shading.ForegroundPatternColor = Color.Blue;

builder.InsertCell();

builder.CellFormat.Shading.Texture = TextureIndex.TextureDiagonalCross;

builder.CellFormat.Shading.BackgroundPatternColor = Color.YellowGreen;

builder.CellFormat.Shading.ForegroundPatternColor = Color.HotPink;

builder.EndRow();

builder.InsertCell();

builder.CellFormat.Shading.Texture = TextureIndex.Texture50Percent;

builder.CellFormat.Shading.BackgroundPatternColor = Color.Indigo;

builder.CellFormat.Shading.ForegroundPatternColor = Color.LightSkyBlue;

builder.InsertCell();

builder.CellFormat.Shading.Texture = TextureIndex.TextureHorizontal;

builder.CellFormat.Shading.BackgroundPatternColor = Color.Tomato;

builder.CellFormat.Shading.ForegroundPatternColor = Color.LightSalmon;

builder.EndRow();

builder.EndTable();

doc.Save(“result.doc”);