[EXTENSION]eexcelview

Hi everyone,


            $this->widget('ext.eexcelview.EExcelView', array(

                //'libPath' => 'ext.phpexcel.Classes.PHPExcel',

                'id' => 'tool-grid',

                'dataProvider' => $provider,

                'title' => 'Report',

                'grid_mode' => 'export',

                'filename' => 'PDFreport',

                'disablePaging' => false,

                'exportType' => 'PDF',

                'autoWidth' => false,

                'stream' => true, 

                    )

            );

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

        }

Same code with ‘exportType’ => ‘Excel2007’ is used to generate to generate Excel sheet and is working fine. When I use above code to generate for PDF, it gives me error like ‘File not found’.

Please guide me.

Thanks

Finally, I found my mistake. I forgot to include external pdf library. I added the mPDF library and set PdfRendererName and PdfRendererPath. As a result, I got the PDF saved.

Thanks

@simonweb

I had the same issue and searched my httpd logs on my centos server and found that a folder case error was causing the issue. The following line in EExcelView.php:




public $libPath = 'ext.PHPExcel.Classes.PHPExcel'; //the path to the PHP excel lib



Needs to be changed




public $libPath = 'ext.phpexcel.Classes.PHPExcel'; //the path to the PHP excel lib



Or if you don’t want to edit the extension file, update the extension folder for phpexcel to match the $libPath to the extension.

Hi,

  1. I am able to use ‘onRenderHeaderCell’ and ‘onRenderDataCell’ but cannot use ‘onRenderFooterCell’. Can anyone please give an example of it?

  2. I am trying to display total using ‘onRenderFooterCell’. Is it the correct approach?

Thanks

I managed to solve this issue. But now facing a new one.

I need to insert a new row to insert logo and text above header row. Using ‘onRenderHeaderCell’, I am able to do it.

The problem is that it overwrites the header row and cannot manage to insert the header row in second row. Can anyone guide me how to restore the header row below first row?

Thanks

Please could describe how you did it? I’m not able to get this working…

Someone could help me exporting in pdf please?

Hey did you ever solve this? Or maybe someone else?

Basically I would like to add additional columns to the exported sheet that would otherwise clog up the gridview.

I think the widget will only export the displayed columns (it’s made for it). I resolved making a button that point to a controller action that produces a file with different number of columns.

This in the controller.





public function actionExportAll() {

        //create dataprovider with data that you want to export

        $tobexported = new CActiveDataProvider('Risultati', array(

            'criteria' => array(

                'with' => array('table2', 'table3', ...),//if you want to export also related table

                'together' => true,//important

            ),

            'pagination' => 'false'//or true if you need

        ));




        $columns = array(

            'col1::id',

                'col2::name',

                'col3::tel',

                ...


        );

        if (isset($_GET['type'])) {

            switch ($_GET['type']) {

                case 'Excel5':

                    $tipofile = 'Excel5';break;

                case 'csv':

                    $tipofile = 'CSV'; break;

                case 'pdf':

                    $tipofile = 'PDF';break;

                default:

                    $tipofile = 'Excel5';

            };

        }


        date_default_timezone_set('Europe/Belgrade');

        $filename = date("YmdHis"); //to get a filename with date


        $this->toExcel($tobexported, $columns, $filename, array(

            'creator' => 'INT',

                ), $tipofile

        );

    }



called by a button over my GridView




$this->widget('zii.widgets.jui.CJuiButton', array(

                'buttonType'=>'link',

                'url'=>array('exportAll', 'type'=>'csv'),

                'label'=>'Export csv',

                'htmlOptions'=>array('id'=>'exportallcsv'),




)); 



I hope it helps.

Still waiting for someone helps me how to print a pdf, with any kind of pdf library…

@FunnyDj

Thanks for that. I’m sure that’ll work for what I need right now, though what are you doing in the toExcel method?

Actually, I managed to find another way of doing it which will go a long way towards my ultimate goal of providing a dialog where the user can choose which columns are to be included in the export.

In the init() method in EExcelView, I just added some test code in the ‘Export’ loop:




public function init() {

...

if($this->grid_mode == 'export')

{			

	$this->title = $this->title ? $this->title : Yii::app()->getController()->getPageTitle();

        // Add a new column

        $dataArray =

              array(

                     'name' => 'created_by',

                     'header' => 'Created By',

              );

        // Add the array to $this->columns

        $this->columns[] = $dataArray;

        // Run initColumns as usual

	$this->initColumns();

         ...



This works perfectly so I guess I can expand on it and send in an array of extra columns which I can loop over.

It would still be nice to see your toExcel method for reference though! :slight_smile:

Thanks for your help!

Sorry i forgot it. I used the eexcel behavior (http://www.yiiframework.com/extension/toexcel/). If you open EExcelBehavior.php you will find also a little explanation on how to use it.

Simply put in the controller:




public function behaviours()

	{

	  return array(

	     'eexcelview'=>array(

	        'class'=>'ext.eexcelview.EExcelBehavior',

	     ),

	  );

	}



then you can call the function toExcel. It’s only a wrapper(look in the file, is quite siply).

It’s like to call $this->owner->widget(‘ext.eexcelview.EExcelView’, …); with all params.

The concept is to create the widget inside the controller action with custom columns, i used the behavior just because it uses the function instead setting the widget.

Or if you want to do it simply, istead to call toExcel, just remove toExcel and put this:




$this->render('exporting', array(

            'dataprovider'=>$tobexported,

            

        ));



put exporting.php inside of /views/modelname forlder and inside it:




$this->widget('ext.eexcelview.EExcelView', array(

        'dataProvider'=>$dataprovider,

        'title'=>'put name here',

        [b]'grid_mode'=>'export',[/b]

        'exportType'=>'Excel5',

        'columns'=>array(

            'id',

            'user',

             ...

            )

       

));



Thanks a million for providing all that info! It’s a great help!

I am currently running through the same problem. Could you please tell me how did u add the pdf library to Yii project. Thanks.

Hi,

This extension works really great with one CGrivView on a page. Is it possible to apply this extension to more than one CGrivView on the same page?

Thanks

Yes. You would do so in the same manner as rendering multiple grids on the same page, which is by passing a different dataProvider object.

Hi,This is my controller code i cannot get the downloaded file in excel using this extension can anyone help me




public function actionExcel() {

        $model=new News('search');

    

               

              

        $this->widget('EExcelView', array(

     'dataProvider'=> $model->search(),

     'title'=>'My CSV File',

     'autoWidth'=>false,

            'grid_mode' => 'export',

            'title' => 'News Analytics',

            'filename' => 'report.xlsx',

            'stream' =>false,

            'exportType' =>'Excel2007',

//	'filter'=>$model,

            'columns' => array(

//		'pkreportid',

                array('header' => 'Sr#',

                    'value' => '$this->grid->dataProvider->pagination->offset + $row+1',

                ),

                array(

                    'header' => 'News Paper Name',

                    'name' => 'fknewspaperid',

                    'value' => '$data->Newspapername->newspapername',

                ),

                'headline',

                'pageno',

                'reportername',

                'city',

                array(

                    'header' => 'Date',

                    'name' => 'reportdate',

                ),

                array(

                    'header' => 'News Analyst',

                    'name' => 'fkuserid',

                    'value' => '$data->User->username',

                ),

            /*

              'fkcityid',

              'reportinggaps',

              'bridginggapsinfo',

              'publicbody',

              'fklawid',

             */

            ),

        ));

       

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


    }



This code just give me a gridview on html page how to export it in excel

Hello, is this extension still maintained?

please can anyone tell how to add header,title to the excel sheet using this extension.

I am trying out from two days please help me,i have saw many examples nothing worked out.Help this poor newbie

Thank You In Advance.

Hi,

I have lot’s of records in my table and when I try to download it as a excel using this extension. It causes my server to shut down. So basically I am unable to export large files using this extension. My Grid contains data from different tables.

So how do I download large files using this extension.

Thanks a lot sir, it worked.

but when my grid is updated it wont export the updated data, can you help me with that.

Thanks again

I am currently using 1.8.0 phpexcel…but this little bit tricky…

1.8.0 does not have inbuild pdf library so we have to load external library like mpdf , htmlpdf, tcpdf

so download from any one vendor site and copy the folder into /protected/vendor folder

Then goto eexcelview init method and replace with this code.

what i did here is simple

i am loading [size="2"]rendererName[/size][size="2"] and [/size][size="2"]rendererLibraryPath[/size][size="2"] , then i am calling [/size][size="2"]setPdfRenderer of phpexcel… It will inform [/size]

[size=“2”]hi phpexcel i am going to use mpdf and you can load library from this renderer path :)[/size]

[size="2"]Have Fun[/size]





public function init()

		{

			if(isset($_GET[$this->grid_mode_var]))

				$this->grid_mode = $_GET[$this->grid_mode_var];

			if(isset($_GET['exportType']))

				$this->exportType = $_GET['exportType'];


			$lib = Yii::getPathOfAlias($this->libPath).'.php';

			if($this->grid_mode == 'export' and !file_exists($lib)) {

				$this->grid_mode = 'grid';

				Yii::log("PHP Excel lib not found($lib). Export disabled !", CLogger::LEVEL_WARNING, 'EExcelview');

			}


			if($this->grid_mode == 'export')

			{

				$this->title = $this->title ? $this->title : Yii::app()->getController()->getPageTitle();

				$this->initColumns();

				//parent::init();

				//Autoload fix

				spl_autoload_unregister(array('YiiBase','autoload'));

				Yii::import($this->libPath, true);


				$this->objPHPExcel = new PHPExcel();

				$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;

				$rendererLibraryPath = Yii::app()->basePath . '/vendor/mpdf60';

				//  Here's the magic: you __tell__ PHPExcel what rendering engine to use

				// 	and where the library is located in your filesystem

				if (!PHPExcel_Settings::setPdfRenderer($rendererName,$rendererLibraryPath)) {

					die('NOTICE: Please set the $rendererName and $rendererLibraryPath values' .

							'<br />' .

							'at the top of this script as appropriate for your directory structure'

					);

				}


				spl_autoload_register(array('YiiBase','autoload'));

				// Creating a workbook

				$this->objPHPExcel->getProperties()->setCreator($this->creator);

				$this->objPHPExcel->getProperties()->setTitle($this->title);

				$this->objPHPExcel->getProperties()->setSubject($this->subject);

				$this->objPHPExcel->getProperties()->setDescription($this->description);

				$this->objPHPExcel->getProperties()->setCategory($this->category);

			} else

				parent::init();

		}



I hope it will help others who are trying to upgrade 1.7 phpexcel to 1.8.0 (only pdf required this settings)