0
header("Content-type: application/octet-stream"); 
header("Content-Disposition: attachment; filename=filename.xls");
header("Pragma: no-cache");
header("Expires: 0");

On my local system above code work properly but on server its not work.

chriz
  • 1,580
  • 19
  • 27

2 Answers2

0

I don't know yet if it will help you, but if you wan't, you can generalize octet-stream output for some extension, directly in VirtualHost config.

For that, use AddType application/octet-stream .xlsx .xls

And all url to Excel files would be downloaded.

JoDev
  • 6,633
  • 1
  • 22
  • 37
0

write ob_clean() just before the last line below , i was having same problem got resolved by this

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="temlik.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
ob_clean();
$objWriter->save('php://output');
sandeepKumar
  • 771
  • 2
  • 12
  • 33