When using ExcelWorksheet -> InsertRow with a referenced row from which the styles should be copied than styles are wrong if referenced row (copyStylesFromRow) is higher or equal to the target insert position (rowFrom).
Load a sheet that has two rows (eg: row 1 + 2) with styles. Now insert a row between them and copy styles from row 2.
int targetRow = 2;
int numRowsToInsert = 1;
int refRow = 2;
sh.InsertRow(targetRow, numRowsToInsert, refRow);
The code above will insert a row but the styles are not copied from "refRow" but from itself.
Using the following code will result in correct styles:
int targetRow = 2;
int numRowsToInsert = 1;
int refRow = 2;
sh.InsertRow(targetRow, numRowsToInsert, refRow + numRowsToInsert);
The issues lies in ExcelWorksheet.cs -> public void InsertRow(int rowFrom, int rows, int copyStylesFromRow) line 1925
var cseS = new CellsStoreEnumerator<ExcelCoreValue>(_values, copyStylesFromRow, 0, copyStylesFromRow, ExcelPackage.MaxColumns); //Fixes issue 15068 , 15090
It should be
if ( copyStylesFromRow >= rowFrom )
copyStylesFromRow += rows;
var cseS = new CellsStoreEnumerator<ExcelCoreValue>(_values, copyStylesFromRow, 0, copyStylesFromRow, ExcelPackage.MaxColumns); //Fixes issue 15068 , 15090
Same here.
Workaround refRow will be moved to refRow + numRowsToInsert by the insert.
So you need to point to refRow + numRowsToInsert to copy the style
When using ExcelWorksheet -> InsertRow with a referenced row from which the styles should be copied than styles are wrong if referenced row (copyStylesFromRow) is higher or equal to the target insert position (rowFrom).
Load a sheet that has two rows (eg: row 1 + 2) with styles. Now insert a row between them and copy styles from row 2.
The code above will insert a row but the styles are not copied from "refRow" but from itself. Using the following code will result in correct styles:
The issues lies in ExcelWorksheet.cs -> public void InsertRow(int rowFrom, int rows, int copyStylesFromRow) line 1925
It should be