diff options
| author | Weston Ganger <[email protected]> | 2021-12-29 12:00:26 -0800 |
|---|---|---|
| committer | Weston Ganger <[email protected]> | 2021-12-29 13:11:55 -0800 |
| commit | 6bc6e6303ac27ac11571760c036c244b1448aeaa (patch) | |
| tree | b0aa4f90802b49f5fcb6eb7dc53931b9364889f1 /lib/axlsx.rb | |
| parent | 7aa995d58f072d2b49166d43ef44232a5086042a (diff) | |
| download | caxlsx-6bc6e6303ac27ac11571760c036c244b1448aeaa.tar.gz caxlsx-6bc6e6303ac27ac11571760c036c244b1448aeaa.zip | |
Fix Worksheet#name_to_cell bug which returned reversed row/col indexes
Diffstat (limited to 'lib/axlsx.rb')
| -rw-r--r-- | lib/axlsx.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb index 0c8c3850..4e804513 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -79,11 +79,25 @@ module Axlsx # returns the x, y position of a cell def self.name_to_indices(name) raise ArgumentError, 'invalid cell name' unless name.size > 1 + + letters_str = name[/[A-Z]+/] + # capitalization?!? - v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |val, c| - val[:i] += ((c.bytes.first - 64) * val[:base]); val[:base] *= 26; val + v = letters_str.reverse.chars.reduce({:base=>1, :i=>0}) do |val, c| + val[:i] += ((c.bytes.first - 64) * val[:base]) + + val[:base] *= 26 + + next val end - [v[:i]-1, ((name[/[1-9][0-9]*/]).to_i)-1] + + col_index = (v[:i] - 1) + + numbers_str = name[/[1-9][0-9]*/] + + row_index = (numbers_str.to_i - 1) + + return [col_index, row_index] end # converts the column index into alphabetical values. |
