NPOI icon indicating copy to clipboard operation
NPOI copied to clipboard

填充背景颜色无效

Open jianxuanbing opened this issue 6 years ago • 5 comments

给单元格设置背景颜色无效,不起作用

        [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 avatar Sep 29 '18 06:09 jianxuanbing

突然发现,得设置 前景色才可以

jianxuanbing avatar Sep 29 '18 06:09 jianxuanbing

我设置了背景色以后,单元格设置的居中等样式都乱了是怎么回事

wanghaoxing avatar Oct 22 '18 06:10 wanghaoxing

经过测试发现是想根据不同单元格设置不同颜色的时候,样式会乱掉

wanghaoxing avatar Oct 22 '18 07:10 wanghaoxing

@jianxuanbing 请问是怎么生效的呢?

            _defaultTitleStyle.FillBackgroundColor = Red.Index;
            _defaultTitleStyle.FillForegroundColor = Red.Index;

我像上面这么写也没有生效,样式中除了背景色其他都生效了

smartlei24 avatar Nov 07 '18 02:11 smartlei24

好吧... 是还需要设置填充样式才会填充

_defaultTitleStyle.FillPattern = FillPattern.SolidForeground;

smartlei24 avatar Nov 07 '18 05:11 smartlei24