HSSFCellStyle style = changeStyleByCreditExport(workbook, "仿宋",12," 204, 204, 255"); HSSFCell cell = row.createCell(0); cell.setCellValue("值"); cell.setCellStyle(style);
private HSSFCellStyle changeStyleByCreditExport(HSSFWorkbook workbook, String fontName,int fontSize,String rgbColor){ HSSFCellStyle style = workbook.createCellStyle(); String[] rgb = rgbColor.split(","); int r = Integer.parseInt(rgb[0].trim()); int g = Integer.parseInt(rgb[1].trim()); int b = Integer.parseInt(rgb[2].trim()); HSSFPalette palette = workbook.getCustomPalette(); //这个是重点,具体的就是把之前的颜色 HSSFColor.LIME.index //HSSFColor.PALE_BLUE.index //替换为 RGB(51,204,204) 宝石蓝这种颜色 //你可以改为 RGB(0,255,127)204, 204, 255 palette.setColorAtIndex(HSSFColor.LIME.index, (byte)r,(byte)g,(byte)b); short backgroundColor = palette.getColor(HSSFColor.LIME