Skip to content

Instantly share code, notes, and snippets.

@libkazz
Last active August 3, 2019 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save libkazz/9650817a454126f4e9bb0a725dac0b16 to your computer and use it in GitHub Desktop.
Save libkazz/9650817a454126f4e9bb0a725dac0b16 to your computer and use it in GitHub Desktop.
RubyでExcel列文字列を列番号に変換する方法
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