- Notifications
You must be signed in to change notification settings - Fork1.9k
feat: Add applyWidthHeightFormats option for pivot table column widths#2997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
protobi-pieter wants to merge1 commit intoexceljs:masterChoose a base branch fromprotobi:upstream-pr/pivot-column-width
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+200 −9
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
By default, Excel pivot table styles control column widths, overridingworksheet column widths. This adds an optional parameter to preservecustom column widths.Changes:- Added applyWidthHeightFormats option to addPivotTable() (default: '1')- When set to '0', Excel preserves worksheet column widths- Documented in README with usage examples- Added test case demonstrating custom width preservationUsage: pivotSheet.addPivotTable({ sourceSheet: dataSheet, rows: ['Region'], columns: ['Quarter'], values: ['Amount'], applyWidthHeightFormats: '0' // Preserve worksheet widths });No breaking changes - defaults to '1' (existing behavior).Closes#2🤖 Generated with [Claude Code](https://claude.com/claude-code)Co-Authored-By: Claude <noreply@anthropic.com>protobi-pieter added a commit to protobi/exceljs that referenced this pull requestNov 7, 2025
All original features now submitted to upstream:- PRexceljs#2995: Multiple pivot tables support- PRexceljs#2996: XML special character escaping- PRexceljs#2997: Pivot table column width controlTotal: 9 PRs submitted to upstream (6 adopted + 3 original)All features are now pending upstream review.🤖 Generated with [Claude Code](https://claude.com/claude-code)Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
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.
Summary
Adds optional
applyWidthHeightFormatsparameter to pivot tables, allowing users to preserve worksheet column widths instead of using Excel's default pivot table style widths.Problem
By default, Excel pivot table styles control column widths, overriding any custom column widths set on the worksheet. This is Excel's standard behavior (
applyWidthHeightFormats='1'), but users often want to preserve their carefully crafted column widths.Current behavior:
The pivot table style resets all column widths, making custom sizing impossible.
Solution
Add optional
applyWidthHeightFormatsparameter (default:'1'for backwards compatibility):Implementation
1.API Change (
lib/doc/pivot-table.js)Added parameter to pivot table model with sensible default:
2.XML Generation (
lib/xlsx/xform/pivot-table/pivot-table-xform.js)Pass the setting to Excel via OOXML attribute:
PerOOXML spec:
'1'(default) - Apply pivot table style widths/heights'0'- Preserve worksheet widths/heights3.Test Case (
test/test-pivot-table.js)Added test demonstrating custom width preservation:
Use Cases
1. Custom Dashboard Layouts
2. Print-Optimized Reports
3. Responsive Layouts
Backwards Compatibility
✅100% backwards compatible
'1'maintains existing behaviorStandards Compliance
FollowsOffice Open XML Part 1 Section 18.10:
This is a standard Excel feature exposed through the OOXML format.
Files Changed
lib/doc/pivot-table.js- Accept parameter, set defaultlib/xlsx/xform/pivot-table/pivot-table-xform.js- Pass to XMLtest/test-pivot-table.js- Test case demonstrating featureChecklist
Fork Context: This PR originates from@protobi/exceljs, a temporary fork with pivot table enhancements. We're submitting all improvements back to upstream.