From 362863fc352b0bba24c31693f63a434fb2cdbb7c Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Mon, 5 Dec 2011 09:09:14 +0900 Subject: 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] --- lib/axlsx.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 -- cgit v1.2.3