簡體   English   中英

使用Apache POI在Excel中的一定數量的單元格后字體消失

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

當嘗試從舊的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對象( XSSFFont style.getFont()應返回的style.getFont() )並且不會拋出Exception

如果有人可以幫我解決這個問題,我真的很感激。

Apache POI限制為每個工作簿32767個字體

您需要找到一種重用字體和單元格樣式的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM