php - PHPExcel in Zend2 Controller -
i'm trying phpexcel working zend2. working, not intended (i can write file, cannot let download without saving). found examples, this:
$objphpexcel = .... header('content-type: application/vnd.ms-excel'); header('content-disposition: attachment;filename="01simple.xls"'); header('cache-control: max-age=0'); $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel5'); $objwriter->save('php://output');
and file allowed download. how can achive similar in zend2 controller? i've tried far:
public function generateraportaction() { $objphpexcel = new phpexcel(); $objphpexcel->getactivesheet()->setcellvalue( 'b8', 'some value' ); $objwriter = \phpexcel_iofactory::createwriter( $objphpexcel, 'excel5' ); $response = $this->getevent()->getresponse(); $response->getheaders()->clearheaders()->addheaders( array( 'pragma' => 'public', 'content-type' => 'application/vnd.ms-excel', 'content-disposition' => 'attachment; filename="test.xls"', 'cache-control' => 'must-revalidate, post-check=0, pre-check=0', 'content-transfer-encoding' => 'binary', ) ); $objwriter->save( 'php://output' ); return $response; }
but gives me "echo like" output on page. second attempt was:
$response->setcontent($objwriter->save( 'php://output' ));
yet result same.
as @aydin hassan commented, i've tried with:
$objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel2007'); ob_start(); $objwriter->save('php://output'); $exceloutput = ob_get_clean();
and passed $exceloutput
response content, , works great!
$response->setcontent($exceloutput);
Comments
Post a Comment