I'm looking for the opposite to this Q&A: Convert an excel or spreadsheet column letter to its number in Pythonic fashion.
or this one but in python How to convert a column number (eg. 127) into an excel column (eg. AA)
def colnum_string(n): string = "" while n > 0: n, remainder = divmod(n - 1, 26) string = chr(65 + remainder) + string return string print(colnum_string(28)) #output:AB
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With