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)