在MS Word中获取单元格颜色

时间:2011-11-15 00:40:00

标签: c# .net office-interop office-2007

在微软的单词中,我可以打开一个文档并为这样的单元格获取文本(office interop):

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

但我找不到可以返回这种确切单元格颜色的属性。任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:2)

我认为您需要Shading属性(app.Tables[1].Cell(2, 2).Shading;)。

修改

解决你的评论:我不相信有更好的方法来获得颜色。 WdColorIndex枚举的BackgroundPatternColorIndexForegroundPatternColorIndex返回值;它们具有与RGB颜色无关的数值。例如,wdRed的值为6(有关详情,请参阅http://msdn.microsoft.com/en-us/library/bb237561(v=office.12).aspx)。

如果您想要RGB值,您可能会使用BackgroundPatternColorForegroundPatternColor而不是...ColorIndex。但听起来你正在寻找字符串名称而不是数字值。