POI 自定义16进制颜色导出
来源:互联网 发布:mac用的office 编辑:程序博客网 时间:2024/06/12 20:39
今天导入一个Excel 要求什么格式导入就怎么显示,包括字体 颜色,还要怎么导出。这个poi导入的是16进制颜色,导出比较麻烦。具体参考以下代码吧
private CellStyle createStyle(Workbook wb, ExcelCellStyle excelCellStyle) { if(styleMap.get(excelCellStyle.getBgColor())!=null) return styleMap.get(excelCellStyle.getBgColor()); CellStyle style = wb.createCellStyle(); Font titleFont = wb.createFont(); //titleFont.setFontHeightInPoints((short)48); //titleFont.setColor(IndexedColors.DARK_BLUE.getIndex()); style = wb.createCellStyle(); String colorStr = excelCellStyle.getBgColor(); if (colorStr.length() > 6) colorStr = colorStr.substring(2); HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette();//replacing the standard red with freebsd.org red palette.setColorAtIndex((short) 9, (byte) convertHexToNumber(colorStr.substring(0, 2)),//RGB red (byte) convertHexToNumber(colorStr.substring(2, 4)),//RGB green (byte) convertHexToNumber(colorStr.substring(4, 6)) //RGB blue ); style.setFillForegroundColor((short) 9); style.setFillPattern((short) 1); //style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFont(titleFont); styleMap.put(excelCellStyle.getBgColor(), style); return style; } private int convertHexToNumber(String hex) { int num = 0; try { num = Integer.parseInt(hex, 16); } catch (Throwable t) { logger.error("数字转换异常 " + t); } return num; }
阅读全文
1 0
- POI 自定义16进制颜色导出
- JAVA POI 自定义颜色
- POI-----自定义颜色
- POI学习笔记 自定义颜色
- 【POI】自定义cell的颜色
- Java poi 自定义RGB颜色
- POI生成excel文件,自定义单元格颜色
- POI生成excel文件,自定义单元格颜色
- POI生成excel文件,自定义单元格颜色
- POI之Excel自定义单元格背景颜色
- java POI实现Excel单元格自定义颜色
- POI设置自定义的RGB背景颜色
- poi导出excel,可以自定义保存路径
- excel导入导出使用poi自定义注解
- 头部列自定义内容导出,采用POI
- excel 导入导出使用poi自定义注解
- Java POI导出Excel时,字体单元格颜色示例
- java使用poi导出excel设置颜色问题
- HDFS分布式文件系统
- 解决 Bash On Windows 无法下载(慢)
- ElasticSearch Java Api(四) -删除索引
- LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal
- Android四大组件及Intent
- POI 自定义16进制颜色导出
- LeetCode
- 经典问题a+=b和a=a+b
- Torch
- MFC模态对话框和非模态对话框及副窗口调用主窗口控件 自定义消息发送
- 关于弱网测试的一些要点,供测试的朋友们进行参考
- SIGHUP
- vivo部分笔试题(2017提前批)
- 冒泡排序算法