EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

Copying a worksheet to a new workbook does not copy relevant global names

Open craigbrown opened this issue 4 years ago • 3 comments

Hi, I think I've found another bug with copying worksheets (sorry).

If I copy a worksheet to a new workbook, and that worksheet contains cells that are 'global' names (i.e. names defined at the workbook level), EPPlus doesn't copy those names. This means that any formula on the worksheet that references that name will be broken on the copied sheet.

If I try the same thing in Excel, the global names on the sheet do get copied.

craigbrown avatar Mar 29 '21 17:03 craigbrown

EPPlus don't copy workbook defined names when using a worksheet as template today. For now you will have to copy any defined name on the worksheet level yourself. To add this functionality we will have to check all formulas for references to defined names on this level. I'll add this as an enhancement for a future version.

JanKallman avatar Mar 30 '21 12:03 JanKallman

Great, thanks.

Just to clarify, as I think there's two possible things here:

  1. Global Names which reference a range on the sheet being copied (e.g. if I name Sheet1!A1 as MyRange, should MyRange be copied when I copy Sheet1?)
  2. Formulas on the sheet which use a Global Name, where that name might be on a different sheet (e.g. if Sheet2 uses MyRange in a formula, should MyRange be copied when I copy Sheet2?)

In this issue I'm just talking about number 1 (which I think should just mean checking all the workbook's defined names?). I think number 2 could be quite slow and wouldn't be in line with what Excel does anyway.

craigbrown avatar Mar 31 '21 11:03 craigbrown

Yes, I see your point. I'll have a look at it for a future version.

JanKallman avatar Mar 31 '21 11:03 JanKallman