We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

IndexOutOfBoundsException on saving particular table/range

I get IndexOutOfBoundsException when I try to save the particular table using PasteOptions.
I have attached the XLSX file for your reference.
The table being used from the given file is "DailySchedule" from the worksheet "Daily Schedule"

Following is the code snippet being used for saving the table from the source to the new target workbook:
Workbook workbook = new Workbook("C:/temp/Daily work schedule.xlsx");
com.aspose.cells.Worksheet selectedWorksheet = workbook.getWorksheets().get("Daily Schedule");
ListObject listObject = selectedWorksheet.getListObjects().get("DailySchedule");
Range sourceRange = listObject.getDataRange();

Workbook targetWorkbook = new Workbook(FileFormatType.XLSX);
WorksheetCollection targetWsc = targetWorkbook.getWorksheets();
com.aspose.cells.Worksheet targetWs = (com.aspose.cells.Worksheet)targetWsc.get(0);
Range targetRange = targetWs.getCells().createRange(0, 0, sourceRange.getRowCount(), sourceRange.getColumnCount());
PasteOptions options = new PasteOptions();
options.setPasteType(PasteType.ALL);
targetRange.copy(sourceRange, options);

File htmlFile = new File("C:/temp/TargetDailyShedule.xlsx");
targetWorkbook.save(htmlFile.getAbsolutePath(), SaveFormat.XLSX);

Following is the stacktrace of the exception that occurs:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 8, Size: 4
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at com.aspose.cells.NameCollection.get(Unknown Source)
at com.aspose.cells.bpl.a(Unknown Source)
at com.aspose.cells.bpl.a(Unknown Source)
at com.aspose.cells.um.a(Unknown Source)
at com.aspose.cells.um.a(Unknown Source)
at com.aspose.cells.FormatCondition.a(Unknown Source)
at com.aspose.cells.FormatCondition.getFormula1(Unknown Source)
at com.aspose.cells.qo.a(Unknown Source)
at com.aspose.cells.qo.a(Unknown Source)
at com.aspose.cells.qo.x(Unknown Source)
at com.aspose.cells.qo.a(Unknown Source)
at com.aspose.cells.qm.p(Unknown Source)
at com.aspose.cells.qm.b(Unknown Source)
at com.aspose.cells.qm.g(Unknown Source)
at com.aspose.cells.qm.a(Unknown Source)
at com.aspose.cells.ql.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)

Hi,


After an initial test, I observed the issue as you mentioned by using your sample code and template file. I got:
java.lang.IndexOutOfBoundsException: Index: 8, Size: 4
on saving particular table/range.
e.g
Sample code:

Workbook workbook = new Workbook(“Daily+work+schedule.xlsx”);
com.aspose.cells.Worksheet selectedWorksheet = workbook.getWorksheets().get(“Daily Schedule”);
ListObject listObject = selectedWorksheet.getListObjects().get(“DailySchedule”);
Range sourceRange = listObject.getDataRange();

Workbook targetWorkbook = new Workbook(FileFormatType.XLSX);
WorksheetCollection targetWsc = targetWorkbook.getWorksheets();
com.aspose.cells.Worksheet targetWs = (com.aspose.cells.Worksheet)targetWsc.get(0);
Range targetRange = targetWs.getCells().createRange(0, 0, sourceRange.getRowCount(), sourceRange.getColumnCount());
PasteOptions options = new PasteOptions();
// options.setPasteType(PasteType.ALL);
// options.setTranspose(true);//it works but gives corrupted file.

// targetRange.copy(sourceRange, options);
targetRange.copy(sourceRange);

File htmlFile = new File(“f:\files\outTargetDailyShedule1.xlsx”);
targetWorkbook.save(htmlFile.getAbsolutePath(), SaveFormat.XLSX);

I have logged a ticket with an id “CELLSJAVA-40938” for your issue. We will look into your issue soon.

Once we have any update on it, we will let you know here.

Thank you.

Hi,

Please try our latest version/fix: Aspose.Cells for Java v8.1.2.5 (attached)

Your issue should be fixed in it.

Let us know your feedback.

Thank you.

The issues you have found earlier (filed as CELLSJAVA-40938) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi,


I have tested it with the Aspose Cells 8.3.0 and observed that it works fine.

Thanks,
Neeraj

Hi,


Thanks for your feedback.

Good to know that it figures out your issue now. Feel free to write back if you have further comments or questions, we will be happy to assist you soon.

Thank you.