失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > POI设置Excel单元格样式和背景色

POI设置Excel单元格样式和背景色

时间:2023-01-31 03:37:50

相关推荐

POI设置Excel单元格样式和背景色

private static CellStyle leftStyle(final Workbook exportWorkbook) {CellStyle cellStyleLeft = exportWorkbook.createCellStyle();Font font = exportWorkbook.createFont();font.setFontName("宋体");cellStyleLeft.setFont(font);cellStyleLeft.setAlignment(HorizontalAlignment.LEFT);cellStyleLeft.setVerticalAlignment(VerticalAlignment.CENTER);cellStyleLeft.setBorderBottom(BorderStyle.THIN);cellStyleLeft.setBorderLeft(BorderStyle.THIN);cellStyleLeft.setBorderRight(BorderStyle.THIN);cellStyleLeft.setBorderRight(BorderStyle.THIN);cellStyleLeft.setBorderTop(BorderStyle.THIN);cellStyleLeft.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); // 灰色cellStyleLeft.setFillPattern(FillPatternType.SOLID_FOREGROUND);return cellStyleLeft;}

根据需求设置单元格背景色为灰色,以上代码设置结果为黑色,原因是cellStyleLeft.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); // 灰色

这段代码有问题,改成下面就行,注意页面颜色填充

cellStyleLeft.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); // 灰色

如果觉得《POI设置Excel单元格样式和背景色》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。