python win32com excel problem

Bart Willems b.r.willems at gmail.com
Tue May 1 20:14:55 EDT 2007


Ray wrote:
> Hi,
> I tried to call "xlApp.Columns.AutoFit=1" the whole program will crash,
> but without xlApp.Columns.AutoFit=1, everything just fine.

Autofit is a method. Also, columns are a method of a worksheet - try:
xlApp.Worksheets.Columns("C:K").Autofit()
(or whatever columns you need of course)

> 2. How do I set a rows format? I need to set row "F" to "Text", "o","p" 
> to general, and
> "Q", "R", to currency.

Same story: you will need to define the range first.
xlApp.Worksheets.Rows("10:200").Numberformat = "General"
I think that you actually mean columns, and not rows - columns have 
character designators, rows have numbers. In that case, try something 
like xlApp.Activesheet.Columns("F") = "@" (text format), or the other 
appropiate codes for number formatting as required. I usually pick 
"#,##0.00" to display numbers with two decimals and thousands seperators.

Cheers,
Bart



More information about the Python-list mailing list