Fix XLSX export issues causing Excel 2013 recovery warnings #246
+20
−3
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
When opening XLSX files exported by the reporting engine in Excel 2013, users received warnings that the file needed to be recovered. Analysis of the exported files revealed three structural issues:
Missing font definition in
xl\styles.xml: When no custom fonts were used, the styles.xml file contained<fonts count="0"></fonts>with no font elements, violating Excel's requirement for at least one font definition.Broken relationship reference in
xl\workbook.xml: Empty reports referencedr:id="rId1"for Sheet1, but this relationship ID didn't exist in the relationships file.Missing worksheet relationship in
xl\_rels\workbook.xml.rels: When no sheets were explicitly added, the relationships file lacked the required entry linking toworksheets/sheet1.xml.These issues occurred specifically when generating empty reports or reports without formatted text, causing Excel to treat the files as corrupted.
Solution
Modified
ExcelValet.csto ensure proper XLSX structure for all scenarios:1. Added Default Font Definition
When no fonts are cached (empty reports), a default Calibri 11pt font is now added to satisfy Excel's requirements.
2. Added Worksheet Relationship for Empty Sheets
Ensures that when an empty sheet is created (as referenced in workbook.xml with
r:id="rId1"), a corresponding relationship entry is added to workbook.xml.rels.Impact
Testing
_FontCache.Count == 0or_Sheets.Count == 0Fixes #362
Original prompt
Fixes #161
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.