Background
When a worksheet containing tables is copied within the same workbook, EPPlus renames each copied table to a generated name (Table1, Table2, ...). There are two problems:
-
No naming hook. Callers who need meaningful table names on the copy (e.g. stamping per-market sheets from a template) have no way to set names at copy time, and must match generated names back to originals by fragile heuristics after the fact.
-
Copied formulas are not adjusted. Formula cells are cloned verbatim, so a copied SUM(BoxOffice[Col]) still references the source table name while the copied table has been renamed to Table1. The copy is left internally inconsistent. This happens because copied tables are written directly to XML (for performance), bypassing the ExcelTable.Name setter that normally adjusts references.
Proposed change
- Add an options object to
Worksheets.Copy/Add with a per-table callback to assign a custom name (routed through the ExcelTable.Name setter, so references update and uniqueness is validated).
- Fix the underlying bug: adjust table references in copied formulas, scoped to the copied worksheet so the source sheet is untouched.
- Add unit tests covering both the default
Table{n} behaviour and the naming hook (previously untested).
Background
When a worksheet containing tables is copied within the same workbook, EPPlus renames each copied table to a generated name (
Table1,Table2, ...). There are two problems:No naming hook. Callers who need meaningful table names on the copy (e.g. stamping per-market sheets from a template) have no way to set names at copy time, and must match generated names back to originals by fragile heuristics after the fact.
Copied formulas are not adjusted. Formula cells are cloned verbatim, so a copied
SUM(BoxOffice[Col])still references the source table name while the copied table has been renamed toTable1. The copy is left internally inconsistent. This happens because copied tables are written directly to XML (for performance), bypassing theExcelTable.Namesetter that normally adjusts references.Proposed change
Worksheets.Copy/Addwith a per-table callback to assign a custom name (routed through theExcelTable.Namesetter, so references update and uniqueness is validated).Table{n}behaviour and the naming hook (previously untested).