Fwd: [python-win32] Fwd: Autosizing column widths in Excel using win32com.client ?

James Matthews nytrokiss at gmail.com
Sun May 17 08:03:27 EDT 2009


---------- Forwarded message ----------
From: Tim Golden <mail at timgolden.me.uk>
Date: Sun, May 17, 2009 at 1:00 PM
Subject: Re: [python-win32] Fwd: Autosizing column widths in Excel using
win32com.client ?
To:
Cc: Python-Win32 List <python-win32 at python.org>


James Matthews wrote:

> ---------- Forwarded message ----------
> From: <nonsense at mynonsense.net>
> Date: Fri, May 15, 2009 at 7:45 PM
> Subject: Autosizing column widths in Excel using win32com.client ?
> To: python-list at python.org
>
>
> Is there a way to autosize the widths of the excel columns as when you
> double click them manually?
>

Usual answer to this kind of question: record a macro
in Excel to do what you want, and then use COM to
automate that. On my Excel 2007, this is the VBA result
of recording:

<vba>
Sub Macro2()
'
' Macro2 Macro
'
'
  Columns("A:A").Select
  Range(Selection, Selection.End(xlToRight)).Select
  Columns("A:D").EntireColumn.AutoFit
End Sub
</vba>


You then just fire up win32com.client or comtypes,
according to taste and go from there. If you need
help with the COM side of things, post back here.

TJG
_______________________________________________
python-win32 mailing list
python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32



-- 
http://www.goldwatches.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090517/bcddf327/attachment.html>


More information about the Python-list mailing list