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

Free Support Forum - aspose.com

copyRow fails randomly

I have templates with two-rows arrays with ranges for columns.
Format is different for first row and second one.
When data is loaded from DB, I must expand the rows depending on the count of results (rowCount) obtained from DB.
In order to benefit from an automatic expansion of the column ranges, I expand the array by inserting rows starting from the second row (the middle of the ranges).
Then, I copy even rows, then I copy odd rows to have the styles of the couple of initial rows to be propagated correctly.

cells.insertRows(firstRowIndex + 1, rowCount - 2);
for (int i = 0; i < (rowCount - 2) / 2 + rowCount % 2; i++) {
cells.copyRow(cells, firstRowIndex + rowCount - 1, firstRowIndex + 2 * i + 1); // even rows
for (int i = 0; i < (rowCount - 2) / 2 + rowCount % 2; i++) {
cells.copyRow(cells, firstRowIndex, firstRowIndex + 2 * i + 2); // odd rows

After that, values are filled in the expanded ranges and the same work is done for a next array on the same sheet.

The problem encountered is an Exception thrown by the ‘copyRow’ in the middle of its execution (datas for the row have been partially copied).

com.aspose.cells.CellsException: Cell has been removed: R149
com.aspose.cells.CellsException: Cell has been removed: R149
at com.aspose.cells.Cell.a(Unknown Source)
at com.aspose.cells.RowCollection.a(Unknown Source)
at com.aspose.cells.Cells.copyRows(Unknown Source)
at com.aspose.cells.Cells.copyRow(Unknown Source)

The aforementioned row (149) is the one being copied during ‘even’ copies (that has already been copied correctly for some previous loops).

I was not able to reproduce this behaviour in a simple sample.
The error seems to happen or not depending on the parameters (rowCount and data set in the previously expanded arrays).

In the screenshots, with rowCount=18 and firstRowIndex=132:
1) the array before expansion
2) the array partially expanded when the process fails. (row 149 is the last white row with a date in first cell, already copied 5 times correctly)

No error when executing same code but replacing copyRow by a loop on every cell of the row and copying style and formulas.


Thanks for providing us some details and screen shots.

I am afraid, we cannot evaluate your issue properly unless we have your simple sample console application (runnable) to reproduce the issue on our end. It looks like the issue is with your code or logic (as you cannot reproduce the issue in a simple application) although we are not entirely certain about it. We request you to kindly create a separate simple console application (runnable), zip it and post us here with all the details and template files (if you have any), so we could look into your issue precisely and log it into our database for correction. Please remove any inter dependencies regarding database or data source, you may create dynamic data tables in your code, so we could run it on our end.

Looking forward to get your sample console demo application.

PS. We also recommend you to kindly try our latest version/fix: Aspose.Cells for Java v8.6.2 (if you are not already using it) to check if it makes any difference.

Thank you.

Hi Sébastien,

Thank you for contacting Aspose support.

I have tried to evaluate the presented scenario against the latest version of Aspose.Cells for Java 8.6.2 and following piece of simple code. I am afraid, I was not able to observe the said exception even once during the testing of more than 50 cycles (because you mentioned the problem is random). If you are not already using the latest revision of the API then please give it a try on your end. In case the problem persists, please provide us an executable sample application (along with dependencies & input documents) that could allow us to replicate the issue on our side.


Workbook book = new Workbook(filePath);
Worksheet sheet = book.getWorksheets().get(0);
Cells cells = sheet.getCells();
int rowCount = 100;
int firstRowIndex = 2;
cells.insertRows(firstRowIndex + 1, rowCount - 2);
for (int i = 0; i < (rowCount - 2) / 2 + rowCount % 2; i++) {
cells.copyRow(cells, firstRowIndex + rowCount - 1, firstRowIndex + 2 * i + 1); // even rows
System.out.println( (firstRowIndex + rowCount - 1) + " " + (firstRowIndex + 2 * i + 1));
for (int i = 0; i < (rowCount - 2) / 2 + rowCount % 2; i++) {
cells.copyRow(cells, firstRowIndex, firstRowIndex + 2 * i + 2); // odd rows
System.out.println( (firstRowIndex) + " " + (firstRowIndex + 2 * i + 2));
Amjad Sahi:
It looks like the issue is with your code or logic (as you cannot reproduce the issue in a simple application)

The portion of code and the indications I've provided reveal that, in a loop that only calls 'copyRow', copyRow(rowA, rowB) works well and on a next iteration, copyRow(rowA, rowC) throws an exception with rowA not found.

Hi Sébastien,

As discussed earlier, we cannot be sure whether the problem is in the code/logic or a bug on the part of Aspose.Cells APIs unless you share an executable standalone sample application along with its dependencies for thorough investigation. Looking forward to the above requested in order to assist you further in this regard.

I’ve found the cause of the bug : memory management.
Therefore, I could reproduce the error.

Run Test class with USE_MEMORY_PREFERENCE set to true or false.

When true, the error appears, when false, everything is OK.

Attached a ZIP file containing :
Example.xlsx : template file
data.ser : serialized data needed for the excel generation
Test.java : the main class to run
EnrichedResultSet.java : type for deserialization

Hi Sébastien,

Thank you for the sample project. We have evaluated the presented scenario while using the latest version of Aspose.Cells for Java 8.6.2, and we are able to replicate the CellsException: Cell has been removed: . This scenario needs thorough investigation therefore we have logged it in our bug tracking system as CELLSJAVA-41596. Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Could we have an update on this one as for the moment, this bug breaks the confidence in using memory management ?
And the work-around consisting in copying values and styles cell by cell is far from being cost-effective !


Well, we are currently working over your issue “CELLSJAVA-41596” and hopefully it will be fixed soon. I have also asked the concerned developer from product team to update on it or provide an eta (if possible).

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

Thank you.

Hi Sébastien,

This is to update you that the ticket logged earlier as CELLSJAVA-41596 has been marked resolved. We will shortly provide the fix here after ensuring the quality of the build and incorporating other enhancements.


Thanks for using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for Java (Latest Version) and let us know your feedback.

Seems fixed !

Worked with the provided sample and with my initial private data that revealed the problem.

Thank you.


Thanks for your feedback and using Aspose.Cells.

It is good to know that your issue is resolved with the latest fix. Let us know if you encounter any other problem, we will be glad to look into it and help you further.

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

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

Is this issue fixed in .Net version as well?

I am running into same issue with When I use, it seems to work fine with same code.

I am trying to insert data from datatable (DB query) into 2nd row onwards. with InsertRows = true. Before doing that, I am copying data cells into an array so I can set style and conditional formatting onto inserted rows.

dataCells = new Cell[rangeColCount];
headerCells = new Cell[rangeColCount];
for (int i = 0; i < rangeColCount; i++)
dataCells[i] = rangeByName.Worksheet.Cells[rangeSecondRow, rangeFirstColumn + i];
headerCells[i] = rangeByName.Worksheet.Cells[rangeFirstRow, rangeFirstColumn + i];


ImportTableOptions options = new ImportTableOptions();
options.InsertRows = true;
options.IsFieldNameShown = true;

int countRows = ws.Cells.ImportData(dt, c.Row, c.Column, options);

It fails on this line: cell.SetStyle(headerCells[j].GetStyle());

headerCells[j].GetStyle() throws:

+ base {“Cell has been removed: A87”} System.ApplicationException {Aspose.Cells.CellsException}

Hi Jayesh Jain,

Thanks for your sample code snippet and some details.

Generally all the JAVA fixes are also included in the relevant .NET version and vice versa. Could you please try our latest version/fix: Aspose.Cells for .NET (Latest Version) if it makes any difference. If you still find the issue, please create a simple executable standalone sample application, zip the project and post us here to reproduce the issue on our end. We will check it soon. Also, provide your template file (if any). Please create DataTables dynamically in your code and remove any other inter-dependencies, so we could evaluate/run your project and log a ticket into our database for your issue to be fixed soon.

Thank you.