feat: add UseSharedStrings option for streaming writes (D1)#2326
Open
AdamDrewsTR wants to merge 2 commits into
Open
feat: add UseSharedStrings option for streaming writes (D1)#2326AdamDrewsTR wants to merge 2 commits into
AdamDrewsTR wants to merge 2 commits into
Conversation
Add UseSharedStrings bool to Options struct. When enabled, the stream writer stores unique string values once in xl/sharedStrings.xml and references them by index in cell elements (t="s" with <v>idx</v>), instead of writing inline strings for every cell. This can significantly reduce output file size when many cells contain duplicate string values. Implementation: - Add useSharedStrings, sharedStrings, sharedStringsMap fields to StreamWriter; initialized from Options in NewStreamWriter - After setCellValFunc produces an inlineStr cell with a simple <t> value, convert it to a shared string reference (t="s") - getOrAddSharedString: dedup via map, returns shared string index - writeSharedStrings: on Flush, writes xl/sharedStrings.xml with proper xml:space="preserve" for whitespace, adds content type part and workbook relationship if not already present
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2326 +/- ##
=======================================
Coverage 99.60% 99.60%
=======================================
Files 32 32
Lines 26791 26838 +47
=======================================
+ Hits 26685 26732 +47
Misses 55 55
Partials 51 51
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Cover all diff lines including getOrAddSharedString deduplication, writeSharedStrings XML generation with xml:space="preserve", content type/relationship registration, and error paths.
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
Sign up for free
to 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
Add
UseSharedStringsoption for streaming writes. When enabled, the stream writer stores unique string values once inxl/sharedStrings.xmland references them by index in cell elements (t="s"with<v>idx</v>), instead of writing inline strings for every cell.This can significantly reduce output file size when many cells contain duplicate string values.
Implementation
UseSharedStrings booltoOptionsstructuseSharedStrings,sharedStrings,sharedStringsMapfields toStreamWriter; initialized fromOptionsinNewStreamWritersetCellValFuncproduces aninlineStrcell with a simple<t>value, convert it to a shared string reference (t="s")getOrAddSharedString: dedup via map, returns shared string indexwriteSharedStrings: onFlush, writesxl/sharedStrings.xmlwith properxml:space="preserve"for whitespace-padded strings, adds content type part and workbook relationship if not already presentUsage