Last active
August 3, 2019 09:59
-
-
Save libkazz/9650817a454126f4e9bb0a725dac0b16 to your computer and use it in GitHub Desktop.
RubyでExcel列文字列を列番号に変換する方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def row_number(str) | |
str.bytes.reverse.each.with_index(0).reduce(0) do |n, (c, i)| | |
n += (26 ** i * (c.ord - 64)) | |
end | |
end | |
('A'..'BZ').each do |str| | |
p [str, row_number(str)] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment