Skip to content

Commit

Permalink
Accept either Transitional or Strict Type url for worksheets. (roo-rb…
Browse files Browse the repository at this point in the history
…#441)

* Accept either Transitional or Strict Type url for worksheets.

* Add basic specs for Strict file handling.
  • Loading branch information
k3rni authored and tgturner committed Sep 17, 2018
1 parent 782420b commit 5ad99a9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/roo/excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,9 @@ def extract_worksheet_rels(entries, path)

wb_rels.extract(path)
rels_doc = Roo::Utils.load_xml(path).remove_namespaces!
worksheet_type = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet'

relationships = rels_doc.xpath('//Relationship').select do |relationship|
relationship.attributes['Type'].value == worksheet_type
worksheet_types.include? relationship.attributes['Type'].value
end

relationships.inject({}) do |hash, relationship|
Expand Down Expand Up @@ -466,5 +465,12 @@ def process_zipfile_entries(entries)
def safe_send(object, method, *args)
object.send(method, *args) if object && object.respond_to?(method)
end

def worksheet_types
[
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet', # OOXML Transitional
'http://purl.oclc.org/ooxml/officeDocument/relationships/worksheet' # OOXML Strict
]
end
end
end
43 changes: 43 additions & 0 deletions spec/lib/roo/strict_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'spec_helper'

describe Roo::Excelx do
subject { Roo::Excelx.new('test/files/strict.xlsx') }

example '#sheets' do
expect(subject.sheets).to eq %w(Sheet1 Sheet2)
end

example '#sheet' do
expect(subject.sheet('Sheet1')).to be_a(Roo::Excelx)
end

example '#cell' do
expect(subject.cell(1, 1)).to eq 'Sheet 1'
expect(subject.cell(1, 1, 'Sheet2')).to eq 'Sheet 2'
end

example '#row' do
expect(subject.row(1)).to eq ['Sheet 1']
expect(subject.row(1, 'Sheet2')).to eq ['Sheet 2']
end

example '#first_row' do
expect(subject.first_row).to eq 1
expect(subject.first_row('Sheet2')).to eq 1
end

example '#last_row' do
expect(subject.last_row).to eq 1
expect(subject.last_row('Sheet2')).to eq 1
end

example '#first_column' do
expect(subject.first_column).to eq 1
expect(subject.first_column('Sheet2')).to eq 1
end

example '#last_column' do
expect(subject.last_column).to eq 1
expect(subject.last_column('Sheet2')).to eq 1
end
end
Binary file added test/files/strict.xlsx
Binary file not shown.

0 comments on commit 5ad99a9

Please sign in to comment.