5

I have headers:

            header('Content-Type: text/html; charset=UTF-8');
            header("Content-type: application/octetstream");
            header('Content-Disposition: attachment; filename="export.csv"');

but decoding not work correct if I have word in database "Pagrindinė" in excel show "PagrindinÄ", what is wrong with my headers ?

user2287965
  • 203
  • 2
  • 6
  • 14
  • 1
    So you're outputting a CSV? Or an Excel file created with PHPExcel? What is it? – deceze Apr 30 '13 at 13:43
  • 1
    Duplicate of: [Microsoft Excel mangles Diacritics in .csv files?](http://stackoverflow.com/questions/155097/microsoft-excel-mangles-diacritics-in-csv-files) – M8R-1jmw5r Apr 30 '13 at 13:44
  • Are you actually using the PHPExcel library to create your csv file? – Mark Baker May 01 '13 at 06:28

3 Answers3

3

What is wrong with my headers ?

Nothing, your headers are looking fine.

What is wrong with Excel?

The user who opens the file in Excel needs to tell Excel that the file is in UTF-8 encoding. Direct that user to contact the vendor of the software it uses for her/his support options.

Users of LibreOffice or a derivate of it do not have that problem btw., so one solution is to tell those to install a suite of such, open the CSV file and save it as Excel file for example.

Or you directly create the Excel file on your server.

M8R-1jmw5r
  • 4,896
  • 2
  • 18
  • 26
0

Maybe if you change the format text encoding of your .php file when you save it, to Unicode (UTF-8). It works for me.

Hope it helps.

PedroSaiz
  • 143
  • 2
  • 2
0

try this:

 header('Content-Transfer-Encoding: binary');
header("Content-Type: application/octet-stream"); 
header("Content-Transfer-Encoding: binary"); 
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 
header('Content-Disposition: attachment; filename = "Export '.date("Y-m-d").'.xls"'); 
header('Pragma: no-cache'); 

//these characters will make correct encoding to excel 
echo chr(255).chr(254).iconv("UTF-8", "UTF-16LE//IGNORE", $out);