Empty output file by browser

Topics: Developer Forum, User Forum
Aug 24, 2011 at 7:45 PM
Edited Aug 24, 2011 at 7:47 PM

PHP:  PHP Version 5.3.5-1ubuntu7.2
OS: ubuntu 11.04
phpexcel: 1.7.6
framework: cakephp 1.3.2

Issue:

I begin with phpexcel, so I tried to make a test to export a simple excel file.

It works if I save the file on the server hard disk, but if I output it to the browser, the file is empty.

Thank your for your help.

Note that the PHPexcel file are include in the controller (cakephp).

 

Working - Code to save the file on the server's hard disk

 

$workbook = new PHPExcel;

$sheet =$workbook->getActiveSheet();

$sheet->setCellValue('A1','MaitrePylos');

$writer = new PHPExcel_Writer_Excel2007($workbook);

$records = './fichier.xlsx';

$writer->save($records);

 

 

Not working - Code to output to the browser

 

<?php

$workbook = new PHPExcel;

$sheet =
$workbook->getActiveSheet();
$sheet->setCellValue('A1','MaitrePylos');

$writer = new PHPExcel_Writer_Excel2007($workbook);


 header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
 header('Content-Disposition:inline;filename=Fichier.xlsx ');
 $writer->save('php://output');

?>