diff options
| author | Joe Kain <[email protected]> | 2012-03-31 22:04:41 -0700 |
|---|---|---|
| committer | Joe Kain <[email protected]> | 2012-04-01 00:05:41 -0700 |
| commit | 44c77ed27b20c4ebe1c9c8faf6ad80701d7f567e (patch) | |
| tree | 9a474295ec099e303b3711338962d84cb7a43596 /lib | |
| parent | bff4c5ecfa730c6f5af35577a5cb83562512866e (diff) | |
| download | caxlsx-44c77ed27b20c4ebe1c9c8faf6ad80701d7f567e.tar.gz caxlsx-44c77ed27b20c4ebe1c9c8faf6ad80701d7f567e.zip | |
Fixes for 3+ letter columns
In Axlsx::name_to_indices multiply by the base.
In Axlsx::col_ref move the -1 into the loop, it applies to all but
the first iteration.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb index dd628562..46d1c9bf 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -57,7 +57,7 @@ module Axlsx def self.name_to_indices(name) raise ArgumentError, 'invalid cell name' unless name.size > 1 v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |val, c| - val[:i] += ((c.bytes.first - 65) + val[:base]); val[:base] *= 26; val + val[:i] += ((c.bytes.first - 64) * val[:base]); val[:base] *= 26; val end [v[:i]-1, ((name[/[1-9][0-9]*/]).to_i)-1] @@ -71,9 +71,9 @@ module Axlsx chars = [] while index >= 26 do chars << ((index % 26) + 65).chr - index /= 26 + index = index / 26 - 1 end - chars << ((chars.empty? ? index : index-1) + 65).chr + chars << (index + 65).chr chars.reverse.join end |
