Cell.Style.Fill.BackgroundColor没有填充正确的颜色

时间:2017-11-08 16:02:54

标签: c# excel

我需要将输出excel文件中的错误单元格标记为红色。如果在原始文档中这些单元格没有填充,则一切都很好,颜色为红色。但如果细胞已经充满了蓝色(或某种类型),在输出中它会变成粉红色,但不是红色! 这是我的代码:

var cell = worksheet.Cells[row, column];
        cell.Reset();
        cell.Value = string.Format("{0}  Error:{1}", cell.Value, errortext);
        cell.Style.Fill.BackgroundColor.SetColor(Color.Empty);
        cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
        cell.Style.Fill.BackgroundColor.SetColor(Color.Red);
        cell.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(255, 0, 0));

这应该是它的样子:

This is how it should look

如果原始填充为蓝色,则为此:

This is how it is if the original fill was blue

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

cell.Style.Fill.BackgroundColor.Tint = 0;

有帮助。