saving a excel sheet as a csv file

Joost van Rooij j.vanrooij_at_e-quest.nl
Tue Jun 10 06:38:13 EDT 2003


Hello,

I would like to save an Excel file to a csv file, which works nicely using
com, but I can't seem to find out how to be able to select a particular
sheet.

This code converts all right, but the selecting the right sheet won't
work...

from win32com.client import Dispatch

def xl2csv(source, destination, sheet):
    xl = Dispatch("Excel.Application")
    xl.Workbooks.Open(source)
    xl.Sheets.Select(sheet)
    xl.ActiveWorkbook.SaveAs(destination,FileFormat= "6")
    xl.Workbooks(1).Close(0)
    return

xl2csv("d:\\file.xls", "d:\\file.csv", "Sheet2")

Any help would be very much appreciated....

grtz Joost






More information about the Python-list mailing list