Free Support Forum - aspose.com

Dynamic table alternating row colors

Hey guys,

Is it possible to make dynamic tables have alternating row colors, much like .Net’s datagrid control?

Here’s an example:
http://pcwin.com/Software_Development/DataGrid_Columns__NET_assembly/screen.htm

I am currently using Aspose.Words v1.1.4322

Thanks.

Hi

Thanks for your inquiry. I think that you can try to change background color. See the following code example.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//generate table

for (int i = 0; i < 10; i++)

{

for (int j = 0; j < 5; j++)

{

builder.CellFormat.Width = 100;

builder.InsertCell();

//change background

if (i % 2 != 0)

{

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

}

else

{

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

}

}

builder.EndRow();

}

builder.EndTable();

doc.Save(@"out.doc");

I hope that this will help you.

Also, I would advise to use the latest version of Aspose.Words.

The latest version of Aspose.Words is available for download from here.

Best regards.

Ahh okay. I coded something like that yesterday, but was wondering if there was a simple property to set like the .net datagrid. This works though.

Thanks, Alexey.