code: POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("blank.xls")); Workbook wb = new HSSFWorkbook(fs); System.out.println(wb.getSheetName(0)); // result Ok -> Sheet1 HSSFSheet cc = wb.cloneSheet(0); FileOutputStream fileOut = new FileOutputStream(n); wb.write(fileOut); // EXCEPTION : //java.lang.IndexOutOfBoundsException: Index: 9, Size: 9 // at java.util.ArrayList.RangeCheck(ArrayList.java:507) // at java.util.ArrayList.get(ArrayList.java:324) // at org.apache.poi.hssf.record.MergeCellsRecord.getAreaAt //(MergeCellsRecord.java:201) // at org.apache.poi.hssf.record.MergeCellsRecord.serialize //(MergeCellsRecord.java:227) // at org.apache.poi.hssf.model.Sheet.serialize(Sheet.java:787) // at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes //(HSSFWorkbook.java:797) // at org.apache.poi.hssf.usermodel.HSSFWorkbook.write //(HSSFWorkbook.java:742) // at ExcelReportMaker.close(ExcelReportMaker.java:43) fileOut.close();
We're going to need more detail...like the blank.xls file you used. I just tried this code with version 2.0 FINAL and it worked ok.
java.lang.IndexOutOfBoundsException is throws if "blank.xls" file consist merged cells.
Removed variable that stores the number of merged regions in its record since the array should be the basis for this number. Less manual index tracking, the better. Thanks for problem report! Should be released shortly in a development/production release but is now available in CVS.