Repository navigation
Treat tabs and line breaks as blanks when exporting strings - #1033
Merged
michelebastione merged 1 commit intoOct 22, 2026
Merged
Conversation
Excel drops leading and trailing blanks from a <t> without xml:space="preserve". The export only checked for a plain space, while the template pass (mini-software#295) checks char.IsWhiteSpace, so a value that starts with a tab or ends with a line break kept it in FillTemplate but lost it in Export. Inline cells and shared strings now use the same check.
michelebastione
approved these changes
Oct 22, 2026
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.
Refs #294. Follow-up to #1030, from its review.
Excel drops leading and trailing blanks from a
<t>that has noxml:space="preserve". Export added the attribute only for a plain space (StartsWith(" ") || EndsWith(" ")). #1030's template pass useschar.IsWhiteSpace, so a value starting with a tab or ending with a line break kept the attribute in FillTemplate but not in Export. Tabs and line breaks are written raw (EncodeStringpasses them through as valid XML characters), so without the attribute they are at the same risk as spaces.Change
XmlHelper.HasLeadingOrTrailingWhiteSpace:char.IsWhiteSpaceon the first and last character. No allocation; it works onnetstandard2.0.OpenXmlWriter.WriteCellAsync, the Prefix and suffix blank space will lost after SaveAs #294 check) and for shared strings (ExcelXml.SharedStrings).The formula branch of
WorksheetXml.Cellalso readspreserveSpace, so a formula that starts or ends with a tab or line break now gets the attribute too, as one with a space already did.Tests
TestIssue294WhiteSpaceexports"\tJack","Jack\n"and"Ja\tck"withStringStorageMode.InlineandShared. It checks the<x:t>insheet1.xmlorsharedStrings.xml: the attribute is present for the first two and absent for the third. Without the change tosrc/, the four preserve cases fail and the two"Ja\tck"cases pass.Commands and results
dotnet test tests/MiniExcel.OpenXml.Tests -p:TargetFrameworks=net10.0: 517 passed, 20 failed. The 20 failures are theSQLite.Interop.dllload errors on osx-arm64 described in Keep leading and trailing blanks of template values visible in Excel #1030. Withsrc/from master the same 20 fail, plus the 4 new cases.dotnet test tests/MiniExcel.Csv.Tests -p:TargetFrameworks=net10.0: 82 passed, 4 failed, all SQLite native-library errors.dotnet build src/MiniExcel.OpenXmlfornetstandard2.0,net8.0andnet10.0: no warnings in the changed files.Not run: tests on
net8.0,net9.0andnet11.0(only the .NET 10 runtime is installed here), the SQLite-backed tests, and opening the output in Excel. The tests check the XML Excel reads, not what Excel displays.Summary by CodeRabbit