I got this error in version EPPlus 4.0.2. There is no this error in EPPlus 4.0 beta 2.
My code:
```
rowNumberToInsert = rowNumberToInsert ?? rowNumber;
ws.InsertRow(rowNumberToInsert.Value, 1, rowNumber);
var rowToCopy = ws.GetRow((rowNumber >= rowNumberToInsert.Value) ? rowNumber + 1 : rowNumber);
rowToCopy.Copy(ws.GetRow(rowNumberToInsert.Value));
var copiedRow = ws.GetRow(rowNumberToInsert.Value);
foreach (var cellToCopy in rowToCopy)
{
var copiedCell = copiedRow.FirstOrDefault(x => x.Start.Column.Equals(cellToCopy.Start.Column));
if (copiedCell != null)
{
copiedCell.StyleName = cellToCopy.StyleName;
copiedCell.StyleID = cellToCopy.StyleID;
}
}
rowToCopy.Worksheet.Workbook.Styles.UpdateXml();
```
Stack Trace:
> at OfficeOpenXml.ExcelWorksheet.MergeCellsCollection.Delete(ExcelAddressBase Destination)
at OfficeOpenXml.ExcelRangeBase.Copy(ExcelRangeBase Destination)
at Korus.Document.Util.ExcelHelper.CopyRow(ExcelWorksheet ws, Int32 rowNumber, Nullable`1 rowNumberToInsert)
Comments: I'm not sure that is good solution, but I fixed it by changing Copy method in [ExcelRangeBase.cs](https://epplus.codeplex.com/SourceControl/latest#EPPlus/ExcelRangeBase.cs) Old code from line 2358: ``` int toRow = _toRow - _fromRow + 1, toCol = _toCol - _fromCol + 1; ``` New code: ``` int toRow = _toRow - _fromRow, toCol = _toCol - _fromCol; ```
My code:
```
rowNumberToInsert = rowNumberToInsert ?? rowNumber;
ws.InsertRow(rowNumberToInsert.Value, 1, rowNumber);
var rowToCopy = ws.GetRow((rowNumber >= rowNumberToInsert.Value) ? rowNumber + 1 : rowNumber);
rowToCopy.Copy(ws.GetRow(rowNumberToInsert.Value));
var copiedRow = ws.GetRow(rowNumberToInsert.Value);
foreach (var cellToCopy in rowToCopy)
{
var copiedCell = copiedRow.FirstOrDefault(x => x.Start.Column.Equals(cellToCopy.Start.Column));
if (copiedCell != null)
{
copiedCell.StyleName = cellToCopy.StyleName;
copiedCell.StyleID = cellToCopy.StyleID;
}
}
rowToCopy.Worksheet.Workbook.Styles.UpdateXml();
```
Stack Trace:
> at OfficeOpenXml.ExcelWorksheet.MergeCellsCollection.Delete(ExcelAddressBase Destination)
at OfficeOpenXml.ExcelRangeBase.Copy(ExcelRangeBase Destination)
at Korus.Document.Util.ExcelHelper.CopyRow(ExcelWorksheet ws, Int32 rowNumber, Nullable`1 rowNumberToInsert)
Comments: I'm not sure that is good solution, but I fixed it by changing Copy method in [ExcelRangeBase.cs](https://epplus.codeplex.com/SourceControl/latest#EPPlus/ExcelRangeBase.cs) Old code from line 2358: ``` int toRow = _toRow - _fromRow + 1, toCol = _toCol - _fromCol + 1; ``` New code: ``` int toRow = _toRow - _fromRow, toCol = _toCol - _fromCol; ```