Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python xlwt - Convert column integer into excel cell references. Eg (3,6) to C6

Tags:

python

excel

xlwt

I'm automating formula's using pythons XLWT library. I have column indexs, eg, 1,2,3,99, etc and would like to convert to A,B,C,D, AA,AB, etc.

Is there anything built into xlwt for this? Or should I just write my own function?

like image 627
Humphrey Avatar asked Mar 22 '23 00:03

Humphrey


1 Answers

You can use xlrds helper function:

import xlrd
print xlrd.colname(56)
# BE

Strangely - there doesn't appear to be a direct equivalent in xlwt or xlwt.Utils (although this does have various helper functions for conversion of cells and names)

Going by the question's title - you can use:

>>> xlwt.Utils.rowcol_to_cell(5, 2)
'C6'
like image 174
Jon Clements Avatar answered Apr 10 '23 08:04

Jon Clements