Skip to content

Worksheet copy: add hook for naming copied tables, and fix table references in copied formulas #2453

Description

@swmal

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:

  1. 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.

  2. 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).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status
Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions