编程语言
首页 > 编程语言> > C#Word Interop Automation 2013 – 将字体颜色设置为RGB值

C#Word Interop Automation 2013 – 将字体颜色设置为RGB值

作者:互联网

如何在Microsoft.Office.Interop.Word C#应用程序上设置FONT COLOR?

我注意到ColorIndex属性处理大约20种颜色,并且没有允许我从RGB值中选择的迹象?

这是我无法使其工作的代码:

parag.Range.Font.TextColor.RGB = Color.FromArgb(84, 141, 212).ToArgb();

我得到的例外是:
  传递给此方法或属性的值之一超出范围.

任何帮助将真正感激!!

解决方法:

虽然Color没有出现在intelisense中,但您可以在Font上访问它,如下所示:

parag.Range.Font.Color = WdColor.wdColorBlue;

要创建自定义WdColor,您可以使用:

Color c = Color.FromArgb(229, 223, 236);
var myWdColor = (Microsoft.Office.Interop.Word.WdColor)(c.R + 0x100 * c.G + 0x10000 * c.B);

标签:c,office-interop
来源: https://codeday.me/bug/20190529/1177809.html