- import os
- import win32com.client
- filename = 'myfile.xls'
- filepath = os.path.abspath(filename) # Always make sure you use an absolute path !
- # Start Excel and open the XLS file:
- excel = win32com.client.Dispatch('Excel.Application')
- excel.Visible = True
- workbook = excel.Workbooks.Open(filepath)
- # Save as CSV:
- xlCSVWindows =0x17 # from enum XlFileFormat
- workbook.SaveAs(Filename=filepath+".csv",FileFormat=xlCSVWindows)
- # Close workbook and Excel
- workbook.Close(SaveChanges=False)
- excel.Quit()
- #该片段来自于http://www.codesnippet.cn/detail/110120131521.html
来源: http://www.codesnippet.cn/detail/110120131521.html