業務場景:
項目需要生成多個EXCEL表格,每個表格根據數據列表的大小動態增加Excel的行數,要保證新插入行的樣式與模板完全一致
考慮使用以下方法保證樣式的統一
cloneStyleFrom(templateStyle);
但是由于數據量比較大,拋出如下的異常
?
java.lang.IllegalStateException: The maximum number of Cell Styles was exceeded. You can define up to 64000 style in a .xlsx Workbook
解決辦法:
使用緩存把樣式保存起來,如果緩存中取不到再次通過cloneStyleFrom(templateStyle)賦值;
然后新的異常出現了
This Style does not belong to the supplied Workbook Styles Source. Are you trying to assign a style from one workbook to the cell of a different workbook?
最終的解決辦法:
在存入緩存的key中添加Workbook的HashCode值,保證只取對應的Workbook的Style緩存,最終問題得以解決!*★,°*:.☆( ̄▽ ̄)/$:*.°★* 。