3

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?

4 Answers 4

4

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)
Sign up to request clarification or add additional context in comments.

1 Comment

I thought the value for xlCSV is 6.
4

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)

2 Comments

If the file already exists, then Excel will show a pop-up window. Is there a way to deal with this, or direct the function to always overwrite?
You can set xl.DisplayAlerts = False beforehand and Excel will just overwrite the file.
3

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.

Comments

1

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

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

1 Comment

I need to load a plugin, so a regular xlsx parsing library is no-go. win32com does what I need, the problem is the SaveAs method docstring is unclear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.