POI颜色设置

package com.java.connect.poi; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class POIFillAndColorExample { public static void main(String[] args) throws IOException { // Create a workbook object Workbook workbook = new XSSFWorkbook(); // Create sheet Sheet sheet = workbook.createSheet(); // Create a row and put some cells in it. Row row = sheet.createRow((short) 1); // Aqua background CellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.AQUA.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); Cell cell = row.createCell((short) 1); cell.setCellValue("X1"); cell.setCellStyle(style); // Orange "foreground", foreground being the fill foreground not the // font color. style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.AUTOMATIC.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row.createCell((short) 2); cell.setCellValue("X2"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row.createCell((short) 3); cell.setCellValue("X3"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.BLUE_GREY.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row.createCell((short) 4); cell.setCellValue("X4"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row.createCell((short) 5); cell.setCellValue("X5"); cell.setCellStyle(style); // Create a row and put some cells in it. Row row2 = sheet.createRow((short) 2); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.BROWN.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row2.createCell((short) 1); cell.setCellValue("X6"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.CORAL.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row2.createCell((short) 2); cell.setCellValue("X7"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row2.createCell((short) 3); cell.setCellValue("X8"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row2.createCell((short) 4); cell.setCellValue("X9"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.DARK_GREEN.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row2.createCell((short) 5); cell.setCellValue("X10"); cell.setCellStyle(style); // Create a row and put some cells in it. Row row3 = sheet.createRow((short) 3); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.DARK_RED.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row3.createCell((short) 1); cell.setCellValue("X11"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.DARK_TEAL.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row3.createCell((short) 2); cell.setCellValue("X12"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.DARK_YELLOW.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row3.createCell((short) 3); cell.setCellValue("X13"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.GOLD.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row3.createCell((short) 4); cell.setCellValue("X14"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.GREEN.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row3.createCell((short) 5); cell.setCellValue("X15"); cell.setCellStyle(style); // Create a row and put some cells in it. Row row4 = sheet.createRow((short) 4); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row4.createCell((short) 1); cell.setCellValue("X16"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row4.createCell((short) 2); cell.setCellValue("X17"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row4.createCell((short) 3); cell.setCellValue("X18"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.GREY_80_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row4.createCell((short) 4); cell.setCellValue("X19"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.INDIGO.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row4.createCell((short) 5); cell.setCellValue("X20"); cell.setCellStyle(style); // Create a row and put some cells in it. Row row5 = sheet.createRow((short) 5); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LAVENDER.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row5.createCell((short) 1); cell.setCellValue("X21"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LEMON_CHIFFON.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row5.createCell((short) 2); cell.setCellValue("X22"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row5.createCell((short) 3); cell.setCellValue("X23"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LEMON_CHIFFON.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row5.createCell((short) 4); cell.setCellValue("X24"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row5.createCell((short) 5); cell.setCellValue("X25"); cell.setCellStyle(style); // Create a row and put some cells in it. Row row6 = sheet.createRow((short) 6); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE .getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row6.createCell((short) 1); cell.setCellValue("X26"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row6.createCell((short) 2); cell.setCellValue("X27"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row6.createCell((short) 3); cell.setCellValue("X28"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row6.createCell((short) 4); cell.setCellValue("X29"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row6.createCell((short) 5); cell.setCellValue("X30"); cell.setCellStyle(style); // Create a row and put some cells in it. Row row7 = sheet.createRow((short) 7); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.LIME.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row7.createCell((short) 1); cell.setCellValue("X31"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.MAROON.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row7.createCell((short) 2); cell.setCellValue("X32"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.OLIVE_GREEN.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row7.createCell((short) 3); cell.setCellValue("X33"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.ORANGE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row7.createCell((short) 4); cell.setCellValue("X34"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.ORCHID.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row7.createCell((short) 5); cell.setCellValue("X35"); cell.setCellStyle(style); // Create a row and put some cells in it. Row row8 = sheet.createRow((short) 8); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row8.createCell((short) 1); cell.setCellValue("X36"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.PINK.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row8.createCell((short) 2); cell.setCellValue("X37"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.PLUM.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row8.createCell((short) 3); cell.setCellValue("X38"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.RED.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row8.createCell((short) 4); cell.setCellValue("X39"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.ROSE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row8.createCell((short) 5); cell.setCellValue("X40"); cell.setCellStyle(style); // Create a row and put some cells in it. Row row9 = sheet.createRow((short) 9); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.ROYAL_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row9.createCell((short) 1); cell.setCellValue("X41"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.SEA_GREEN.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row9.createCell((short) 2); cell.setCellValue("X42"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.SKY_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row9.createCell((short) 3); cell.setCellValue("X43"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.TAN.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row9.createCell((short) 4); cell.setCellValue("X44"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.TEAL.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row9.createCell((short) 5); cell.setCellValue("X45"); cell.setCellStyle(style); // Create a row and put some cells in it. Row row10 = sheet.createRow((short) 10); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.TURQUOISE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row10.createCell((short) 1); cell.setCellValue("X46"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.VIOLET.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row10.createCell((short) 2); cell.setCellValue("X47"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row10.createCell((short) 3); cell.setCellValue("X48"); cell.setCellStyle(style); style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell = row10.createCell((short) 3); cell.setCellValue("X49"); cell.setCellStyle(style); // Write the output to a file FileOutputStream fileOut = new FileOutputStream( "POIFillAndColorExample.xlsx"); workbook.write(fileOut); fileOut.close(); } }

一堆代码  我这里想说的是:

styletop.setFillForegroundColor(IndexedColors.TAN.getIndex());  //表头颜色
        styletop.setFillPattern(CellStyle.SOLID_FOREGROUND);  //没有这一行 无法显示颜色

时间: 2024-08-13 14:32:58

POI颜色设置的相关文章

Echarts字体和线条颜色设置操作笔记

这篇文章主要讲述Echarts设置字体和线条的颜色相关操作笔记,希望文章对你有所帮助,主要是自己的在线笔记吧.我在前面先放各种修改前后图片颜色的对照,后面再详细介绍代码.这样更方便阅读及读者知道,是否对自己有所帮助,其重点是如何在模板动态网页或JSP网站中插入Echarts图片.        1.修改标题及背景颜色    2.设置柱形图颜色 3.修改坐标轴字体颜色        4.设置Legend颜色 5.修改折线颜色    6.修改油表盘字体大小及颜色 7.柱状图文本鼠标浮动上的颜色设置

[转]保护眼睛的Windows和IE、Firefox、谷歌等浏览器颜色设置

保护眼睛的Windows和IE.Firefox.谷歌等浏览器颜色设置  长时间在电脑前工作,窗口和网页上的白色十分刺眼,眼睛很容易疲劳,也容易引起头痛,其实我们可以通过设置Windows窗口和软件的颜色设置保护自己的眼睛,总结网上的设置,自己觉得下面是最优的颜色设置方案.眼科专家建议保护眼睛的颜色为:色调:85,饱和度:123,亮度:205.这个颜色就是柔和的豆沙绿色,这个颜色看着眼睛不会那么疲劳. Windows眼睛保护色设置步骤: 右击"桌面"-->"属性"

android中的颜色设置

1.在android中经常看到设置的颜色为八位的十六进制的颜色值,例如: 1 2 3 public static final class color {     public static final int lightblue=0x7f040000; } 或者在Java中tx.setTextColor(0xffff00f); 说明: 0xffff00ff是int类型的数据,分组一下0x|ff|ff00ff,0x表示颜色整数的标记,ff表示透明度,f00f表示色值,注意:0x后面ffff00ff

关于border边框重叠颜色设置问题

盒子模型包括:margin border padding content 在标准盒子模型中 conten不包括border和padding  就是他自身内容所包含的区域. 在IE盒子模型中    content包括border和padding   是内容和border padding之和. 关于盒子边框重叠颜色设置问题: //就拿下列标签来说 <ul> <li class="on">房产</li> <li>家居</li> &l

scale相关设置—颜色设置

颜色设置,在R的可视化中,应该算是相对比较重要的一项内容,如何把握颜色,很大程度上影响图形的展现效果. 在ggplot的scale设置中,颜色相关的函数较多: scale_fill/colour_hue(..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50") scale_colour_discrete 与scale_fill/colour_hue的普通参数部分是

ALV行 列颜色设置

ALV的颜色设置分为3种:行.列.单元格. 1.列颜色的设置 在 slis_t_fieldcat_alv-emphasize 中,写入需要的颜色代码. Eg: DATA: fc TYPE slis_t_fieldcat_alv WITH HEADER LINE. fc-tabname = 'ITAB'. fc-fieldname = 'COL'. fc-emphasize = 'C100'. append fc. 2.行颜色的设置 a.在要输出的 itab 中,加入 color 列,类型为C(4

函数alv下的颜色设置

ABAP中的颜色代码是由4位字都组成的 cxyz    c:color的简写,颜色代码均以C开头 x:标准色代码,SAP中一共有7个标准色    y:反转颜色启用/关闭 1/0 z:增强颜色启用/关闭 1/0 标准色代码一览表 X 颜色 主要用处 1 灰蓝色 抬头.标题栏 2 浅灰色 列表内容 3 黄色 汇总 4 蓝色 关键字 5 绿色 正确 6 红色 错误 7 橙色 控制 如: 单元格颜色控制: 定义最后显示内表的时候要在里面增加一个 colour  type lvc_T_scol,类型,这是

ubuntu终端颜色设置

Linux给人最大的享受就是可以根据个人喜好去定制令自己舒服的系统配置,像终端颜色的设置就是一个典型的例子. 图1 系统默认状态下的终端显示 在没有经过自定义配置的终端下工作久了,难免容易疲劳,因为所有输入输出都是一个颜色,对查找一些命令的执行结果很不方便.除了颜色,默认终端配置下的长长的路径名也是一个让人比较蛋疼的地方.经过网上一番资料查找,才知道,原来对终端的配置,可以写到不同的文件之中,例如:-/.bashrc./etc /bash.bashrc./etc/profile这几个文件.但是,

iOS开发UITableViewCell的选中时的颜色设置

1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionStyle = UITableViewCellSelectionStyleBlue; //灰色 cell.selectionStyle = UITableViewCellSelectionStyleGray; 2.自定义颜色和背景设置 改变UITableViewCell选中时背景色: UIColor *color