[EXTENSION]eexcelview

Just released a new ver with many improvements. Enjoy ! :)

I think you should look at the ‘param’ property from dataProvider when rendering export buttons.

I don’t understand. Why should I look at the ‘param’ property of the dataProvider ?

My english is rather bad so…

Above my gridView I have two date inputs and Find button. I select time range and push Find. Page reloads, and in my gridView I can see records between date_from and date_to. But when I try to export this records, page reload again and what I set in date_from and date_to is lost.

And I find another bug:


'columns'=>array(

post.number,

...

doesn’t work

but


'columns'=>array(

array(

   'name'=>'post.number',

   'value'=>'$data->post->number',

...

works.

Cant find the attached file. Morever, Writer is a folder not a file, so can u kindly point me to where to update?

to solve an problem with some data who’s start with / are similar to a numeric value, i modify the code into the method renderRow:




if ($column->type != 'ftext') {

	$value=$value===null ? "" : $column->grid->getFormatter()->format($value,$column->type);

	$this->objPHPExcel->getActiveSheet()->setCellValue($this->columnName($a).($row+2) ,$value);

} else {

	$value = $value===null ? "" : $column->grid->getFormatter()->format($value,'text');

		$this->objPHPExcel->getActiveSheet()->getCell($this->columnName($a).($row+2))->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);

}



You can use it by specify the type with the column property : ‘type’=>‘ftext’

Also, into the xls file you have the value 00012345 and not 12345.

how can i add header and footer of excel sheet such as: name of report, date, company name, signature, company logo, summary …

I attached an example.

help me, please.

anyone help me???

Hello,

I am trying to use this extension without success. Actually I am getting the contents printed in the web page rather than exported to the output stream.

Controller




   public function actionExport2excel() {


      $model = new GeneralProcess();

            

      $this->widget('application.extensions.EExcelView.EExcelView' , array(

                        'dataProvider' =>  new CActiveDataProvider ($model , array('pagination'=>false)),

                        'title'=>"Some title",

                        'exportType'=>'Excel2007',

                        'columns'=>array('id','court_process'),

      ));

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

   } 



View




$this->menu=array(

	array('label'=>'Create Process','url'=>array('create')),

        array('label'=>'Export To Excel','url'=>array('export2excel')),

);



When I click on “Export to Excel” link I will be redirected to the export2excel action and the contents of dataProvider (columns ‘id’ and ‘court_process’) are written on the screen.

Am I doing something wrong?

Thanks for the help

A.Miguel

@A.Miguel try to add this property

‘grid_mode’=>‘export’,

@banamlehsb: that’s not possible at the moment. May I can think of some callback function to render the header and footer. Or may be I can return the excel object so you can add anything with your own code.

Yeah, I found it while debugging your code! ;)

Thanks for the quick reply anyway!

A.Miguel

Can i past in an array of values and columns and it displays the excel spreadsheet

Hello,

Can I format output of the excel file? I want to bold the header row and change the font of the table.

Why dont you just pass this to CArrayDataProvider and use it as a datasource ?

Well formatting excel tables might be quite specific to any user/project. So I’ve created callback functions when rendering headers and rows. So you can create a callback function for onRenderHeaderCell(PHPExcel_Cell $cell, string $value) and use the $cell to do whatever you want, see PHPExcel’s documentation for more info.

Where should I place this code?

You create of function in you controller onRenderHeaderCell(PHPExcel_Cell $cell, string $value) then when you init the widget , you do it like this:

$this->widget(…

‘onRenderHeaderCell’=>array($this, ‘onRenderHeaderCell’),

…);

I did some ugly hacking in the EExcelView::renderRow() method. Not very nice but it suited my need for that time.


public function renderRow($row)

{

	$data=$this->dataProvider->getData();			

	

	if(!$this->showHeader) $offset = 1;

	else $offset = 0;

	

	$a=0;

	foreach($this->columns as $n=>$column)

	{

	    if($column->value!==null) 

	        $value=$this->evaluateExpression($column->value ,array('data'=>$data[$row]));

	    else if($column->name!==null) 

	        $value=$data[$row][$column->name];


	    $value=$value===null ? "" : $column->grid->getFormatter()->format($value,$column->type);

	    

		$a++;

		if($column->type=='text')

			$this->objPHPExcel->getActiveSheet()->setCellValueExplicit($this->columnName($a).($row+2-$offset), $value, PHPExcel_Cell_DataType::TYPE_STRING);

		else

			$this->objPHPExcel->getActiveSheet()->setCellValue($this->columnName($a).($row+2-$offset), $value);

		

		if(substr($value,'\n'))

			$this->objPHPExcel->getActiveSheet()->getStyle($this->columnName($a).($row+2-$offset))->getAlignment()->setWrapText(true);

		

		if(isset($column->cssClassExpression))

		{

			$css = $this->evaluateExpression($column->cssClassExpression,array('data'=>$data[$row]));

			if($css=='red')

			{

				$background = 'FF0000';

				$font = 'FFFFFF';

			}

			else if($css=='yellow')

			{

				$background = 'FFFF00';

				$font = '000000';

			}

			else if($css=='green')

			{

				$background = '008000';

				$font = 'FFFFFF';

			}

			else

			{

				$background = 'FFFFFF';

				$font = '000000';

			}

			

			$this->objPHPExcel->getActiveSheet()->getStyle($this->columnName($a).($row+2-$offset))->applyFromArray(

				array(	'font'	=> array(

									'bold'      => true,

									'color'	=> array( 'rgb' => $font )

								),

						'fill' 	=> array(

									 'type'		=> PHPExcel_Style_Fill::FILL_SOLID,

									 'color'	=> array('rgb' => $background)

								),

				));

			$this->objPHPExcel->getActiveSheet()->getStyle($this->columnName($a).($row+2-$offset))->getAlignment()

					->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);

		}

		

		$this->_lastCell = $this->columnName($a).($row+2-$offset);

	}	

}

Hi, thank you for your helpful extension. I’ve got it working but saw the release notes and the mention of export buttons as being new to v0.3. I do not quite understand what its purpose is and how it is to be used. Could you please post an example? My initial thought, after reading the notes, was that it customizes the default CGridView with export buttons…is this correct?

I was able to figure it out on my own but am still trying to get the actual exporting to happen now.