将System.Color转换为Microsoft Word WdColor

use*_*651 9 c# colors

我对C#很陌生,并且发现将RGB颜色或system.color转换为WdColor的简单方法几乎无法形容!

VB很简单,C# - 真的很难吗?

我不想在我的项目中引用VB.

我在一些单词自动化项目中使用它来为字体着色,例如

tmpRange.Find.Replacement.Font.Color = Color.FromArgb(100, 150, 75); 
Run Code Online (Sandbox Code Playgroud)

但是上面这行不可能,它需要是WdColor.

Col*_*ron 17

Color c = Colors.Blue;
var wdc = (Microsoft.Office.Interop.Word.WdColor)(c.R + 0x100 * c.G + 0x10000 * c.B);
Run Code Online (Sandbox Code Playgroud)


Pra*_*thy 5

添加对Microsoft.VisualBasic dll的引用

using Microsoft.VisualBasic;

int rgbColor = Information.RGB(100, 150, 75);
Word.WdColor wdColor = (Word.WdColor)rgbColor;
Run Code Online (Sandbox Code Playgroud)