简体   繁体   English

使用Apache POI在Excel中的一定数量的单元格后字体消失

[英]Font disappears after a certain amount of cells in Excel using Apache POI

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: 当尝试从旧的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)

and to copy over the CellStyle from the old Excel file, I did this: 并从旧的Excel文件复制CellStyle ,我这样做:

XSSFCellStyle style = workbook.createCellStyle();
style.cloneStyleFrom(oldCell.getCellStyle());
newCell.setCellStyle(style);
style.getFont(); //throws error here
newCell.setCellType(oldCell.getCellType());

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 . 但我不明白它为什么这样做,因为当我执行rows.get(2506).getCell(2).getCellStyle().getFont()它返回一个XSSFFont对象( XSSFFont style.getFont()应返回的style.getFont() )并且不会抛出Exception

I would really appreciate if someone could help me with this problem. 如果有人可以帮我解决这个问题,我真的很感激。

Apache POI is limited to 32767 Fonts per workbook Apache POI限制为每个工作簿32767个字体

You will need to find a way to reuse the fonts and cell styles. 您需要找到一种重用字体和单元格样式的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM