0

Possible Duplicate:
How can I output a UTF-8 CSV in PHP that Excel will read properly?

I need to export from html table to excel file, but I'm having troubles with characters when I read de xml file..

Something like this:

Región should be like Región
Teléfono should be like Teléfono

This is my header definition:

header('Content-encoding: UTF-8');
header("Content-type: application/x-msexcel; charset=UTF-8");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-disposition: attachment; filename=" . $nombreArchivo . ".xls");

there is a BOM configuration, but don't know how set that in the header

Very Nice

I just apply this code just before the end of header

echo "\xEF\xBB\xBF";

and that solved the problem with the "special characters". thanks to mario :)

but

Now I still get this message when I want to open the downloaded file:

 "The file you are trying to open, 'file.xls', has a different format than specified by the file extension. Make sure the file is not corrupted and is from a trusted source before opening. Do you want to open the file now?" 

any ideas for avoid that message?

Community
  • 1
  • 1
Camilo Salas
  • 143
  • 2
  • 10
  • How are you generating the Excel file? Or are you just outputting CSV or a HTML table with a fake MIME type? – mario Oct 27 '12 at 15:25
  • The only way to avoid the "different format" message is to apply the correct file extension to the file format, so if you're writing a csv file, use a .csv extension; if you're writing an html markup file, use an .html or .htm extension; if you use an .xls extension then you need to create a BIFF format Excel file – Mark Baker Oct 27 '12 at 18:27

0 Answers0