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.
Hi,
Hi Sébastien,
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,
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
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 !
Hi,
Hi Sébastien,
Hi,
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.
Hi,
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 8.7.0.0. When I use 7.3.1.0, 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,