Skip to content Skip to sidebar Skip to footer

Excel Fails To Open Python-generated Csv Files

I have many Python scripts that output CSV files. It is occasionally convenient to open these files in Excel. After installing OS X Mavericks, Excel no longer opens these files pro

Solution 1:

Maybe I had the similar problem, the error message "SYLK: File format is not valid" when open python autogenerated csv file. The solution is really funny. The first two characters must not be I and D in uppercase (ID). Also see "SYLK: File format is not valid" error message when you open file.

Solution 2:

Possible solution1: use *.txt instead of *.csv. In this case Excel (at least, 2010) will show you an import data wizard where you can specify delimiters, character encoding, field types, etc.

UPD: Solution2: The python "csv" module has a "dialect" feature. For example, the following modification of your code generates valid csv file for my environment (Python 2.7, Excel 2010, Windows7, locale with ";" list delimiters):

import csv
withopen('csv_test2.csv', 'wb') as f:
    csv.excel.delimiter=';'
    writer = csv.writer(f, dialect=csv.excel)
    writer.writerow([1,2,3])
    writer.writerow([4,5,6])

Post a Comment for "Excel Fails To Open Python-generated Csv Files"