当尝试从旧的 Excel 文件复制单元格样式时,在写入 32357 个单元格后,字体消失了,当找到问题的根源时,我遇到了它抛出的错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -32768
at java.util.ArrayList.elementData(ArrayList.java:400)
at java.util.ArrayList.get(ArrayList.java:413)
at org.apache.poi.xssf.model.StylesTable.getFontAt(StylesTable.java:210)
at org.apache.poi.xssf.usermodel.XSSFCellStyle.getFont(XSSFCellStyle.java:561)
at Compare.writeRows(Compare.java:415)
at Compare.main(Compare.java:44)
为了从旧的 Excel 文件中复制 CellStyle
,我这样做了:
XSSFCellStyle style = workbook.createCellStyle();
style.cloneStyleFrom(oldCell.getCellStyle());
newCell.setCellStyle(style);
style.getFont(); //throws error here
newCell.setCellType(oldCell.getCellType());
但我不明白为什么要这样做,因为当我执行 rows.get(2506).getCell(2).getCellStyle().getFont()
时,它会返回一个 XSSFFont
对象(style.getFont()
应该返回的 XSSFFont
)并且不会抛出 Exception
。
如果有人能帮我解决这个问题,我将不胜感激。
最佳答案
Apache POI is limited to 32767 Fonts per workbook
您需要找到一种方法来重用字体和单元格样式。
关于java - 使用 Apache POI 在 Excel 中的一定数量的单元格后字体消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31146897/