$filename = "file.xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$content = "asd";
echo $content;
If $content contains some unicode symbols, in excel file, result is something like this : áƒáƒ¡áƒ“
How to solve this? How to set this php file UTF8 encoding ?
I am trying: header("Content-Type: application/vnd.ms-excel; charset=utf-8"); but not works
If you are generating file by simply echoing strings, you should create it as xml then doing an echo you need to add encoding to file.
$content = '<?xml version="1.0" encoding="UTF-8"?>'
You need to create your file in xml as its expected.
Ex:
<?xml version="1.0" encoding="UTF-8"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet>
<Table>
<Row>
<Cell><Data>$content</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
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