diff options
| author | 2019-02-01 19:22:38 -0500 | |
|---|---|---|
| committer | 2019-02-01 19:22:38 -0500 | |
| commit | 46eadd2724cd841328d90c3143a485fcdf423ed6 (patch) | |
| tree | eb23c011f1c80a4cce169d9d9523a28927770b12 /lib/roo/utils.rb | |
| parent | 16dd018ca735392c2fb28b986316a9b22a06ccf9 (diff) | |
New upstream version 2.8.2upstream/2.8.2
Diffstat (limited to 'lib/roo/utils.rb')
| -rw-r--r-- | lib/roo/utils.rb | 23 |
1 files changed, 22 insertions, 1 deletions
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) |
