Python Win32,如何将XLS保存为CSV?

[英]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.

我正在使用win32com加载.xlsx,并希望在完成后将结果保存为csv。

myworkbook.SaveAs('results.csv')

gives me an xlsx file with a csv extension. How do I save as an actual CSV?

给我一个带有csv扩展名的xlsx文件。如何保存为实际的CSV?

4 个解决方案

#1


3  

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.

我认为CSV(DOS)的类型是24。

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

#2


2  

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

以下是saveAs的文档:http://msdn.microsoft.com/en-us/library/bb214129.aspx

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

#3


2  

You have to specify the type after the filename.

您必须在文件名后指定类型。

For CSV the following modes are available:

对于CSV,可以使用以下模式:

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.

这里可用的文件格式很流行,可以在这里找到saveAs方法的规范。即使没有python的例子,参数和值也应该相同。

#4


1  

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

我没有使用过这个库但可能值得一试:

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

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


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2011/05/31/d4bc06eaf3d71e999723457331a0432b.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号