This project has moved. For the latest updates, please go here.
1
Vote

Error "row cannot be less than 1" while using 'InsertRow' in version 4.1.0 when worksheet has broken reference in NamedRange

description

Our project is upgraded from 4.0.5 to 4.1.0 and noticed this error
The following code results in exception "row cannot be less than 1"
int xlRow = 18;
using (ExcelPackage xl = new ExcelPackage(pfReport, template))
{
var wb = xl.Workbook;
ExcelWorksheet sht = wb.Worksheets[1];
--> sht.InsertRow(xlRow, 1);
xl.Save();
}
Note that the template file contains text in cells below row 18
When rolling back to version 4.0.5 the code runs normally
Comments: In our case in turned out that it was an invalid NamedRange in the Excel template. You can check this by hitting CTRL+F3 in Excel. Search for #REF! in Value column. After deleting this NamedRange the problem was solved. Error message is misleading because it suggests your parameters are invalid.

comments