poi workbook 的 cellstyle 创建不能超过4000的解决方法
来源:互联网 发布:感情洁癖 知乎 编辑:程序博客网 时间:2024/05/17 06:03
利用POI进行Excel的工作表(Sheet)复制时,如果复制的工作表(Sheet)较多(100个左右)或者Excel行数较多(5000+),会报告 workbook 的 cellstyle 创建不能超过4000 的错误.
The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook
(注:网上大多解决方案为把CreateCellStyle放在循环外面,但是对于Excel 的复制 是行不通的,为了最大限度的利用CellStyle,且控制在4000个之内.构造了一个缓存对象.来缓存创建的CellStyle,所有的CellStyle获取,先通过从缓存取,如果不存在再创建.代码如下)
public class CellStyleCache { private static List<HSSFCellStyle> list = null; public CellStyleCache(){ } public static void Initialized(){ if(list==null||CacheManager.getCacheInfo("CellStyleCache").getValue()==null){ list = new ArrayList<HSSFCellStyle>(); CacheManager.putCacheInfo("CellStyleCache", list, 7200); } } public static void addCellStyle(HSSFCellStyle style){ list.add(style); } public static HSSFCellStyle getCellStyle(HSSFCellStyle cellStyle){ for(HSSFCellStyle style : list){ if(style.getAlignment() == cellStyle.getAlignment() //边框和边框颜色 && style.getBorderBottom() == cellStyle.getBorderBottom() && style.getBorderLeft() == cellStyle.getBorderLeft() && style.getBorderRight() == cellStyle.getBorderRight() && style.getBorderTop() == cellStyle.getBorderTop() && style.getTopBorderColor() == cellStyle.getTopBorderColor() && style.getBottomBorderColor() == cellStyle.getBottomBorderColor() && style.getRightBorderColor() == cellStyle.getRightBorderColor() && style.getLeftBorderColor() == cellStyle.getLeftBorderColor() //背景和前景 && style.getFillBackgroundColor() == cellStyle.getFillBackgroundColor() && style.getFillForegroundColor() == cellStyle.getFillForegroundColor() && style.getHidden() == cellStyle.getHidden() && style.getVerticalAlignment() == cellStyle.getVerticalAlignment()){ return style; } } addCellStyle(cellStyle); return null; }}
0 0
- poi workbook 的 cellstyle 创建不能超过4000的解决方法
- npoi workbook 的 cellstyle 创建不能超过4000的解决方法
- Workbook POI 对Excel表格的读取
- POI 单元格样式CellStyle
- 使用Apache POI WorkBook 进行下载文件的一个问题
- 解决java poi导出excel2003不能超过65536行的问题
- WorkBook的SaveAs方法
- WorkBook的SaveAs方法
- WorkBook的SaveAs方法
- POI导出Excel的三种 workbook 的发展与区别
- bootstrap table中cellStyle以及formatter的问题
- Excel Open Xml 中cellStyleXfs,cellStyle,cellXfs之间的关系
- workbook传输遇到的问题
- Workbook类提供的方法
- C#中WorkBook的操作
- django下video播放时间不能超过5s并且视频有时无法显示问题的解决方法
- java的Workbook.getWorkbook(fis)注意事项
- 如何查找QUERY 与 WORKBOOK的关系
- 浅谈oracle中row_number() over()分析函数用法
- Mongoose初体验
- deque容器基本操作
- 【caffe学习】caffe第二个比较典型的识别例子CIFAR_10的运行详解
- 【java】制造工厂里的开发工作
- poi workbook 的 cellstyle 创建不能超过4000的解决方法
- Bootstrap内容分类使用方法(tab)
- gets和fgets函数的区别
- 前端学习笔记-HTML(一)
- 微信小程序开发基础篇之安装(一)
- Spring入门之bean装配
- 【jQuery】管理包装集
- Hive概述
- qml文件如何查看效果