0

I am using PHPExcel.php and /PHPExcel/Writer/Excel2007.php in my application , in my code:

$objPHPExcel = new PHPExcel();

//adding values to cells

$objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('b'.$position,'Total')
 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="file.xlsx"');
$objWriter->save('php://output');

But the excel is not downloaded at client side but if we use $objWriter->save($fileName); it saves the excel in server location successfully .I got following out put in browser

PK2�GG�D�X�[Content_Types].xml��MN�0���"�%nY ��vAa �(0����ؖg�w{&i�@�nbE�{��y��d۸l m������X�(���)���F���;@1_������c)j�x/%��E��y� �QĿi!��K�y3�J<���Z1�0?Y�L%zV c��Ib7�����a/l٥P1:�q�r��j��j0A����u�""���(� ���W�M��)Tj�({ܲ�>�O��,X٭���>B��~׭���Ӥ6�J=�oBZ����t��X4���Cg�,���QgmrL�ٯc�e���

I am using ubuntu and LibreOffice .Please help me your answer will be appreciate

Shekkar
  • 244
  • 3
  • 10
  • 21
  • header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"'); is not working for me . – Shekkar Aug 07 '15 at 14:13
  • Maybe you have output before calling save() ? The script is stopped after saving the file ? – Debflav Aug 07 '15 at 14:20
  • @Debflav , thank you for your replay but my case ,No , because of $objWriter->save('php://output'); i got above out put , if commented the above line then i got no out put .and after save () if any echo statements , then i got those echo statements. – Shekkar Aug 07 '15 at 14:30
  • possible duplicate of [Generate Excel file, but do not save to the server](http://stackoverflow.com/questions/20676839/generate-excel-file-but-do-not-save-to-the-server) – Katrina Aug 07 '15 at 20:22
  • Are you using any kind of framework thatmight try sending its own headers to override those you're sending here? What code runs after `$objWriter->save('php://output');`? – Mark Baker Aug 08 '15 at 09:02
  • @Mark Baker i have no code after $objWriter->save('php://output'); – Shekkar Aug 11 '15 at 05:59
  • Do you have anything like a terminating `?>`? – Mark Baker Aug 11 '15 at 06:52
  • @Mark Baker ,in my filename.php: – Shekkar Aug 11 '15 at 08:20

0 Answers0