Is there a way to prevent PHP to auto-changing encoding for Excel-file or set encoding?
Already tried:
ini_set('default_charset', 'ANSI');
ini_set('output_encoding', 'ANSI');
header('Content-Type: application/vnd.ms-excel; charset=ANSI');
Using "phpoffice/phpexcel". If I save built Excel-file on server, and download saved file without PHP, than encoding for that file in NotePad++ is ANSI, and file opens correctly in MS Excel program.
But if I tried to return that correct file by PHP:
readfile($file_path);
// OR directly write to output
$objWriter->save('php://output');
Then downloaded Excel-file encoding will be UTF-8-BOM, end MS Excel shows for that file only strange symbols. But I can open that file in NotePad++ and change encoding to ANSI, then that file correctly opens in MS Excel.
How to return with PHP that Excel-file to client without auto-changing encoding of that file?
Thanks to @CBroe and Detecting UTF BOM (byte order mark) using PHP, before set "attachment" headers putted that:
And found, was BOM in one Class, I`ve removed that BOM, and now PHP returns correct Excel-file.