ArrayIndexOutOfBoundException with jxl api when trying to copy content from one sheet to another

Whenever I am trying to use template to create xls using jxl API running into weird ArrayIndexOutOfBoundException. Here is the snippet of code I am trying to use 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(); } Not sure what I am missing in this !!! Exception I am running into Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 56 at jxl.biff.IndexMapping.getNewIndex( at jxl.biff.XFRecord.rationalize( at jxl.biff.FormattingRecords.rationalize( at jxl.write.biff.WritableWorkbookImpl.rationalize( at jxl.write.biff.WritableWorkbookImpl.write( at com.jxl.test.JXLTest.readWorkSheet( at com.jxl.test.JXLTest.main(
The stack trace above does not appear to refer to any of your code. Did you include the complete stack trace from the exception?

以上就是ArrayIndexOutOfBoundException with jxl api when trying to copy content from one sheet to another的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准