I'm trying to get PHPExcel working with Zend2. Actually it is working, but not as I intended (I can write to file, but cannot let download without saving). I found some examples, where you simply do something like 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 was allowed to download. How can I achive something similar in Zend2 Controller? I've tried so 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 it gives me "echo like" output on my page. My second attempt was:
$response->setContent($objWriter->save( 'php://output' ));
Yet result was the same.