Last active
August 29, 2015 14:10
-
-
Save jpterry/11ecda31ee57563375a0 to your computer and use it in GitHub Desktop.
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
# Excel column string to 0 indexed position | |
def self.excel_col_to_index(str) | |
offset = 'A'.ord - 1 | |
str.upcase.chars.inject(0) { |x,c| x * 26 + c.ord - offset } - 1 | |
end | |
# 0 based index to column letter | |
def self.index_to_excel_col(index) | |
'A'.tap do |name| | |
index.times { name.succ! } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment