Conversation
The Open XML SDK models a part as its root element, so the comments and processing instructions between the XML declaration and that element are not part of the tree and are gone the first time the part is re-serialized. The declaration itself survives (the SDK re-emits it), so the save is silent: the part stays well-formed, the command exits 0, and `raw` returns the root element only. Measured on xl/workbook.xml and xl/worksheets/sheet1.xml. Capture each part's prolog from the package as opened, and re-attach it to the written zip from WriteBackFilteredPackage -- the single method both the mid-session flush and the close-time write go through, which is why the restore hangs on AtomicPackageWriter's postProcessTemp hook rather than on two separate call sites. A package whose parts have the usual declaration-then-root shape captures nothing, so those saves are byte-for-byte what they were. Refs iOfficeAI#409 (xlsx; pptx still drops it).
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
The Open XML SDK models a part as its root element, so the comments and
processing instructions that sit between the XML declaration and that element
are not part of the tree. They are gone the first time the part is
re-serialized — and because the SDK re-emits the declaration itself, the loss
is silent: the saved part stays well-formed, the command exits 0, and
rawreturns the root element only.This is the xlsx half of the same defect reported in #409. It captures each
part's prolog from the package as it is opened, and re-attaches it to the
written zip. A package whose parts have the usual declaration-then-root shape
captures nothing, so those saves are byte-for-byte what they were.
Measured before and after on the same two commands, on
xl/workbook.xmlandxl/worksheets/sheet1.xml:The prolog lost is the same one in every case:
<!-- KEEP-ME: prolog note --><?xml-stylesheet type="text/xsl" href="x.xsl"?>,immediately after the declaration and before the root element.
Where the fix lives
ExcelHandlerdiffers fromWordHandlerhere in a way worth naming. Bothsavesand close write the file through one method —WriteBackFilteredPackage— so the restore is attached to the single atomic write it performs, via
AtomicPackageWriter's existingpostProcessTemphook (which runs against thetemp file before the
File.Replace, so the session's own handle on the originalis never in the way). The docx path needed two hooks because its two writes go
through different methods; this one needs one, and hanging the restore on the
shared write is what makes the mid-session
saveand the close path coveredtogether rather than by two independently-drifting call sites.
Core/XmlPrologPreserver.csis the same file as in #421, byte for byte (blobb642fb8c74466f0073f31dae8480ba07b349f63c), so if #421 lands first the twomerge cleanly and this PR reduces to the
ExcelHandlerchange.Tests
dotnet build src/officecli/officecli.csproj -c Release— 0 errors, nonew warnings (the two pre-existing ones are unchanged)
(6/6 cases lost the prolog) and passing after (6/6 preserved), on both the
saveand theclosewrite pathentries are identical to the base build's once the save timestamp is
normalised — nothing is rewritten that did not need to be
script above is the verification
Open question
I read Rule 1 as "one format per PR", so this is the xlsx half alone and the pptx half (
ppt/presentation.xml, which still drops the prolog) would follow separately. I did ask on #409 whether you would rather have the three formats in one PR or one each, and had no answer, so I picked the reading that keeps each change independently revertable. Say the word and I will either fold pptx in here or open it on its own.Refs #409 (xlsx; pptx still drops it).