Export To Excel With Yii

I haven’t been able to figure out any good solution for how to get all nested tables into 1 worksheet. I think I need help with this. Can anyone please help out with this?

I have changed these 2 rows to only get one worksheet.

And row 238 to this:

However, I am still struggling with getting the columns right. Any idea of where to change the $xcol param to get this working properly?

Is there anyone reading this who can help me out??

Please can anyone tell me how to add header or title to the excel sheet.

I have generated the excel sheet using eexcelview and phpexcel extension in csv type but title is not displayed.

I am struggling from past two days studied various articles but didnt figure out,I dont know what to add and where to add,as i am new to yii.

I have used php_writeexcel extension to export in Excel. (Attached in this reply. Extract and put in Extension folder).

In Controller add an action for Export like below code :

public function actionExportExcel()


{


	require_once Yii::app()->basePath."/extensions/php_writeexcel/class.writeexcel_workbookbig.inc.php";


	require_once Yii::app()->basePath."/extensions/php_writeexcel/class.writeexcel_worksheet.inc.php";





	$fname = tempnam("/tmp", time().".xls");


	$workbook = &new writeexcel_workbookbig($fname);


	$worksheet = &$workbook->addworksheet();





	$worksheet->set_column(0, 50, 15);





	$headers = array(


	      'attribute1',


	      'attribute2',      


	      'attribute3',


	      'attribute4',


	      'attribute..n',


	);





	$row = array();





	foreach($headers as $header) 


	{


		$row[] = Model_name::model()->getAttributeLabel($header);


	}





	$i=0;


	foreach($headers as $header) 


	{





		$worksheet->write(1, $i,iconv('UTF-8', 'ISO-8859-1//IGNORE',$row[$i]));


		$i++;


	}





	$model=new Model_name('search');





	$model->unsetAttributes();  // clear any default values








	$model->attributes=$_POST['Form_name'];








	$dp = $model->search();


	$models = $dp->getData();











	$worksheet->set_column('A:A', 55);


	$worksheet->set_column('B:B', 20);


	$worksheet->set_column('C:C', 20);


	$worksheet->set_column('D:D', 20);


	$worksheet->set_column('E:E', 20);


	$worksheet->set_column('F:F', 20);


	$worksheet->set_column('G:G', 30);


	$worksheet->set_column('H:H', 20);

// Some Heading Format that we can use for each cell

//***************************************

	$heading  =& $workbook->addformat(array(


						underline    => 1,


						fg_color   => 49,


						size    => 20,


						merge   => 1,


						pattern => 1,


						color => 'white',


						font => 'Calibri'


						));





	$heading1  =& $workbook->addformat(array(


						bold    => 1,


						fg_color   => 49,


						size    => 12,


						pattern => 1,


						color => 'white',


						align => 'center',


						font => 'verdana'


						));





	$inner_heading  =& $workbook->addformat(array(


						bold    => 1,


						size    => 11,


						align => 'center',


						font => 'verdana'


						));





	$inner_text  =& $workbook->addformat(array(


						size    => 11,


						align => 'center',


						font => 'verdana'


						));


	$inner_text->set_size(11);


	$inner_text->set_font('Verdana');


	$inner_text->set_align('center');


	$inner_text->set_align('vcenter');





	$inner_heading->set_size(11);


	$inner_heading->set_font('Verdana');


	$inner_heading->set_align('center');


	$inner_heading->set_align('vcenter');

//***********************************************

	$worksheet->write_row('A1', "TEXT", $heading);





	$worksheet->write_row('A2', "TEXT", $heading1);








	$c=1;





	foreach($models as $model) 


	{





		  $c++;





		  $worksheet->write($c, 0, CHtml::value($model,'attribute1'),$inner_text);


		  $worksheet->write($c, 1, CHtml::value($model,'attribute2'),$inner_text);


		  $worksheet->write($c, 2, CHtml::value($model,'attribute..n'),$inner_text);








	}


	$workbook->close();





	$filename = "filename_".time().".xls";


	header("Content-Type: application/x-msexcel; name=\"$filename\"");


	header("Content-Disposition: inline; filename=\"$filename\"");


	$fh=fopen($fname, "rb");


	fpassthru($fh);


	unlink($fname);








	Yii::app()->end();


}

http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/demo/

http://www.yiiframework.com/forum/index.php/topic/7660-export-to-excel/