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

POI 设置Excel单元格背景色

时间:2019-09-08 18:07:31

相关推荐

POI 设置Excel单元格背景色

POI 设置Excel单元格背景色

前言一、冲~~~1.代码实现2.颜色对应3.填充对应总结

前言

POI 设置单元格背景颜色


一、冲~~~

1.代码实现

注: 本人用的是目前最新的依赖 4.1.2

代码如下(示例):

HSSFWorkbook workbook = new HSSFWorkbook();HSSFCellStyle style = workbook.createCellStyle();//设置单元格颜色(颜色对应枚举会放在下面)style.setFillForegroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex());//全部填充 (填充枚举对应的样式也会放在下面)style.setFillPattern(FillPatternType.SOLID_FOREGROUND);//当然 style可以设置多个 填充时选取自己需要的就行//下面简单举例一下(单个单元格)其他的都一样HSSFSheet sheet = workbook.createSheet("excel");HSSFRow row = sheet.createRow(0);HSSFCell cell = row.createCell(0);cell.setCellValue("哈哈"); //单元格内容cell.setCellStyle(style);//填充

2.颜色对应

IndexedColors.AQUA.getIndex();IndexedColors.AUTOMATIC.getIndex(); IndexedColors.BLUE.getIndex(); IndexedColors.BLUE_GREY.getIndex();IndexedColors.BRIGHT_GREEN.getIndex();IndexedColors.BROWN.getIndex();IndexedColors.CORAL.getIndex();IndexedColors.CORNFLOWER_BLUE.getIndex();IndexedColors.DARK_BLUE.getIndex();IndexedColors.DARK_GREEN.getIndex();IndexedColors.DARK_RED.getIndex();IndexedColors.DARK_TEAL.getIndex();IndexedColors.DARK_YELLOW.getIndex();IndexedColors.GOLD.getIndex();IndexedColors.GREEN.getIndex();IndexedColors.GREY_25_PERCENT.getIndex();IndexedColors.GREY_40_PERCENT.getIndex();IndexedColors.GREY_50_PERCENT.getIndex();IndexedColors.GREY_80_PERCENT.getIndex();IndexedColors.INDIGO.getIndex();IndexedColors.LAVENDER.getIndex();IndexedColors.LEMON_CHIFFON.getIndex();IndexedColors.LIGHT_BLUE.getIndex();IndexedColors.LEMON_CHIFFON.getIndex();IndexedColors.LIGHT_BLUE.getIndex();IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex();IndexedColors.LIGHT_GREEN.getIndex();IndexedColors.LIGHT_ORANGE.getIndex();IndexedColors.LIGHT_TURQUOISE.getIndex();IndexedColors.LIGHT_YELLOW.getIndex();IndexedColors.LIME.getIndex();IndexedColors.MAROON.getIndex();IndexedColors.OLIVE_GREEN.getIndex();IndexedColors.ORANGE.getIndex();IndexedColors.ORCHID.getIndex();IndexedColors.PALE_BLUE.getIndex();IndexedColors.PINK.getIndex();IndexedColors.PLUM.getIndex();IndexedColors.RED.getIndex();IndexedColors.ROSE.getIndex();IndexedColors.ROYAL_BLUE.getIndex();IndexedColors.SEA_GREEN.getIndex();IndexedColors.SKY_BLUE.getIndex();IndexedColors.TAN.getIndex();IndexedColors.TEAL.getIndex();IndexedColors.TURQUOISE.getIndex();IndexedColors.VIOLET.getIndex();IndexedColors.WHITE.getIndex();IndexedColors.YELLOW.getIndex();

3.填充对应

NoFill = 0,SolidForeground = 1,FineDots = 2,AltBars = 3,SparseDots = 4,ThickHorizontalBands = 5,ThickVerticalBands = 6,ThickBackwardDiagonals = 7,ThickForwardDiagonals = 8,BigSpots = 9,Bricks = 10,ThinHorizontalBands = 11,ThinVerticalBands = 12,ThinBackwardDiagonals = 13,ThinForwardDiagonals = 14,Squares = 15,Diamonds = 16,LessDots = 17,LeastDots = 18

总结

遇到的问题:poi依赖版本的问题 版本的老一点的HSSFCellStyle 就可以直接使用颜色

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

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