For exporting our reports, we set the header to 'Content-Disposition: attachment;filename=fileName.xls' and dump the html to the output buffer and it downloaded the excel file nice and clean.
This was used to work until recently and now the downloaded file does not open in Excel. It doesn't give any error, just shows the blank gray screen similar to the screen when you close all the worksheets.
Strange enough, if you just open the file in Notepad++, add a space and save it, Excel WILL open it.
I suspect it to be something to do w/ the encoding of the file which is not acceptable to excel when the file is downloaded but something changes after you edit it in Notepad++ and excel would open it after the edit.
I have tried using ob_clean(), trim and converted the content to utf8 before dumping but nothing seems to work, what am I doing wrong?
Here is a sample code that recreates the issue I have:
ob_clean();
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=filename.xls");
header('Cache-Control: max-age=0');
header_remove('Pragma');
// simple html table
echo '<table><thead><tr><td>header 1</td><td>header 2</td></tr></thead><tbody><tr><td>content 1</td><td>content 2</td></tr></tbody></table>';
The above code snippet downloads the file 'filename.xls', excel initially does not open it, but after editing it the way I described earlier, excel WILL open it.
Thanks.