Quantcast
Viewing all articles
Browse latest Browse all 35

Answer by Basj for Is it possible to force Excel recognize UTF-8 CSV files automatically?

15 years later, I finally found the solution: write CSV in UTF-16-LE without BOM, and it will work on Excel 2007+.

Example with Python:

import csvwith open('test.csv', "w", encoding="utf-16-le", newline='') as csvfile:    w = csv.writer(csvfile, delimiter=';')    w.writerow(["abc", "def"])    w.writerow(["été", "hiver"])

The output CSV file can be opened directly with Excel, and:

  • (1) no problems with the accents
  • (2) the delimiters will be automatically parsed into multiple columns

Note: if using encoding="utf-16" instead of utf-16-le, (1) will still be ok, but not (2).


Viewing all articles
Browse latest Browse all 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>