Excel and UTF-8 CSV export

November 23rd, 2012 by Alex Leave a reply »

So you probably exported your lovely database, perfectly stored in UTF-8 encoding, and then you open the csv in Excel, and see a bunch of crazy-looking characters where ä, Õ and é should be?

Well, here’s a fix: add a Byte-Order-Mark to your file. Excel just needs it desperately..

header('Content-Type: application/force-download');
header('Content-Description: File Transfer'); 
header('Content-disposition: attachment; filename="export.csv"');
 
echo chr(0xEF).chr(0xBB).chr(0xBF);
 
echo $mycsvoutput;

Comments are closed.