integrate csv writer into cakephp. keep getting empty csv file

Topics: Developer Forum, User Forum
Jan 27, 2012 at 12:11 AM
Edited Jan 27, 2012 at 12:12 AM



I am trying to integrate the latest 1.7.6 into cakephp 2.0 as a Helper class. I keep getting empty csv file.

Please advise.


include_once(APP . DS . 'Plugin' . DS . 'PhpExcel' . DS . 'Vendor' . DS . 'PhpExcel' . DS . 'IOFactory.php');

include_once(APP . DS . 'Plugin' . DS . 'PhpExcel' . DS . 'Vendor' . DS . 'PhpExcel' . DS . 'PHPExcel.php');

class CsvHelper extends AppHelper {

	var $objPHPExcel; 
	var $writer; 
	var $sheet; 
	var $data;
	var $blacklist = array();

	public function csvHelper() {
		$this->objPHPExcel = new PHPExcel(); 

	function generate($data, $title = 'Report') {

		$this->data = $data;
		return true;


	function _output($title, $type = 'CSV') {

		header("Content-type: text/csv");
		header('Content-Disposition: attachment;filename="'.$title.'.csv"');
		header('Cache-Control: max-age=0');
		$this->objPHPExcel->getActiveSheet()->setCellValue('A1', 'First Name')->setCellValue('B1', 'Last Name') ->setCellValue('C1', 'Age') ->setCellValue('D1', 'Date of birth') ->setCellValue('E1', 'Salary');

		$this->writer = PHPExcel_IOFactory::createWriter($this->objPHPExcel, 'CSV');



Jan 27, 2012 at 8:16 AM

have you ever looked at php's builtin csv functions? Why you would want to use PHPExcel (or any full blown library for that matter) just to build a csv document is beyond me.


As for your problem, have you tried setting debug to 2 in cake php, otherwise warnings and notices are suppressed.

Jan 27, 2012 at 8:41 AM

Hi borft, 


I did not know that there are csv functions within php itself.

I am thinking of eventually allowing export of excel as well hence i considered phpexcel.


I have set debug to 2, nothing shows up.