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

Free Support Forum - aspose.com

Set the background color of a table in Word documents

Hello,

I am trying to set the background color of a table in word. I’ve tried using the SetShading function, with the foregroundcolor set to empty, and the backgroundcolor set to my desired color. However I’m not having having success. Please see the screenshot for more details.

Is it possible to set the background color of a table?

Screenshot:

Hi David,


Thanks for your inquiry. Sure, you can fill the table cells with a light green solid color by using the following code snippet:

Document doc = new Document(@“C:\test\in.docx”);<o:p></o:p>

Table tab = doc.FirstSection.Body.Tables[0];

tab.SetShading(TextureIndex.TextureSolid, Color.LightGreen, Color.Empty);

doc.Save(@"C:\test\out.docx");


I hope, this will help.

Best Regards,

Hello,

Thanks for the feedback. I am currently already able to set the coloring of the cells, however, I was looking for a way to set the background color of the table itself. Currently the space between the cells, as in the screenshot, appear white. I am looking for a way to add color to that spacing, which I assume is the background of the table.

Hello,

Has there been any update to the resolution of this issue? Setting the shading using the method above only affected the cells, not the table.

Hi
David,


Thanks for your inquiry and sorry for the delayed response. This behaviour definitely looks like a bug. I have logged this issue in our bug tracking system as WORDSNET-6156. Your request has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best Regards,