Hello,

I need a generator to create the cellname in a excell (using pyuno) document to assign value to the correct cell. The following code does this but do you have some optimizations
on it, for instance to get the alphabetic chars instead of hard-coding it.

Cheers
karim

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def _xrange_cellnames(rows, cols):
...     """Internal iterator function to compute excell table cellnames."""
...     cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
...     for row in xrange(1, rows+1):
...         for char in cellnames.replace('', ' ').split()[:cols]:
...             yield char + str(row)
...
>>> list( _xrange_cellnames(rows=3,cols=4))
['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3']


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to