POI setting Cell Background to a Custom Color

后端 未结 6 867
野性不改
野性不改 2020-12-25 11:03

I want to set custom color to a cell\'s background.
I use HSSFWorkbook (can\'t use anything else).

HSSFPalette palette = aWorkBook.getCustom         


        
6条回答
  •  情话喂你
    2020-12-25 11:22

    Slot free in NPOI excel indexedcolors from 57+

                Color selColor;
    
            var wb = new HSSFWorkbook();
    
            var sheet = wb.CreateSheet("NPOI");
            var style = wb.CreateCellStyle();
            var font = wb.CreateFont();
            var palette = wb.GetCustomPalette();
    
            short indexColor = 57; 
            palette.SetColorAtIndex(indexColor, (byte)selColor.R, (byte)selColor.G, (byte)selColor.B);
    
            font.Color = palette.GetColor(indexColor).Indexed;
    

提交回复
热议问题