使用Apache POI在Excel中一定量的细胞后,字体消失 [英] Font disappears after a certain amount of cells in Excel using Apache POI
问题描述
在试图复制在从旧Excel文件单元格样式,写32357细胞后,字体消失,找到问题的根源时,我遇到了错误,它的投掷这次来到:
When trying to copy over cell styles from an old Excel file, after writing 32357 cells, the font disappears and when finding the root of the problem, I came across the error that it's throwing this:
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)
和到复制 CellStyle
从旧的Excel文件,我这样做:
and to copy over the CellStyle
from the old Excel file, I did this:
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
对象( XSSFFont
的 style.getFont()
应该返回),并不会引发例外
。
But I don't understand why it's doing that because when I do rows.get(2506).getCell(2).getCellStyle().getFont()
it returns an XSSFFont
object (the XSSFFont
that style.getFont()
should be returning) and doesn't throw an Exception
.
我真的AP preciate如果有人可以帮助我解决这个问题。
I would really appreciate if someone could help me with this problem.
推荐答案
您将需要找到一种方法来重用字体和单元格样式。
You will need to find a way to reuse the fonts and cell styles.
这篇关于使用Apache POI在Excel中一定量的细胞后,字体消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!