c#epplus不填充单元格的背景颜色

问题描述

好吧,我很难过设置的字体工作并设置了正确的单元格。 Fill.BackgroundColor.SetColor 不起作用。它实际上什么都不做。我错过了什么吗?我使用该语法进行的每次搜索都应该有效。 是的,这是读取数据表 dt,这不是循环正常工作的问题。

int startupRow = 2; // row 1 is header

for (int row = startupRow; row <= dt.Rows.Count; row++)
{
    //if allocation check is populated it will have a value > 0
    if (Convert.ToInt32(workSheet.Cells[row,8].Value) > 0)
    {
        //if Balance Remaining Barrels <  allocation check
        if (Convert.ToInt32(workSheet.Cells[row,7].Value) < Convert.ToInt32(workSheet.Cells[row,8].Value))
        {
            //set the font to red 
            var cell = workSheet.Cells[row,7];
            cell.Style.Font.Color.SetColor(System.Drawing.Color.Red);
            cell.Style.Font.Bold = true;

            //Setting the background color to red
            cell.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.solid;
            cell.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red);

        }
    }
}  
       

解决方法

我解决了我自己的问题,希望这对其他人有所帮助。 边框必须在格式的最后。某些元素优先于其他元素,它们会消失。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...