问题描述
好吧,我很难过设置的字体工作并设置了正确的单元格。 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);
}
}
}
解决方法
我解决了我自己的问题,希望这对其他人有所帮助。 边框必须在格式的最后。某些元素优先于其他元素,它们会消失。