Header for excel save as file

im is able to output excel file in php and it opens correctly in excel. No problem. When the user clicsk saves as in Excel, he has the first option .txt. How can I set the title, so the first option would be .xls with saving as. Headers using now:

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

Thanks in advance

+3
source share
3 answers

the solution is to use phpexcel http://phpexcel.codeplex.com/

if the used xls file builds with / t as a text file, it will be treated as a txt file with excel

+1
source

If your name contains spaces, try quoting it:

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

, excel

0

Source: https://habr.com/ru/post/1761282/


All Articles