Method: RubyXL::Parser.convert_to_index
- Defined in:
- lib/rubyXL/parser.rb
.convert_to_index(cell_string) ⇒ Object
converts cell string (such as “AA1”) to matrix indices
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubyXL/parser.rb', line 12 def Parser.convert_to_index(cell_string) index = Array.new(2) index[0]=-1 index[1]=-1 if(cell_string =~ /^([A-Z]+)(\d+)$/) one = $1.to_s row = Integer($2) - 1 #-1 for 0 indexing col = 0 i = 0 one = one.reverse #because of 26^i calculation one.each_byte do |c| int_val = c - 64 #converts A to 1 col += int_val * 26**(i) i=i+1 end col -= 1 #zer0 index index[0] = row index[1] = col end return index end |