Last active
May 23, 2016 11:57
-
-
Save akszydelko/ab370605206f23d6d3d0f1024ce2d0e2 to your computer and use it in GitHub Desktop.
Export csv that opens in Excl without formatting problems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codecs | |
import csv | |
with open('data.csv', 'wb') as f: | |
# Write BOM to the file, it is required | |
# Excl without BOM does not understend UTF-8 charcters... (Non ascii characters) | |
f.write(codecs.BOM_UTF8) | |
# Set excl dialect | |
# Delimiter ; is required so columns are detected properly | |
writer = csv.writer(f, dialect=csv.excel, delimiter=';') # Option 1 | |
dict_writer = csv.DictWriter(f, dialect=csv.excel, delimiter=';', fieldnames=['a', 'b', 'c']) # Option 2 | |
# Continiue normally |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment