EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

System.ArgumentOutOfRangeException when using ExcelWorksheet.InsertRow

Open thetilliwilli opened this issue 3 years ago • 2 comments

[Description] EPPlus version: 5.8.1

  1. Put some data (it may be even cell with changed background only) at last row of excel image

  2. insert 1 row at any position, e.g. ExcelWorksheet.InsertRow(1,1)

[Result]

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'Can't insert. Rows will be shifted outside the boundries of the worksheet.')
   at OfficeOpenXml.Core.Worksheet.WorksheetRangeInsertHelper.ValidateInsertRow(ExcelWorksheet ws, Int32 rowFrom, Int32 rows)
   at OfficeOpenXml.Core.Worksheet.WorksheetRangeInsertHelper.InsertRow(ExcelWorksheet ws, Int32 rowFrom, Int32 rows, Int32 copyStylesFromRow)
   at OfficeOpenXml.ExcelWorksheet.InsertRow(Int32 rowFrom, Int32 rows, Int32 copyStylesFromRow)
   at OfficeOpenXml.ExcelWorksheet.InsertRow(Int32 rowFrom, Int32 rows)

[ExpectedResult] No exception, new rows inserted, excessing count of rows (i mean Rows beyond > 1,048,576) are annihilated.

[AdditionalInfo] I'm aware of Excel behaviour: image

but, it seems to be ok in GUI app - cause user get instant feedback and can react.

another story: EPPlus on backend without direct interaction with user - it could handle this on behalf of user (kind of cool)

Right now before any insertion, a developer should check Sheet.Dimension.End, find last index of Row, count how many Rows to delete to free space. Maybe the more appropriate place for such code is inside EPPlus library?

thetilliwilli avatar Jan 21 '22 14:01 thetilliwilli

This is the intended behaviour. Discarding overflowing cells on rows or columns without a notification sounds dangerous to me. If you are writing a rolling log appender I can understand this behaviour, but Excel data is usually financial data. What is the use case for your scenario?

JanKallman avatar Jan 25 '22 06:01 JanKallman

Use case: Report system which uses excel template file (like in the screenshot below) and fills with data.

Example image

The system inserts data at marker position {{table1}} (see (1) in the screenshot). Below the marker there is some text (see (2) in the screenshot) that is not important in case of overflowing.

thetilliwilli avatar Jan 26 '22 13:01 thetilliwilli