Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# code to fill color in a table cell in a word document

Tags:

c#

ms-word

I have created a word document which contains a table, using C#. Now I want to fill one of the cells in this table with red color. While searching on the net, I found that I could use the shading object to do this. But I dint get any details on how I could use this.

I tried using something like:

doc.Tables[whichTable].Cell(1,4).Range.Shading.BackgroundPatternColor

But how can I set a color using this???

like image 402
Jahnavi K. Abhyuday Avatar asked Mar 27 '13 05:03

Jahnavi K. Abhyuday


1 Answers

If you look at this reference page you will see the WdColor constants listed. These are colours available to word, to see more about them there is an enumeration listing here.

Your code to select the table cell looks correct to me, so you just need to set the BackgroundPatternColor to one of the WdColors.

like image 171
Nashibukasan Avatar answered Sep 28 '22 20:09

Nashibukasan