public static function sendExcel(\PHPExcel_Writer_IWriter $writer, $fileName = NULL) { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Disposition: attachment;filename={$fileName}"); header("Content-Transfer-Encoding: binary "); //Seems that there's a bug on PHP excel 2007 and we can't write directly //to stdout. Actually the code attempts to make the EXACT same thing //we are doing here when the string equals to php://stdout or php://output $file = File::makeTemporary('__apf_excel_download'); $writer->save($file); $file->chunkedOutput(); }
/** * Set writer * If extension is csv, set some parameters. */ protected function _setWriter() { $this->writer = PHPExcel_IOFactory::createWriter($this->excel, $this->format); if ($this->format == 'CSV') { $this->writer->setDelimiter(','); $this->writer->setEnclosure('"'); $this->writer->setLineEnding("\r\n"); } }
/** * Stream the file as Response. * * @param \PHPExcel_Writer_IWriter $writer * @param int $status * @param array $headers * * @return StreamedResponse */ public function createStreamedResponse(\PHPExcel_Writer_IWriter $writer, $status = 200, $headers = array()) { return new StreamedResponse(function () use($writer) { $writer->save('php://output'); }, $status, $headers); }
/** * @param PHPExcel_Writer_IWriter $objWriter */ protected function saveOutputAndExit(PHPExcel_Writer_IWriter $objWriter) { $objWriter->save('php://output'); exit; }
/** * @test * @covers Plum\PlumExcel\ExcelWriter::finish() */ public function finishWritesExcelFileToDisk() { $this->excelWriter->shouldReceive('save')->with(vfsStream::url('fixtures/test.xlsx'))->once(); $this->writer->finish(); }
/** * @param \PHPExcel_Writer_IWriter $writer * * @return StreamedResponse */ public function createResponseForExcel(\PHPExcel_Writer_IWriter $writer) { $response = new StreamedResponse(function () use($writer) { $writer->save('php://output'); }); $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); return $response; }