[Tutor] Saving Excel file as HTML

Rich Krauter rmkrauter at yahoo.com
Sat Feb 14 10:09:04 EST 2004


On Sat, 2004-02-14 at 06:59, Shitiz Bansal wrote:
> hi,
> I have been using python to Automate Excel using the Dispatch method
> in win32com module.
> I have written a script to create and write an excel doc.
> I want to save this document in HTML format.
>  
> I used the visual basic editor in excel macros to find out the desired
> syntax.
> but unfortunately i am getting an error.
> Can anybody help.
> Also i would like to know if i can somehow set the width of individual
> columns in excel .Microsoft help  didnt help much.
>  
> here is a part of my script:
>  
> x=listdir('C:\\teams/'+j+'/teams')
>     xlApp.Workbooks.Add()
>     xlBook = xlApp.Workbooks(1)
>     xlSheet = xlApp.Sheets(1)
>     xlSheet.Cells(1,1).Value = 'TeamName'
>     xlSheet.Cells(1,2).Value = 'Institute'
>     xlSheet.Cells(1,3).Value = 'Team Members'
> ......
>   

This is what I tried:

I manually created a worksheet in excel, and recorded the macro as I
proceeded to save the document as html. Then I looked at the macro to
see what excel was actually doing.

I translated the VB to python to do the 'saveas' operation:

xlBook.PublishObjects.Add(1,'C:/test.html',"Sheet1").Publish(True)

To adjust column width, I did the same thing - record the macro, look at
the resulting VB, and translate it to python:

xlSheet.Columns('C:C').ColumnWidth = 50

Hope that helps.

Rich



More information about the Tutor mailing list