Repository navigation
Conversation
…ini-software#295) FillTemplate wrote inline strings without xml:space="preserve", so Excel dropped leading and trailing blanks from filled values. Mark a <t> that starts or ends with white space, or that still holds a list placeholder whose value is filled in later, the way the exporter already does (mini-software#294).
This branch has not been deployed
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.
Fixes #295
Problem
FillTemplateturns template cells into inline strings (<is><t>…</t></is>) but never writesxml:space="preserve"on the<t>. Excel drops leading and trailing blanks from a<t>without that attribute, so a value such as" Jack"shows asJack, even though MiniExcel reads the blanks back.Exportalready handles this (#294,OpenXmlWritersetspreserveSpace); the template path did not.As noted in the issue, the template keeps the original
celement, so the attribute has to be added there.Change
A new
PreserveInlineStringSpacespass inOpenXmlTemplate.Impl.csruns afterUpdateDimensionAndGetRowsInfoin bothGenerateSheetByUpdateModeAsyncandGenerateSheetByCreateModeAsync. It setsxml:space="preserve"on an inline<t>when:{{Name}}) are already filled in, so this covers them and also static text;{{…}}placeholder. List rows ({{employees.name}}) are filled in later by string replacement on the row XML, so the value is not known yet. Marking the template cell lets every generated row inherit the attribute without touching the per-row code.The attribute only changes how Excel treats white space at the edges of the text. Cells without such white space look the same in Excel.
Output change
List cells that hold string placeholders now always come out as
<t xml:space="preserve">…</t>, even when the value has no edge blanks. Single values only get the attribute when they need it. The text MiniExcel reads back is the same.TestIssueI4DQUNchecked the exact<t>markup of a list cell, so its expected string was updated to include the attribute.Tests
TestIssue295inMiniExcelGithubIssuesTests(next toTestIssue294):TestTemplateEasyFill.xlsx):A2(" Jack") andE2(" Jack has 123 points") carryxml:space="preserve"and keep their text;TestTemplateBasicIEmumerableFill.xlsx):A2,B2,A3andB3carry the attribute, the blanks in" Jack","HR "and" IT "are kept, andQueryreads them back unchanged.OpenXmlTemplate.Impl.cs,TestIssue295fails (Expected: "preserve",Actual: nullonA2) and so does the updatedTestIssueI4DQUN. With it, both pass. Dropping either condition of the new check makesTestIssue295fail again, once on the single-value part and once on the list part.What was run (macOS arm64, .NET SDK 10.0.401; .NET 11 is not installed, so
-p:TargetFrameworks=…limited the build to installed frameworks):dotnet test tests/MiniExcel.OpenXml.Tests -p:TargetFrameworks=net10.0: 504 passed, 20 failed. The same 20 tests fail without this change, all withDllNotFoundException: SQLite.Interop.dll(System.Data.SQLite has no native library for osx-arm64 here).net8.0: 504 passed, the same 20 SQLite failures.dotnet test tests/MiniExcel.Csv.Tests -p:TargetFrameworks=net10.0: 82 passed, 4 failed, all SQLite native-library errors as well.dotnet build src/MiniExcel.OpenXmlfornetstandard2.0,net8.0andnet10.0: no new warnings.Not run:
net9.0andnet11.0, the SQLite-backed tests, and opening the output in Excel itself. The tests check the XML that Excel reads, not what Excel displays.Summary by CodeRabbit