3

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 :

$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

fabrik
  • 14,094
  • 8
  • 55
  • 71
Grumpy
  • 2,140
  • 1
  • 25
  • 38
  • What is $filename? If it's Something.xls then that's probably all you can do; mime & extension. I sometimes use the html-tables-to-excel shortcut but you can get a somewhat more native solution with the Spreadsheet Writer library in Pear – Hans Aug 24 '10 at 09:47
  • thats the content type i use, don't have any problems. You'll probably find your issue is browser specific too, not that that helps you – Andrew Bullock Aug 24 '10 at 09:50
  • filename = jaar.xls I wish it was that simple, i have added it to the source. – Grumpy Aug 24 '10 at 09:57

3 Answers3

1

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

header("Content-Disposition: attachment; filename='$filename'");
Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
1

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

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

Grumpy
  • 2,140
  • 1
  • 25
  • 38
0
header("Content-Disposition: attachment; filename=".$filename);

This is enough to save as excel file

Vishnu Jayan
  • 149
  • 3
  • 16