From 7b4615839c770bbb7aa079905a992df55a7aee10 Mon Sep 17 00:00:00 2001 From: Jeremy Aube Date: Wed, 9 Jan 2019 13:12:49 -0500 Subject: [PATCH] Fixes issue with missing location for links. --- lib/roo/excelx/sheet_doc.rb | 6 ++++-- spec/lib/roo/excelx_spec.rb | 19 +++++++++++++++---- test/files/link_with_location.xlsx | Bin 0 -> 8943 bytes 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 test/files/link_with_location.xlsx 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 0000000000000000000000000000000000000000..393f5aca4d9511ab933af4b00977d19c638a7e99 GIT binary patch literal 8943 zcmeHt1y@|z(stwS?vmivKyV8XJh&4eI0PCRcPBxE(-1TS3&Gvp3BiLya0njU;q8pv z%rNtu&7BO`-EBeCS@5uonE+Vm{r?;P#V1gdps3Ud#C~%wJ5O^&NN1-@ z{W`_DeHfQn71L-%&UB)jZMdqc)^eo=`NLS?Y$RK6#(7IqxiD#|U@99;)?o>LrwKKe zef3n&p!^}P&u6eya88=mq!42_smj~JfrwFO3IKPBt4??#=s**dAdsh;mL8(; z(XVdpMMxmaI0;Cxjim?Mu~f44xUs!v|4nw7v?Q-;Y=&kpv7`BVNc6GW!DhE{tVlx3 ztLGTAQxQ>kjKF6qq%Q#5pxBKp^`5=D^Gm10$5;O3rmyeub{)41kJ}`$``fhDkSOXA z81A`F6elz9zc(uiNd<8!c5?TAbK^##l1~>11@nP=#&P1NaU^r95rog_6ta5LUJ!`4 zs;#*#?E)67-N?C`873H@CUt)g2T=JNE~_a z2H{_}UKFRO+zCVvK9Ic$={uiTh{2Xna1)npq|xy8mz&3`j?8{cw$REzj;%o&1SjLy z?0fThZb3M5yN~8<v(BxZWYL}`bj(_s5w z5v-bL zkE48qDwEUPM^(Qo}S7$8s@EaYljw@V(tDTp8wSD1HUv9x+cl5m)@>~#q z_Vzw9&Q{ls@G|fDXJL+8Ma{&=Z#!~O`{UMpD;DrQV&8f8^A{t$wj1^!oko``trs1= zTxs_eJlsg`P>)@bsvgASdu+BW9noYT?}%472k2GRSPFc65hB;!G`h$yRInNTE|=SH zQ}R*NQ?cOb=p=%9s^V24uru2F<8r_1+wO}G2sQ2`NJd{z_9K`qgF`(KpBc$oeD4=~ z$^Ipm#Je_d0F&rF-R5n_Pz{dJD@)5Vnfr+nA1sGfc->{d}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