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

Free Support Forum - aspose.com

Exception when insert/copy rows

LoadOptions oo = new LoadOptions();
oo.setMemorySetting(MemorySetting.MEMORY_PREFERENCE);
Workbook wb = new Workbook("C:/x.xlsx", oo);
Worksheet s = wb.getWorksheets().get(0);
Cells ocells = s.getCells();
Workbook nwb = new Workbook();
nwb.getSettings().setMemorySetting(MemorySetting.MEMORY_PREFERENCE);
Cells cells = nwb.getWorksheets().get(0).getCells();
cells.setMemorySetting(MemorySetting.MEMORY_PREFERENCE);

int insertRow = 4;
int cRow = 10003;
int posRow = 4;
int tailRows = 1;
int maxRowsPerSheet = 0x100000;

Cells excelResultCells = cells;

for (int i = 0; i < 140; i++) {
if (insertRow + cRow - posRow + 1 + tailRows >= maxRowsPerSheet) {
excelResultCells.insertRows(insertRow, maxRowsPerSheet - insertRow - tailRows);
excelResultCells.copyRows(ocells, posRow, insertRow, maxRowsPerSheet - insertRow - tailRows);
int idx = nwb.getWorksheets().add();
Worksheet newSheet = nwb.getWorksheets().get(idx);
newSheet.copy(s);
excelResultCells = newSheet.getCells();
excelResultCells.deleteRows(posRow, maxRowsPerSheet - insertRow - tailRows);
insertRow = cRow + 1 - (maxRowsPerSheet - insertRow - tailRows);
} else {
excelResultCells.insertRows(insertRow, cRow - posRow + 1);
excelResultCells.copyRows(ocells, posRow, insertRow, cRow - posRow + 1);
insertRow += cRow - posRow + 1;
}
}

Hi,

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue by executing your sample code with your sample excel file using the latest version: Aspose.Cells for Java (Latest Version) and found, the code throws exception as per your description.

This issue has been logged as

  • CELLSJAVA-42231 - Exception occurs on inserting rows

Here is the exception generated by the code for a reference.

Exception

Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 1050217

at com.aspose.cells.zbfc.b(Unknown Source)

at com.aspose.cells.zbeq.b(Unknown Source)

at com.aspose.cells.zbeq.f(Unknown Source)

at com.aspose.cells.zh.i(Unknown Source)

at com.aspose.cells.zbeo.a(Unknown Source)

at com.aspose.cells.zif.a(Unknown Source)

at com.aspose.cells.zif.insertRows(Unknown Source)

at ClsAspose.f1(ClsAspose.java:65)

Hi,


Please try our latest version/fix: Aspose.Cells for Java (Latest Version)

Your issue “CELLSJAVA-42231” should be fixed in it.

Let us know your feedback.

Thank you.

Hi,


We recommend you kindly try our latest version/fix: Aspose.Cells for Java v17.3.8 (attached).

We have made some more enhancements for Memory mode to avoid potential exceptions.

Thank you.

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


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