0

This code is creates a xlsx file :

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));

I would like to allow visitors to visit and get the file in choosing "open or save"

Do you know how can I get this ?

Thanks in advance.

Amit Prajapati
  • 13,525
  • 8
  • 62
  • 84
David
  • 427
  • 1
  • 5
  • 21
  • 1
    Have you looked at the examples such as `01simple-download-xlsx.php` to see how it sends headers to the browser? And how it saves to `php://output` – Mark Baker Nov 16 '13 at 10:12

2 Answers2

3

The code from 01simple-download-xlsx.php in the /Examples folder shows how to do this:

// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
0
// Redirect output to a client’s web browser (Excel5)

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

$objWriter->save('Template.xls');

header('location:Template.xls');
Axel
  • 3,331
  • 11
  • 35
  • 58
Mrinmoy
  • 31
  • 1