Convert spreadsheet number to column letter
start_index = 1 # it can start either at 0 or at 1
letter = ''
while column_int > 25 + start_index:
letter += chr(65 + int((column_int-start_index)/26) - 1)
column_int = column_int - (int((column_int-start_index)/26))*26
letter += chr(65 - start_index + (int(column_int)))
The xlsxwriter library includes a conversion function, xlsxwriter.utility.xl_col_to_name(index)
and is on github
here is a working example:
>>> import xlsxwriter
>>> xlsxwriter.utility.xl_col_to_name(10)
'K'
>>> xlsxwriter.utility.xl_col_to_name(1)
'B'
>>> xlsxwriter.utility.xl_col_to_name(0)
'A'
Notice that it's using zero-indexing.
The openpyxl library includes the conversion function (amongst others) which you are looking for, get_column_letter
:
>>> from openpyxl.utils.cell import get_column_letter
>>> get_column_letter(1)
'A'
>>> get_column_letter(10)
'J'
>>> get_column_letter(3423)
'EAQ'