PHP_excel: export to xlsx loads successfully, but when we open it, it shows a warning that Excel has detected unreadable content

I am using php_excel to export to xlsx. In my application, I am using a template. When I download, the xlsx file loads normally, but when we open it, the following warning is displayed:

" Excel detected unreadable content in" project_report (3) .xlsx. "Would you like to restore the contents of this workbook? If you trust the source of this workbook, click Yes ."

If I click yes, it opens the file correctly.

And one more thing when I attach the downloaded file to the mail. And if I open it, sing the Google Spread sheet, it will say that the bad format does not open.

therefore, if someone knows the reason, please suggest me to solve this problem.

-2
source share
1 answer

check your headers, here are mine:

header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download");; header("Content-Disposition: attachment;filename=$filename"); header("Content-Transfer-Encoding: binary"); $objWriter->save('php://output'); 

check output (spaces before <?php forgot echo ? etc.

0
source

All Articles