diff --git a/lib/roo/excelx/sheet_doc.rb b/lib/roo/excelx/sheet_doc.rb index 52bab45e..0e7f2662 100755 --- a/lib/roo/excelx/sheet_doc.rb +++ b/lib/roo/excelx/sheet_doc.rb @@ -179,8 +179,10 @@ def extract_hyperlinks(relationships) return {} unless (hyperlinks = doc.xpath('/worksheet/hyperlinks/hyperlink')) Hash[hyperlinks.map do |hyperlink| - if hyperlink.attribute('id') && (relationship = relationships[hyperlink.attribute('id').text]) - [::Roo::Utils.ref_to_key(hyperlink.attributes["ref"].to_s), relationship.attribute('Target').text] + if hyperlink['id'] && (relationship = relationships[hyperlink['id']]) + target_link = relationship['Target'] + target_link += "##{hyperlink['location']}" if hyperlink['location'] + [::Roo::Utils.ref_to_key(hyperlink['ref']), target_link] end end.compact] end diff --git a/spec/lib/roo/excelx_spec.rb b/spec/lib/roo/excelx_spec.rb index cbbceb79..6c2289f0 100755 --- a/spec/lib/roo/excelx_spec.rb +++ b/spec/lib/roo/excelx_spec.rb @@ -382,11 +382,22 @@ end describe '#hyperlink' do - let(:path) { 'test/files/link.xlsx' } + context 'without location' do + let(:path) { 'test/files/link.xlsx' } - it 'returns the expected result' do - expect(subject.hyperlink(1, 1)).to eq "http://www.google.com" - expect(subject.hyperlink(1, 2)).to eq nil + it 'returns the expected result' do + expect(subject.hyperlink(1, 1)).to eq "http://www.google.com" + expect(subject.hyperlink(1, 2)).to eq nil + end + end + + context 'with location' do + let(:path) { 'test/files/link_with_location.xlsx' } + + it 'returns the expected result' do + expect(subject.hyperlink(1, 1)).to eq "http://www.google.com/#hey" + expect(subject.hyperlink(1, 2)).to eq nil + end end end diff --git a/test/files/link_with_location.xlsx b/test/files/link_with_location.xlsx new file mode 100644 index 00000000..393f5aca Binary files /dev/null and b/test/files/link_with_location.xlsx differ