Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue with missing location for links. #482

Merged
merged 1 commit into from
Jan 10, 2019
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
6 changes: 4 additions & 2 deletions lib/roo/excelx/sheet_doc.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.