NPOI
NPOI copied to clipboard
填充背景颜色无效
给单元格设置背景颜色无效,不起作用
[Fact]
public void Test2()
{
FileStream fs = new FileStream("D:\\测试Npoi_007.xls", FileMode.Open);
HSSFWorkbook workbook = new HSSFWorkbook(fs);
HSSFSheet currentSheet = (HSSFSheet)workbook.GetSheet("测试工作表");
HSSFCellStyle style8 = (HSSFCellStyle)workbook.CreateCellStyle();
style8.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index;
style8.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Red.Index;
var cell=currentSheet.GetRow(0).GetCell(0);
cell.CellStyle = style8;
cell.SetCellValue("123");
using (var temp = new FileStream("D:\\测试Npoi_0071.xls", FileMode.Create, FileAccess.Write))
{
workbook.Write(temp);
}
fs.Close();
}
突然发现,得设置 前景色才可以
我设置了背景色以后,单元格设置的居中等样式都乱了是怎么回事
经过测试发现是想根据不同单元格设置不同颜色的时候,样式会乱掉
@jianxuanbing 请问是怎么生效的呢?
_defaultTitleStyle.FillBackgroundColor = Red.Index;
_defaultTitleStyle.FillForegroundColor = Red.Index;
我像上面这么写也没有生效,样式中除了背景色其他都生效了
好吧... 是还需要设置填充样式才会填充
_defaultTitleStyle.FillPattern = FillPattern.SolidForeground;