0

I'm trying to encode some nested lists of data in python in order to save the file as a csv and have others be able to access and use the data in Excel.

My data is supplied in UTF8. As part of converting this into an Excel-friendly format, I typically decode from UTF8 and encode using cp1252 so that Excel can display the csv data correctly.

If the data is in Russian, I would use cp1251 instead, for the windows/excel-friendly Cyrillic character set.

However, I have issues with string which are a mixture of character sets.

If we take a string asdasdasd фоиииффииф, is it possible to encode this in a manner that will allow me to save a csv that can be opened in Excel? It's not a problem in UTF8 of course, but I can't use that for opening in Excel...

  • First of all, there is nothing preventing a CSV file from containing UTF-8 data. (If you are using Python 2, then you do have to work around some limitations with its `csv` module, but that is doable. And there is no trouble with Python 3.) Second, if the data will be opened in Excel, you can write directly to an Excel workbook. I strongly recommend XlsxWriter for this purpose. – John Y Aug 05 '16 at 22:08

1 Answers1

0

Solved by ignoring Windows codecs and instead keeping UTF8, and inserting a BOM. I believe my original question had no solution using Windows codecs.

Is it possible to force Excel recognize UTF-8 CSV files automatically?

Community
  • 1
  • 1