Fix getTable().addRow() workflow for loaded tables #2998
+269
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
getTable().addRow()workflow fails when working with tables loaded from Excel files, throwing:This prevents a common use case: loading an Excel template with existing tables and adding rows to them programmatically.
Additionally, even when the error doesn't occur:
Solution
This PR fixes the table loading and addRow workflow with comprehensive changes to
lib/doc/table.jsandlib/doc/worksheet.js.Key Changes
lib/doc/table.js:
autoFilterRefto target header row only (e.g.,A1:C1) instead of all filter rows_updateTableRef()method to dynamically update table ranges when rows changeaddRow()to update table references and callcommit()to re-render properlyremoveRows()to update table references after removal_writeRowToWorksheet()helper for targeted row writesautoFilterRefgetter/setterlib/doc/worksheet.js:
tableReftoreffor Excel format compatibility when loadingrowsarray for loaded tables (Excel doesn't store row data in definitions)headerRowwhen columns have namesfilterButton: trueon columns whenautoFilterRefexiststest/test-table-addrow.js:
getTable().addRow()workflowExample Usage
Test Results
Credits
Original implementation by Ryan Martin (@rmartin93)
This PR adopts and submits Ryan's excellent work to upstream with comprehensive testing.
Related Issues
Checklist
Impact
This fix enables:
This is a critical fix for enterprise/production use cases where Excel templates are common.