summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2011-12-05 09:09:14 +0900
committerRandy Morgan <[email protected]>2011-12-05 09:09:14 +0900
commit362863fc352b0bba24c31693f63a434fb2cdbb7c (patch)
tree9bf7e3d8add9820e91eb1ea32c0d1cf3080197b8 /lib
parent9a4ebb63653f3148e383873189df2f529b375972 (diff)
downloadcaxlsx-362863fc352b0bba24c31693f63a434fb2cdbb7c.tar.gz
caxlsx-362863fc352b0bba24c31693f63a434fb2cdbb7c.zip
adding class method to transform single cell names in to x, y coordinates. For example "A1" transliterates to [0, 0] while "C7" transliterates to [2, 6]
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb
index 18d4a127..7d0d9e05 100644
--- a/lib/axlsx.rb
+++ b/lib/axlsx.rb
@@ -41,4 +41,14 @@ module Axlsx
ref += ":#{items.last.r_abs}" if items.size > 1
ref
end
+
+ 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 |v, c|
+ v[:i] += ((c.bytes.first - 65) + v[:base]); v[:base] *= 26; v
+ end
+
+ [v[:i]-1, ((name[/[1-9]+/]).to_i)-1]
+
+ end
end