I’d rather call it “an example for why developers do not like Microsoft”, actually..
After 3 days of struggling, I have now non-English csv file, which opens correctly in MS Office. No, standards are not important here; creating a valid file won’t help. It will open in Open and Libre Office, and probably even in notepad and wordpad. But not in MS Excel, which is used by all those people we create reports for..
Keeping the long story short, this is the code that worked:
header ( 'HTTP/1.1 200 OK' );
header ( 'Date: ' . date ( 'D M j G:i:s T Y' ) );
header ( 'Last-Modified: ' . date ( 'D M j G:i:s T Y' ) );
header ( 'Content-Type: application/vnd.ms-excel') ;
header ( 'Content-Disposition: attachment;filename=report.csv' );
print chr(255) . chr(254) . mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8');
It is about 50th sample of code I tried. I’ve encoded it as ISO, and as Windows-1252 (yes, it’s hebrew), and what not…
Hope it would help someone.