What's are the simplest way to convert excel-like column letter to integer?
for example:
AB --> 27
AA --> 26
A --> 0
Z --> 25
def excel_col_index( str )
value = Hash[ ('A'..'Z').map.with_index.to_a ]
str.chars.inject(0){ |x,c| x*26 + value[c] + 1 } - 1
end
Or
def excel_col_index( str )
offset = 'A'.ord - 1
str.chars.inject(0){ |x,c| x*26 + c.ord - offset } - 1
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With