2

テンプレートを使用してjxl APIを使用してxlsを作成しようとすると、奇妙なArrayIndexOutOfBoundExceptionが発生します。ここに私が使用しようとしているコードのスニペットがあります

private static void readWorkSheet()throws Exception{
            File file = new File("C:\\reports\\");
            Map template = new HashMap();
            File[] listFiles = file.listFiles();
            for(File file1:listFiles){
                if(file1.getName().endsWith(".xls")){
                    System.out.println(" ==> "+file1.getName());
                    Workbook workbookTemplate = Workbook.getWorkbook(file1);
                    template.put(file1.getName(), workbookTemplate);
                }

            }
            System.out.println("template "+template);
            Workbook templateWorkBook = (Workbook)template.get("TestReport.xls");
            Sheet readSheet = templateWorkBook.getSheet("Sheet1");

            WritableWorkbook copy = Workbook.createWorkbook(new File("c://myfile_copy2.xls"));

            WritableSheet sheet = copy.createSheet("Test", 0);
            for (int i = 0; i < readSheet.getRows(); i++) {
                for (int j = 0; j < readSheet.getColumns(); j++) {
                    Cell readCell = readSheet.getCell(j, i);
                    CellFormat readFormat = readCell.getCellFormat();
                    if(readFormat != null && readCell.getContents() != null && readCell.getContents() != ""){
                        WritableCell newCell = new Label(i,j,readCell.getContents());
                        WritableCellFormat newFormat = new WritableCellFormat(readFormat);
                        newCell.setCellFormat(newFormat);
                        System.out.println("details of cell ["+i+", "+j+"]"+" Name = "+readCell.getContents());
                        System.out.println("details of newCell ["+i+", "+j+"]"+" Name = "+newCell.getContents());
                        sheet.addCell(newCell);
                    }
                }
        }
            copy.write();
            copy.close(); 
        }

これで何が欠けているのかわからない!!!

私が遭遇している例外

  Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 56
    at jxl.biff.IndexMapping.getNewIndex(IndexMapping.java:68)
    at jxl.biff.XFRecord.rationalize(XFRecord.java:1667)
    at jxl.biff.FormattingRecords.rationalize(FormattingRecords.java:443)
    at jxl.write.biff.WritableWorkbookImpl.rationalize(WritableWorkbookImpl.java:1023)
    at jxl.write.biff.WritableWorkbookImpl.write(WritableWorkbookImpl.java:701)
    at com.jxl.test.JXLTest.readWorkSheet(JXLTest.java:83)
    at com.jxl.test.JXLTest.main(JXLTest.java:30)
4

3 に答える 3