先贴两段代码,HSSFCellStyle style8 = workbook.CreateCellStyle();
style8.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.WHITE.index;
style8.FillPattern = HSSFCellStyle.SQUARES;
style8.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.RED.index;
foreach (DataRow dr in dtSource.Rows)
{
hssfRow = sheet.CreateRow(i + 1); if (i == 5)//11111111111
{
hssfRow.RowStyle = style8;
}
foreach (DataColumn dc in dtSource.Columns)
{
string dcname = dc.ColumnName;
string dcc = dc.ToString();
//object detecell = dr[dc];
string hssfcell = dr[dc].ToString();
HSSFCell cell = hssfRow.CreateCell(dc.Ordinal);
cell.SetCellValue(hssfcell);
}
if (i == 5)//222222222
{
hssfRow.RowStyle = style8;
}
i++;
}我现在想在一或者2那里判断,如果满足条件,则整行颜色改变,但是我的这个方法不起作用, 我的要求是,在循环DataColumn 中某一列时,如果满足某个条件,那么整行的颜色改变,求解!!!!
style8.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.WHITE.index;
style8.FillPattern = HSSFCellStyle.SQUARES;
style8.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.RED.index;
foreach (DataRow dr in dtSource.Rows)
{
hssfRow = sheet.CreateRow(i + 1); if (i == 5)//11111111111
{
hssfRow.RowStyle = style8;
}
foreach (DataColumn dc in dtSource.Columns)
{
string dcname = dc.ColumnName;
string dcc = dc.ToString();
//object detecell = dr[dc];
string hssfcell = dr[dc].ToString();
HSSFCell cell = hssfRow.CreateCell(dc.Ordinal);
cell.SetCellValue(hssfcell);
}
if (i == 5)//222222222
{
hssfRow.RowStyle = style8;
}
i++;
}我现在想在一或者2那里判断,如果满足条件,则整行颜色改变,但是我的这个方法不起作用, 我的要求是,在循环DataColumn 中某一列时,如果满足某个条件,那么整行的颜色改变,求解!!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货