<div dir="ltr"><br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Tim Golden</b> <span dir="ltr"><<a href="mailto:mail@timgolden.me.uk">mail@timgolden.me.uk</a>></span><br>
Date: Sun, May 17, 2009 at 1:00 PM<br>Subject: Re: [python-win32] Fwd: Autosizing column widths in Excel using win32com.client ?<br>To: <br>Cc: Python-Win32 List <<a href="mailto:python-win32@python.org">python-win32@python.org</a>><br>
<br><br><div class="im">James Matthews wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
---------- Forwarded message ----------<br>
From: <<a href="mailto:nonsense@mynonsense.net" target="_blank">nonsense@mynonsense.net</a>><br>
Date: Fri, May 15, 2009 at 7:45 PM<br>
Subject: Autosizing column widths in Excel using win32com.client ?<br>
To: <a href="mailto:python-list@python.org" target="_blank">python-list@python.org</a><br>
<br>
<br>
Is there a way to autosize the widths of the excel columns as when you<br>
double click them manually?<br>
</blockquote>
<br></div>
Usual answer to this kind of question: record a macro<br>
in Excel to do what you want, and then use COM to<br>
automate that. On my Excel 2007, this is the VBA result<br>
of recording:<br>
<br>
<vba><br>
Sub Macro2()<br>
'<br>
' Macro2 Macro<br>
'<br>
'<br>
Columns("A:A").Select<br>
Range(Selection, Selection.End(xlToRight)).Select<br>
Columns("A:D").EntireColumn.AutoFit<br>
End Sub<br>
</vba><br>
<br>
<br>
You then just fire up win32com.client or comtypes,<br>
according to taste and go from there. If you need<br>
help with the COM side of things, post back here.<br>
<br>
TJG<br>
_______________________________________________<br>
python-win32 mailing list<br>
<a href="mailto:python-win32@python.org" target="_blank">python-win32@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>
</div><br><br clear="all"><br>-- <br><a href="http://www.goldwatches.com">http://www.goldwatches.com</a><br><br><br><br>
</div>