Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将System.Drawing.Color指定给Microsoft.Office.Interop.Excel.ColorFormat_C#_Excel_Colors_System.drawing - Fatal编程技术网

C# 如何将System.Drawing.Color指定给Microsoft.Office.Interop.Excel.ColorFormat

C# 如何将System.Drawing.Color指定给Microsoft.Office.Interop.Excel.ColorFormat,c#,excel,colors,system.drawing,C#,Excel,Colors,System.drawing,示例代码如下: Chart.SerialsCollection(1).Point(1).Format.Fill.ForeColor = System.Drawing.Color.Red; 返回一个错误。无法隐式转换类型,一个是结构,另一个是ColorFormat RGB是整数类型,我只能从Color.Red.R、Color.Red.G和Color.Red.B中得到3个整数。如何将颜色指定为“我要使用的颜色”属性?请尝试使用property ForeColor.RGB 例如 按照评论中的建议,使

示例代码如下:

Chart.SerialsCollection(1).Point(1).Format.Fill.ForeColor = System.Drawing.Color.Red;
返回一个错误。无法隐式转换类型,一个是结构,另一个是ColorFormat

RGB是整数类型,我只能从Color.Red.R、Color.Red.G和Color.Red.B中得到3个整数。如何将颜色指定为“我要使用的颜色”属性?

请尝试使用property ForeColor.RGB

例如


按照评论中的建议,使用

或者,输入RGB值:

一些附加信息,因此我不只是重复评论:

ForeColor.RGB可以用十六进制表示为0xBBGGRR。知道了这一点,您可以创建以下函数:

public int Color_to_RGB(Color color) {
    return (color.B << 16) | (color.G << 8) | Color.R;
}

在另一个答案中使用的ToArgb的原因不起作用,因为它的十六进制表示法是0xAARRGGBB

是的,我已经尝试过了,它可以通过编译,但颜色不正确。颜色。红色显示为不同的颜色。我认为这是因为RGB和ARGB是两种不同的颜色系统,对吗?你可以在这里找到答案:ColorTranslator.ToOle可以按照建议工作。
Chart.SerialsCollection(1).Point(1).Format.Fill.ForeColor.RGB = ColorTranslator.ToOle(Color.Red);
Chart.SerialsCollection(1).Point(1).Format.Fill.ForeColor.RGB = ColorTranslator.ToOle(Color.FromArgb(255, 0, 0);
public int Color_to_RGB(Color color) {
    return (color.B << 16) | (color.G << 8) | Color.R;
}
Chart.SerialCollection(1).Point(1).Format.Fill.ForeColor.RGB = Color_to_RGB(Color.Red);