this is my code for(int i=0;i<30;i++) sheet.autoSizeColumn((short)i); and this is stacktrace: java.lang.ArrayIndexOutOfBoundsException: -32721 at java.util.ArrayList.get(ArrayList.java:323) at org.apache.poi.hssf.model.WorkbookRecordList.get(WorkbookRecordList.java:54) at org.apache.poi.hssf.model.Workbook.getExFormatAt(Workbook.java:624) at org.apache.poi.hssf.usermodel.HSSFCell.getCellStyle(HSSFCell.java:856) at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1424)
Your document probably contains some sort of invalid styling. It looks like the autoSizing code is trying to fetch the font details for the cell, and is failing when it can't find it. If you upload the problem file, we can look at throwing a more helpful error
i have no file. I'm trying to generate one....
please post a full test case. I can't reproduce it. Regards, Yegor
Created attachment 21072 [details] Testcase for this bug The attached test program reproduces the bug. I also get the same stacktrace and ArrayIndexOutOfBoundsException. regards, Wim
thanks for the test case. I will find time to look into it. Yegor
Improper usage. The maximum number of fonts in a workbook is 32767 ( the maximum positive short). You are creating a new font for each cell in a loop and finally the font index becomes negative. The subsequent call of HSSFSheet.autoSizeColumn results in ArrayIndexOutOfBoundsException. See how I suggest rewriting your sample code. It should work fine. P.S. I'm going to change HSSFWorkbook.createFont and throw an exception if the font index becomes greater than 32767. This way users will get a clearer indication of the problem. I will commit the fix in a little while. Regards, Yegor
Created attachment 21091 [details] Improved version of the test case by Wim Deblauwe
Thank you for looking into this. You might want to add a note to the busy developers guide (http://poi.apache.org/hssf/quick-guide.html#WorkingWithFonts) for this.