diff options
Diffstat (limited to 'lib/roo')
| -rw-r--r-- | lib/roo/excelx/relationships.rb | 10 | ||||
| -rwxr-xr-x | lib/roo/excelx/sheet_doc.rb | 7 | ||||
| -rw-r--r-- | lib/roo/utils.rb | 23 | ||||
| -rw-r--r-- | lib/roo/version.rb | 2 |
4 files changed, 37 insertions, 5 deletions
diff --git a/lib/roo/excelx/relationships.rb b/lib/roo/excelx/relationships.rb index 19f9919..754775d 100644 --- a/lib/roo/excelx/relationships.rb +++ b/lib/roo/excelx/relationships.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'roo/excelx/extractor' module Roo @@ -11,10 +13,16 @@ module Roo @relationships ||= extract_relationships end + def include_type?(type) + to_a.any? do |_, rel| + rel["Type"]&.include? type + end + end + private def extract_relationships - return [] unless doc_exists? + return {} unless doc_exists? doc.xpath('/Relationships/Relationship').each_with_object({}) do |rel, hash| hash[rel['Id']] = rel diff --git a/lib/roo/excelx/sheet_doc.rb b/lib/roo/excelx/sheet_doc.rb index 2b3aa39..6da4c26 100755 --- a/lib/roo/excelx/sheet_doc.rb +++ b/lib/roo/excelx/sheet_doc.rb @@ -22,7 +22,7 @@ module Roo def hyperlinks(relationships) # If you're sure you're not going to need this hyperlinks you can discard it - @hyperlinks ||= if @options[:no_hyperlinks] + @hyperlinks ||= if @options[:no_hyperlinks] || !relationships.include_type?("hyperlink") {} else extract_hyperlinks(relationships) @@ -185,7 +185,10 @@ module Roo if relationship = relationships[hyperlink['id']] target_link = relationship['Target'] target_link += "##{hyperlink['location']}" if hyperlink['location'] - hash[::Roo::Utils.ref_to_key(hyperlink["ref"].to_s)] = target_link + + Roo::Utils.coordinates_in_range(hyperlink["ref"].to_s) do |coord| + hash[coord] = target_link + end end end end diff --git a/lib/roo/utils.rb b/lib/roo/utils.rb index dcaedde..2d6754a 100644 --- a/lib/roo/utils.rb +++ b/lib/roo/utils.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Roo module Utils extend self @@ -41,7 +43,7 @@ module Roo # convert a number to something like 'AB' (1 => 'A', 2 => 'B', ...) def number_to_letter(num) - result = "" + result = +"" until num.zero? num, index = (num - 1).divmod(26) @@ -73,6 +75,25 @@ module Roo (x2 - (x1 - 1)) * (y2 - (y1 - 1)) end + def coordinates_in_range(str) + return to_enum(:coordinates_in_range, str) unless block_given? + coordinates = str.split(":", 2).map! { |s| extract_coordinate s } + + case coordinates.size + when 1 + yield coordinates[0] + when 2 + tl, br = coordinates + rows = tl.row..br.row + cols = tl.column..br.column + rows.each do |row| + cols.each do |column| + yield Excelx::Coordinate.new(row, column) + end + end + end + end + def load_xml(path) ::File.open(path, 'rb') do |file| ::Nokogiri::XML(file) diff --git a/lib/roo/version.rb b/lib/roo/version.rb index 625e495..1f2140b 100644 --- a/lib/roo/version.rb +++ b/lib/roo/version.rb @@ -1,3 +1,3 @@ module Roo - VERSION = "2.8.1" + VERSION = "2.8.2" end |
