Skip to content

Instantly share code, notes, and snippets.

@jpterry
Last active August 29, 2015 14:10
Show Gist options
  • Save jpterry/11ecda31ee57563375a0 to your computer and use it in GitHub Desktop.
Save jpterry/11ecda31ee57563375a0 to your computer and use it in GitHub Desktop.
# 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