Font disappears after a certain number of cells in Excel using Apache POI

When trying to copy cell styles from an old Excel file after writing 32357 cells, the font disappears, and when you find the root of the problem, I came across an error that it throws 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)

      

and copy the file CellStyle

from the old Excel file, I did the following:

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 does this, because when I do rows.get(2506).getCell(2).getCellStyle().getFont()

it returns an object XSSFFont

( XSSFFont

which it should return style.getFont()

) and doesn't throw Exception

.

I would really appreciate it if someone could help me with this problem.

+3


source to share


1 answer


Apache POI limited to 32767 fonts per book



You will need to find a way to reuse fonts and cell styles.

+3


source







All Articles