Home » excel » php – header for excel file save as

php – header for excel file save as

Posted by: admin April 23, 2020 Leave a comment


im able to output an excel file by php and it opens correctly in excel. No problems there. When the user clicsk save as in Excel it comes with first option .txt How can i set the header so first option will .xls with save as.
Headers im using now :

header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");

Thanks in advance

How to&Answers:

If your name has spaces in it, you should try quoting it:

header("Content-Disposition: attachment; filename='$filename'");


the solution is to use phpexcel

if the xls file used is build with /t like a textfile it will be handled like a txt file by excel


header("Content-Disposition: attachment; filename=".$filename);

This is enough to save as excel file