EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

ExcelNamedRangeCollection.Insert causes error "We found a problem with some content in 'test.xlsx'."

Open owebia opened this issue 2 years ago • 1 comments

Hi,

If a named range references a whole column (e.g. Sheet1!$C:$C) and we insert rows in the worksheet, the range address is changed to something like Sheet1!Sheet1!$C1:#REF!.

When we try to open the resulting file, Microsoft Excel display the following error: We found a problem with some content in 'test.xslx'. Do you want us to recover as much as we can? If you trust the source of this workbook, click Yes.

Example:

var sheet = package.Workbook.Worksheets["Sheet1"];
var range = package.Workbook.Names["MyName"];
var address1 = range.Address; // The value is `Sheet1!$C:$C`

sheet.InsertRow(8, 2, 7);

var address2 = range.Address; // The value is `Sheet1!Sheet1!$C1:#REF!`

A way to fix this issue is to skip the address change if the range references a whole column or a whole row.

A.L.

owebia avatar Aug 09 '22 08:08 owebia

Thanks for reporting this. I'll provide a fix shortly.

JanKallman avatar Aug 10 '22 08:08 JanKallman

Fixed in 5.8.13 and 6.0.7

JanKallman avatar Aug 31 '22 07:08 JanKallman

Thank you for the fix!

owebia avatar Aug 31 '22 08:08 owebia