问题描述
如何将 System.Drawing.Color
转换为 Microsoft.Office.Interop.Word.WdColorIndex
?
到目前为止我已经完成了代码,但它显示了溢出"错误.
I have done the code so far, but it's showing the error "overflow".
这是我做的代码
Color bgcolor = Color.FromArgb(Convert.ToInt32(innerText));
Microsoft.Office.Interop.Word.WdColorIndex wbgc = (Microsoft.Office.Interop.Word.WdColorIndex)(bgcolor.R + 0x100 * bgcolor.G + 0x10000 * bgcolor.B);
doc.Range(iRangeStart, iRangeEnd).HighlightColorIndex = wbgc;
我怎样才能做到这一点?
How can I achieve this?
推荐答案
WdColorIndex
是一个枚举,而不是一个定义颜色系统的对象.这意味着您可以分配的值受枚举元素的限制,例如wdBlack
或 wdBlue
及其基础整数值.
WdColorIndex
is an enumeration, not an object that defines a color system. This means that the value you can assign is limited by the enumeration elements, e.g. wdBlack
or wdBlue
and their underlying integer values.
您使用的技术是应用于 WdColor
对象而不是 WdColorIndex
枚举:
The technique you are using is to be applied to a WdColor
object instead of a WdColorIndex
enumeration:
var wordColor = (Microsoft.Office.Interop.Word.WdColor)(bgcolor.R + 0x100 * bgcolor.G + 0x10000 * bgcolor.B);
Word 文档中的突出显示仅限于多种颜色,如 WdColorIndex
枚举中所定义.因此,您不能简单地将任何颜色转换为 Word 颜色以进行突出显示.您必须选择可用值之一.有关可能的值,请参阅 MSDN for WdColorIndex.
Highlighting in a Word document is limited to a number of colors, as defined in the WdColorIndex
enumeration. Therefore, you cannot simply convert any color to a Word color for highlighting. You have to pick one of the available values. See MSDN for WdColorIndex for possible values.
这篇关于如何将 System.Drawing.Color 转换为 Microsoft Interop WdColorIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!