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单元格背景色相关推荐

  1. poi设置excel单元格背景色

    poi任意设置excel单元格背景色 Cell cell = sheet.createRow(0).createCell(0); XSSFCellStyle cellStyle = (XSSFCell ...

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

    POI 设置Excel单元格背景色(setFillForegroundColor) 背景介绍: 使用Java开发信息系统项目,项目中往往会涉及到报表管理部分,而Excel表格首当其冲称为最合适的选择, ...

  3. 【poi第五节】poi设置Excel单元格边框 和 背景色,java设置Excel 单元格边框 和 背景色

    poi设置Excel单元格边框 和 背景色,java设置Excel 单元格边框 和 背景色 import org.apache.poi.hssf.usermodel.HSSFWorkbook; imp ...

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

    private static CellStyle leftStyle(final Workbook exportWorkbook) {CellStyle cellStyleLeft = exportW ...

  5. 【POI框架实战】——POI设置Excel单元格格式

    背 景 "这个excel中的数据怎么不能做加法啊?"."标头这一行的字体怎么这么小啊,我都看不清"."这一列能不能换个颜色,明显一些".&q ...

  6. java excel单元格背景色_POI 设置Excel单元格背景色(setFillForegroundColor)

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

  7. Apache POI 设置Excel单元格的宽度和高度

    原博作者:Tony Qu 原博链接 在Excel中,单元格的宽度其实就是列的宽度,因为Excel假设这一列的单元格的宽度肯定一致.所以要设置单元格的宽度,我们就得从列的宽度下手,HSSFSheet有个 ...

  8. hutool导出excel 设置单元格日期格式 poi设置excel单元格日期格式

    hutool导出导入excel很方便,但没有依赖poi,需要手动添加poi依赖. <properties><poi.version>4.1.2</poi.version& ...

  9. Aspose Cell设置Excel单元格背景色

    var s = ws.Cells[7, 1].GetStyle(); s.ForegroundColor = Color.Cyan; s.Pattern = BackgroundType.Solid; ...

最新文章

  1. 零基础自学python看什么书-零基础学习Python那些书值得看
  2. MySQL MySQL为什么有时候会选错索引?
  3. Algorithms_算法专项_Bitmap原理及应用
  4. 复习笔记(一)——C++基础
  5. 使用 RUP 管理小型项目和团队
  6. 使用crontab定时保存top信息到文件,并保存到数据库中
  7. linux系统编程之进程(七):system()函数使用
  8. php 类的注释标准,php标准注释
  9. [读书笔记]读《Effective Objective-C 2.0编写高质量iOS与OS X代码的52个有效方法》(一)...
  10. MOQL—过滤器(Filter)
  11. LETTers比赛第三场 --1002 Ignatius and the Princess III解题报告
  12. Spring Security入门教程
  13. Kindle、epub 、azw3修改行间距
  14. waiting for headers
  15. 最新电影《D战》幕后真实案件:暗夜黑客组织被端
  16. 搜索引擎类网站调查报告
  17. 门户通专访爱思网创始人韩笑:SNS网站必然走向实用化!
  18. 未来交通已经“上线” 高德地图智慧交通合作已攻150城,半年大增约五成
  19. 如何剪切视频,只截取视频中间的一部分
  20. rust嵌入式key/value数据库

热门文章

  1. SAS学习第11章:试验设计
  2. 支付宝报错:系统繁忙,请稍后重试(ALIN10070)
  3. 7zZip zip RAR iOS
  4. 实现mini智能助理—模型训练
  5. [策略模式]在游戏开发中的应用
  6. 摩客怎么设置安卓的dp_Android中dp和px之间进行转换
  7. 从千篇一律到独树一帜,TOOM舆情监测系统助你成功!
  8. php早午晚问候语_PHP根据时间设置问候语
  9. 计算机网络实验(一)
  10. 利用Google日历安排工作计划