ob_start();
echo 'Désçàui';
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=Test.xls");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
ob_end_flush();
What I'm getting in the excel file is Désçà ui
However, I do get Désçàui when I try
ob_start();
echo 'Désçàui';
header("Content-Type: text/html; charset=utf-8");
ob_end_flush();
Any help experts?
PS. The file is saved in DW with Title/Encoding Unicode(Utf-8).
Source http://www.mwasif.com/2007/5/download-data-csv-using-php/
Danish Zahur said,
October 7, 2009 @ 7:23 pm
If your contents are in UTF-8 format, then no need to convert encoding. Just start your file/output stream with UTF-8 BOM after headers.
echo pack("CCC",0xef,0xbb,0xbf);
And header should contain encoding UTF-8
header( "Content-type: application/vnd.ms-excel; charset=UTF-8" );
It will work like charm because Excel will recognize file charset with BOM bytes.
I'm not sure, but it may be that excel can not handle utf8(may depend on the version). But it can handle utf16, so try converting the charset. This works for me(in excel2002):
echo mb_convert_encoding('Désçàui','utf-16','utf-8');
I don't know how you're generating the excel file. But, if you're doing it from an HTML output, you can just add the following at the begining:
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
Regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With