public function exportarContatosAction() { $this->_helper->viewRenderer->setNoRender(true); $data = new Application_Model_Contatos(); $collection = (array) $data->getAllContatos(); $collection = $this->titulosPlanilha($collection); $export = new PHPExcel(); $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp; $cacheSettings = array(' memoryCacheSize ' => '8MB'); PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); $export->setActiveSheetIndex(0)->fromArray($collection, null, 'A1'); $xmlWriter = new PHPExcel_Writer_Excel2007($export); header("Pragma: protected"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public", false); // required for certain browsers header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'); header("Content-Disposition: attachment;filename='contatos.xlsx'"); header("Content-Transfer-Encoding: binary"); $xmlWriter->save("php://output"); exit; }