Skip to content

Add cell, row, and column insert/delete APIs with formula/reference update behavior per engine #16

@jochenwezel

Description

@jochenwezel

Goal

Add public ExcelOps APIs for inserting and deleting cells, rows, and columns across all supported Excel engines. The API must make formula/reference update behavior explicit because engines differ: Microsoft Excel usually updates formulas and references automatically during structural worksheet edits, while third-party engines may not do so or may only support part of the behavior.

Scope

Implement, in this order:

  1. AddColumn(sheetName, columnIndex, count, updateFormulasAndReferences)
    • columnIndex is zero-based and identifies the column before which the new column(s) are inserted.
    • count is the number of columns to insert.
  2. AddRow(sheetName, rowIndex, count, updateFormulasAndReferences)
  3. AddCell(sheetName, rowIndex, columnIndex, count, direction, updateFormulasAndReferences)
    • Direction must express shift-right vs shift-down.
  4. Matching delete APIs for columns, rows, and cells, using the same formula/reference update option.
  5. Keep/extend existing row deletion behavior (RemoveRows) without breaking existing callers. Old methods shall be marked as Obsolete with message "Use overloaded methods". From these old methods, call the new method overloads with the new option and/or mapping old behavior to the engine default.

Required API behavior

  • The base class API must expose an additional argument that tells whether formulas/references should be updated automatically.
  • Each engine implementation must override a protected property describing its native/default structural-reference update behavior.
  • If an engine cannot honor a requested updateFormulasAndReferences value, it must throw NotSupportedException instead of silently doing the wrong thing.
  • Indexes should follow the current ExcelOps convention: public row/column indexes are zero-based; engine calls convert to one-based where needed.
  • count = 0 should be a no-op; negative counts should throw ArgumentOutOfRangeException.

Engine evaluation from current codebase

Engine Current structural edit support in wrapper Native/vendor feature observed Expected initial formula/reference update behavior
Microsoft Excel Interop (ExcelOps-MicrosoftExcel) RemoveRows only COM Range.Delete(...) is already used; Excel Interop supports row/column/cell Range.Insert and Range.Delete with shift directions Expected to update formulas/references automatically. This should be represented by the protected engine property. Requests to disable update behavior may be unsupported and should throw unless a reliable implementation exists.
EPPlus FixCalcs (ExcelOps-EpplusFreeFixCalcsEdition) RemoveRows only Vendored EPPlus has ExcelWorksheet.InsertRow, InsertColumn, DeleteRow, DeleteColumn; range delete exists internally Must be verified by unit tests. Do not assume full Excel-equivalent formula/reference updates. If unsupported, throw for updateFormulasAndReferences := True and support only the no-update variant.
EPPlus Polyform (ExcelOps-EpplusPolyform) Shared with EPPlus FixCalcs Same shared implementation pattern as FixCalcs edition Same verification requirement as EPPlus FixCalcs.
Spire.Xls (ExcelOps-SpireXls) RemoveRows only via Worksheet.DeleteRow Current wrapper uses DeleteRow; column/cell insert/delete APIs need direct verification against Spire types/version Must be verified by unit tests. Throw NotSupportedException for unsupported formula/reference update variants.
FreeSpire.Xls (ExcelOps-FreeSpireXls) Shared with Spire.Xls Same shared implementation pattern as commercial Spire wrapper Same verification requirement as Spire.Xls.

Required tests

For each engine, add a durable unit test that creates a workbook (as static file in test data directory (or alternatively in memory)) with content (for later reference: "content feature") similar to:

  • Sheet Data with values in A1:C3.
  • Formulas on the same sheet that reference single cells and ranges, e.g. =B1, =SUM(B1:C1), and formulas below/right of the insertion/deletion point.
  • Cross-sheet references from a second sheet, e.g. =Data!B1 and =SUM(Data!B1:C1).
  • Globally named ranges
  • Repeated column/row headers in printing setup of sheet

The tests must verify the engine's automatic formula/reference update behavior for structural edits:

  • Insert column before B and verify whether formulas/references move to the expected addresses, according to the protected engine property.
  • Insert row before row 2 and verify the same.
  • Delete column/row and verify references or expected errors according to the engine behavior.
  • Cell insert/delete tests must cover both shift-right and shift-down directions once those APIs are implemented.
  • Clarify if there is a partially supported feature-set scenario possible for the content features or if it is always a "none or all" support

Also provide static test files in the test-data directory for long-term regression coverage, especially for saved/reloaded workbooks and cross-engine comparison.

Acceptance criteria

  • Public API exists in ExcelDataOperationsBase and all engine implementations compile.
  • Each engine explicitly declares its structural formula/reference update capability through a protected property. (all existing methods using engine defaults must be marked as obsolete to force developers to exactly specify their expectations regarding formula/reference updates when calling the Add/Delete-methods)
  • Unsupported requested behavior throws NotSupportedException.
  • Unit tests exist for every engine and document the verified behavior.
  • Static test files are added to the appropriate test_data directories.
  • Existing tests continue to pass.
  • After approval and successful tests, prepare a new release.

Notes

This issue intentionally separates ticket/evaluation from implementation. Implementation should start only after review/approval of the API shape and engine behavior matrix.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions