jxl APIを使用して、奇妙なArrayIndexOutOfBoundExceptionを実行するテンプレートを使用してxplを作成しようとしているときはいつでも。ここ は、私がArrayIndexOutOfBoundExceptionあるシートから別のシートにコンテンツをコピーしようとするとjxl apiが発生する
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)
上記のスタックトレースは、いずれのコードも参照していないようです。あなたは例外からの完全なスタックトレースを含めましたか? –
完全な例外トレースを追加しました – Amit
try/catchでコードを囲みます。ファイルがC:\で作成されていますか? – Alfabravo