java poi cellstyle_java-无法在XSSFCell Apache POI中设置自定义颜色

我正在尝试为xssfcell设置一些自定义的颜色(从hexcode或rgb值开始),但是即使我提供了其他颜色,单元的颜色也正在变为黑色.我尝试通过以下方式进行操作:

File xlSheet = new File("C:\Users\IBM_ADMIN\Downloads\Excel Test\Something3.xlsx");

System.out.println(xlSheet.createNewFile());

FileOutputStream fileOutISPR = new FileOutputStream("C:\Users\IBM_ADMIN\Downloads\Excel Test\Something3.xlsx");

XSSFWorkbook isprWorkbook = new XSSFWorkbook();

XSSFSheet sheet = isprWorkbook.createSheet("TEST");

XSSFRow row = sheet.createRow(0);

XSSFCellStyle cellStyle = isprWorkbook.createCellStyle();

byte[] rgb = new byte[3];

rgb[0] = (byte) 24; // red

rgb[1] = (byte) 22; // green

rgb[2] = (byte) 219; // blue

XSSFColor myColor = new XSSFColor(rbg);

cellStyle.setFillForegroundColor(myColor);

cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

cellStyle.setAlignment(HorizontalAlignment.CENTER);

XSSFCell cell = row.createCell(0);

cell.setCellValue("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has");

cell.setCellStyle(cellStyle);

CellRangeAddress rangeAddress = new CellRangeAddress(0, 0, 0, 2);

sheet.addMergedRegion(rangeAddress);

int width = ((int)(90 * 0.73)) * 256;

sheet.setColumnWidth(cell.getColumnIndex(), width);

//sheet.autoSizeColumn(cell.getColumnIndex());

RegionUtil.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM, rangeAddress, sheet, isprWorkbook);

RegionUtil.setBottomBorderColor(IndexedColors.RED.getIndex(), rangeAddress, sheet, isprWorkbook);

XSSFCell cell2 = row.createCell(11);

cell2.setCellValue("222222222222222");

isprWorkbook.write(fileOutISPR);

//程序结束

XSSFCellStyle cellStyle = isprWorkbook.createCellStyle();

byte[] rgb = new byte[3];

rgb[0] = (byte) 24; // red

rgb[1] = (byte) 22; // green

rgb[2] = (byte) 219; // blue

XSSFColor myColor = new XSSFColor(rgb);

cellStyle.setFillForegroundColor(myColor);//1st method

//cellStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128)));//2nd method

//XSSFColor myColor = new XSSFColor(Color.decode("0XFFFFFF"));

cellStyle.setFillForegroundColor(myColor);//3rd Method

我尝试了在相关问题的答案中提到的许多其他方法,但是这些方法都没有解决我的问题.

请帮帮我.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值