Skip to content

Commit

Permalink
Merge 7b46158 into 907c178
Browse files Browse the repository at this point in the history
  • Loading branch information
ResumeNothing committed Jan 10, 2019
2 parents 907c178 + 7b46158 commit 020af4e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/roo/excelx/sheet_doc.rb
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions spec/lib/roo/excelx_spec.rb
Expand Up @@ -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

Expand Down
Binary file added test/files/link_with_location.xlsx
Binary file not shown.

0 comments on commit 020af4e

Please sign in to comment.