user194076
user194076

Reputation: 9017

Get cell color in MS Word

in microsoft word I can open a document and get a text for a cell like this (office interop):

app.Tables[1].Cell(2, 2).Range.Text;

But I cannot find a property that can return this exact cell color. Any help is appreciated!

Upvotes: 2

Views: 1362

Answers (1)

phoog
phoog

Reputation: 43036

I think you need the Shading property (app.Tables[1].Cell(2, 2).Shading;).

EDIT

To address your comment: I don't believe there is a better way to get the color. The BackgroundPatternColorIndex and ForegroundPatternColorIndex return values of the WdColorIndex enumeration; they have a numeric value that is not related to the RGB color. For example, wdRed has a value of 6 (see http://msdn.microsoft.com/en-us/library/bb237561(v=office.12).aspx for more information).

If you want the RGB values, as you may have guessed, you would use BackgroundPatternColor and ForegroundPatternColor rather than ...ColorIndex. But it sounds like you're looking for a string name rather than a numeric value.

Upvotes: 2

Related Questions