Attached the ExcelReportGenerator.java 1) If I do NOT call the autoSizeColumn method, then I am able to get the excel report. Attached the excel report without calling autoSizeColumn method. 2) When I call the autoSizeColumn method, I get the below output and exception. formatFontCount =5 columnValueStyles.length =25 column Count = 25 called autoSizeColumn for the following values of i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Vector.get(Vector.java:712) at org.apache.poi.hssf.usermodel.HSSFDataFormat.getFormat(HSSFDataFormat.java:266) at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1815) at com.jbhunt.report.generator.ExcelReportGenerator.setAutoColumnWidths(ExcelReportGenerator.java:457) at com.jbhunt.report.generator.ExcelReportGenerator.generateHSSFWorkbook(ExcelReportGenerator.java:110) at com.jbhunt.report.generator.ExcelReportGenerator.generateReport(ExcelReportGenerator.java:65) at com.jbhunt.report.service.GenerateReportSvc.generateReport(GenerateReportSvc.java:59) at com.jbhunt.pace.biz.reports.ReportHandler.getReportUsingCustomJavaAPI(ReportHandler.java:635) at com.jbhunt.pace.biz.reports.ejb.ReportsBean.getReportUsingCustomJavaAPI(ReportsBean.java:338) at com.jbhunt.pace.biz.reports.test.CustomJavaReportTest.main(CustomJavaReportTest.java:29) 14540 [main] ERROR service.GenerateReportSvc - Error in generate Excel report. com.jbhunt.report.exception.ReportServiceException: Error in generate Excel report. at com.jbhunt.report.generator.ExcelReportGenerator.generateReport(ExcelReportGenerator.java:70) at com.jbhunt.report.service.GenerateReportSvc.generateReport(GenerateReportSvc.java:59) at com.jbhunt.pace.biz.reports.ReportHandler.getReportUsingCustomJavaAPI(ReportHandler.java:635) at com.jbhunt.pace.biz.reports.ejb.ReportsBean.getReportUsingCustomJavaAPI(ReportsBean.java:338) at com.jbhunt.pace.biz.reports.test.CustomJavaReportTest.main(CustomJavaReportTest.java:29) Caused by: java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Vector.get(Vector.java:712) at org.apache.poi.hssf.usermodel.HSSFDataFormat.getFormat(HSSFDataFormat.java:266) at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1815) at com.jbhunt.report.generator.ExcelReportGenerator.setAutoColumnWidths(ExcelReportGenerator.java:457) at com.jbhunt.report.generator.ExcelReportGenerator.generateHSSFWorkbook(ExcelReportGenerator.java:110) at com.jbhunt.report.generator.ExcelReportGenerator.generateReport(ExcelReportGenerator.java:65) ... 4 more com.jbhunt.report.exception.ReportServiceException: Error in generate Excel report. at com.jbhunt.report.generator.ExcelReportGenerator.generateReport(ExcelReportGenerator.java:70) at com.jbhunt.report.service.GenerateReportSvc.generateReport(GenerateReportSvc.java:59) at com.jbhunt.pace.biz.reports.ReportHandler.getReportUsingCustomJavaAPI(ReportHandler.java:635) at com.jbhunt.pace.biz.reports.ejb.ReportsBean.getReportUsingCustomJavaAPI(ReportsBean.java:338) at com.jbhunt.pace.biz.reports.test.CustomJavaReportTest.main(CustomJavaReportTest.java:29) Caused by: java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Vector.get(Vector.java:712) at org.apache.poi.hssf.usermodel.HSSFDataFormat.getFormat(HSSFDataFormat.java:266) at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1815) at com.jbhunt.report.generator.ExcelReportGenerator.setAutoColumnWidths(ExcelReportGenerator.java:457) at com.jbhunt.report.generator.ExcelReportGenerator.generateHSSFWorkbook(ExcelReportGenerator.java:110) at com.jbhunt.report.generator.ExcelReportGenerator.generateReport(ExcelReportGenerator.java:65) ... 4 more Exception in thread "main" com.jbhunt.report.exception.ReportServiceException: Error in generate Excel report. at com.jbhunt.report.service.GenerateReportSvc.generateReport(GenerateReportSvc.java:65) at com.jbhunt.pace.biz.reports.ReportHandler.getReportUsingCustomJavaAPI(ReportHandler.java:635) at com.jbhunt.pace.biz.reports.ejb.ReportsBean.getReportUsingCustomJavaAPI(ReportsBean.java:338) at com.jbhunt.pace.biz.reports.test.CustomJavaReportTest.main(CustomJavaReportTest.java:29)
Created attachment 22205 [details] Sample report generated without calling autoSizeColumn
Created attachment 22206 [details] Excel Report Generator which is used to create the attached sample excel file
First, I was using POI-3.1 beta-2 version. Then, tried with POI-3.1 Final Version. I get the same ArrayIndexOutOfBoundException: -1 in both the versions. I sent the code to Production. It is working fine for some scenario and not working for some other scenarios.
Fixed in r676995. The method threw ArrayIndexOutOfBoundsException when style.getDataFormat() returned -1. Yegor
FYI: The following line of code was added to bypass the exception: if ( null != row.getCell(i) && null != row.getCell(i).getCellStyle() && row.getCell(i).getCellStyle().getDataFormat() > -1 ) With that line removed, the exception occurs at: sheet.autoSizeColumn((short)i);