700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 设置Excel单元格背景色(setFillForegroundColor)

设置Excel单元格背景色(setFillForegroundColor)

时间:2023-12-21 06:09:55

相关推荐

设置Excel单元格背景色(setFillForegroundColor)

POI 设置Excel单元格背景色(setFillForegroundColor)

背景介绍:

使用Java开发信息系统项目,项目中往往会涉及到报表管理部分,而Excel表格首当其冲称为最合适的选择,但是对单元格操作时对于设置单元格的背景颜色却很少提及,本文旨在方便单元格背景颜色设计。

操作:

至于冗长的创建表格表格设置的代码相信大家都已经了解。直接进行单元格背景颜色设计。

HSSFCellStyle style = wb.createCellStyle();style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式style.setFillForegroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex());// 设置背景色style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //设置加粗HSSFFont font = wb.createFont();font.setFontName("黑体");font.setFontHeightInPoints((short) 12);//设置字体大小style.setFont(font);// 创建标题for (int i = 0; i < title.length; i++) {cell = row.createCell(i);cell.setCellValue(title[i]);cell.setCellStyle(style);}

上面的单元格颜色对应下面的英语颜色表示,从X1-X49 按顺序对应;

将下面对应的code填入上述代码加粗斜体位置即可。

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();

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