Jahnavi K. Abhyuday
Jahnavi K. Abhyuday

Reputation: 163

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

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???

Upvotes: 9

Views: 10550

Answers (1)

Nashibukasan
Nashibukasan

Reputation: 2028

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.

Upvotes: 5

Related Questions