开发者

Python Win32, how to save an XLS as a CSV?

I'm loading up a .xlsx with win32com and would like to save the results as a csv when I'm done.

myworkbook.SaveAs('results.csv')

gives me an xlsx file开发者_如何学运维 with a csv extension. How do I save as an actual CSV?


I think that if you add the type after the filename, it should work. (Can't test right now.)

I think the type for CSV (DOS) is 24.

myworkbook.SaveAs('results.csv', 24)


Here are the docs for saveAs: http://msdn.microsoft.com/en-us/library/bb214129.aspx

from win32com.client import constants as c
myWorkBook.SaveAs('results.csv', c.xlCSV)


You have to specify the type after the filename.

For CSV the following modes are available:

xlCSV = 6         # Comma separated value.
xlCSVMac = 22,    # Comma separated value.
xlCSVMSDOS = 24,  # Comma separated value.
xlCSVWindows =23, # Comma separated value.

Available file formats can be fond here, the spec of the saveAs method can be found here. Even as there is no example for python, the parameters and values should be the same.


I have not used this library but it might be worth giving a shot:

http://pypi.python.org/pypi/ooxml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜