EPPlusSoftware / EPPlus

EPPlus-Excel spreadsheets for .NET
https://epplussoftware.com
Other
1.83k stars 279 forks source link

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

Closed owebia closed 2 years ago

owebia commented 2 years ago

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.

JanKallman commented 2 years ago

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

JanKallman commented 2 years ago

Fixed in 5.8.13 and 6.0.7

owebia commented 2 years ago

Thank you for the fix!