Skip to content

Commit 2050fe2

Browse files
committed
Supports for Office 365 files
Reference #83
1 parent 9d6b022 commit 2050fe2

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

docx.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ Gem::Specification.new do |s|
1919
s.add_development_dependency 'rspec', '~> 3.7'
2020
s.add_development_dependency 'rake', '~> 13.0'
2121
end
22-

lib/docx/document.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ def initialize(path_or_io, options = {})
3030
@zip = Zip::File.open_buffer(path_or_io)
3131
end
3232

33-
@document_xml = @zip.read('word/document.xml')
33+
document = @zip.find_entry('word/document.xml')
34+
document = @zip.find_entry('word/document2.xml') if document.nil?
35+
raise Errno::ENOENT if document.nil?
36+
37+
@document_xml = document.get_input_stream.read
3438
@doc = Nokogiri::XML(@document_xml)
3539
load_styles
36-
if block_given?
37-
yield self
38-
@zip.close
39-
end
40+
return unless block_given?
41+
42+
yield self
43+
@zip.close
4044
end
4145

4246
# This stores the current global document properties, for now

spec/docx/document_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@
7474
end
7575
end
7676

77+
describe '#open' do
78+
context 'When reading a file made by Office365' do
79+
it 'supports it' do
80+
expect do
81+
Docx::Document.open(@fixtures_path + '/office365.docx')
82+
end.to_not raise_error
83+
end
84+
end
85+
end
86+
7787
describe 'reading' do
7888
context 'using normal file' do
7989
before do

spec/fixtures/office365.docx

10.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)