Win32 and Excel ranges
Emile van Sebille
emile at fenx.com
Sat Oct 12 03:29:22 EDT 2002
"L Whitley" asks
> I've found examples of how to read data from Excel using range, but
> haven't found an example of how to write data to Excel using range.
Can
> anyone help?
This is snipped from a script I wrote a couple of years ago. Perhaps it
helps.
def setCell(row,col):
cellref = ""
colref = col
if int((col-1)/26):
cellref = chr(ord("A")-1+int((col-1)/26))
colref = colref - int((col-1)/26)*26
cellref = "%s%s%d" % (cellref, chr(ord("A")-1+colref),row)
return cellref
def SaveSrce(source,worksheet):
ws,r = GetWorksheet(worksheet)
ws.Activate()
for row in source:
cols = len(row)
range = "R"+`r`+"C1:R"+`r`+"C"+`cols`
cell1 = setCell(r,1)
cell2 = setCell(r,cols)
xl.Range(cell1+":"+cell2).Value = row
r = r + 1
--
Emile van Sebille
emile at fenx.com
---------
More information about the Python-list
mailing list