Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/docx/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def initialize(path_or_io, options = {})
document = @zip.glob('word/document*.xml').first
raise Errno::ENOENT if document.nil?

@document_path = document.name
@document_xml = document.get_input_stream.read
@doc = Nokogiri::XML(@document_xml)
load_styles
Expand Down Expand Up @@ -261,7 +262,7 @@ def load_rels
# end of methods that make edits?
#++
def update
replace_entry 'word/document.xml', doc.serialize(save_with: 0)
replace_entry @document_path, doc.serialize(save_with: 0)
replace_entry 'word/styles.xml', styles_configuration.serialize(save_with: 0)
headers.each do |name, content|
replace_entry "word/#{name}.xml", content.serialize(save_with: 0)
Expand Down
12 changes: 12 additions & 0 deletions spec/integration/editing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@
end
end

# Word for the web names the main part word/document2.xml.
describe 'office365.docx' do
it 'persists edits to a main part not named document.xml' do
doc = Docx::Document.open(fixture_path('office365.docx'))

doc.paragraphs.first.text = 'edited'
doc.save(tmp_path('saved.docx'))

expect(Docx::Document.open(tmp_path('saved.docx')).paragraphs.first.text).to eq('edited')
end
end

describe 'multi_doc_bookmarks.docx' do
it 'edits bookmarks in headers and footers and persists them' do
doc = Docx::Document.open(fixture_path('multi_doc_bookmarks.docx'))
Expand Down
Loading