Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
excel-style label conversion
"""MIT license"""
import xlrd
import re
def col2index(name):
name = name.upper()
col = -1
for i, letter in enumerate(name[::-1]):
col += (ord(letter) - ord('A') + 1) * 26**i
return col
def row2index(name):
return int(name) - 1
def cell2index(name):
colname, rowname, _ = re.split(r'(\d+)', name)
return row2index(rowname), col2index(colname)
for i in range(1000):
assert i == col2index(xlrd.colname(i))
print cell2index('AB1243')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.