Skip to content

Save edits to the main part it was read from, not always document.xml - #202

Merged
satoryu merged 1 commit into
ruby-docx:masterfrom
jayhemnani9910:fix/save-main-part-name
Nov 17, 2026
Merged

satoryu merged 1 commit into
ruby-docx:masterfrom
jayhemnani9910:fix/save-main-part-name

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Files saved by Word for the web keep the main part in word/document2.xml (#83). Document.open reads it through the word/document*.xml glob, but #update always writes to word/document.xml. That entry is not in the zip, so save drops it and copies the original document2.xml: every edit is lost, with no error.

open now remembers the entry it read, and #update writes back to it.

Added a spec on office365.docx that edits the first paragraph, saves and reopens; it fails without the change. rake spec passes. Also checked with a template filled through TextRun#substitute: before, the saved file still had {{name}}; after, it has the values.

This keeps the glob. Resolving the part from [Content_Types].xml would be a bigger change, so I left it out.

@satoryu
satoryu merged commit b101ffd into ruby-docx:master Nov 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants