Export to excel

I read from a few forums that eexcelview can be used to export the table grid to excel. Can anyone tell me how it can work if we filter the table and then export only the filtered results?i can do the normal one(i.e. export full grid data) but cant get the filtered data to be exported to excel…

Hello YiiPlayBoy i’m trying to do the same thing.

I’ve used this extension remember-filters-gridview. It works very well with search filter, but I think it can’t remember sort filters.

I hope it helps.

Bye.

Could you tell me how to do an export here?have included the extension…how should my export button be?

presently its as follows


echo CHtml::button('Export To Excel', array('submit' => array('TblBasicEmployeeDetails/export'),'YII_CSRF_TOKEN' => Yii::app()->request->csrfToken

));


public function actionExport()

        {

			$model=new TblBasicEmployeeDetails;

            /* $bh = Yii::createComponent(array(

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

            ));

            $this->attachBehavior('excelExport',$bh);

 

            $this->toExcel($model->search(),

                array(

                    'emp_code',

                    'user_code',

                    'first_name',

                    'employee_full_name',

                    'designation.designation_name::Designation',

                    'department.department_name::Department',

                    'process.process_name::Process',

                    'location.location_name::Location',

                    'doj::Date of Joining',

                    'email_address',

                    'manager.employee_full_name::Manager',

                    'shiftManager.employee_full_name::Shift Manager'

                ),

                'Employee Details',

                array(

                    'creator' => 'CCC Admin',

                ),

                'Excel5' // This is the default value, so you can omit it. You can export to CSV, PDF or HTML too

            );

//thus we can keep the modify in a method ! */

}

how do i change the controller action code i.e. actionExport?

Really appreciate if you could get me through this stumble block.Refreshing this page a few times just to see if there is any new reply to this post ::)

In my case, I use it in this way:

In the controller, you have to give permission to the action then




        public function actionExcel(){

		$model=new machine('search');

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

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

		'grid_mode'=>'export',

		'exportType'=>'Excel5',

		'filename'=>'report',

		));

	}



In the admin view I have this




      <?php echo CHtml::link('Excel',array('excel'),array ('class' => 'bt-excel')); ?>



so whats the relSearch()? i dont have it.where do i define it?

thanks for helping me :D i got it using the search() itself…now only to change the id’s to names…i mean the foreign keys to be converted to their name…i will check it now…

Sorry I forget to change to search. relSearch is a custom function.

In your case use the normal search function of your model.

A pleasure! It was my first reply to a Yii question :lol:

any idea for the relations? i get the entire table data…need to convert them too in the excel file…am specifying the columns but it aint working…


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

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

				//'grid_mode'=>'export',

				'exportType'=>'Excel5',

				'filename'=>'Employee Details',

'columns'=>array('emp_code',

                    'user_code',

                    'first_name')				

			));

sorry, this last one… :)

silly of me…it works…thanks a lot…and congrats for your first post reply :)

Can i ask you all some question.

I have a problem with my EExcelView export result.

I have a field with a default value (it is filled by its value if it’s left empty).

I don’t know why, only the row that contain this default value can appear (not with other row).

I tried to view result in grid, and i found that the filter is not working. Also, in the filter box of the field with default value, it is filled by its default value (maybe this is why only the row that contain this default value can appear). But it is cannot be change.

I don’t know what happen actually, besides in the first time it can work properly.

Please, help me fix this problem?

do you mean a column with a default value?

The attribute is being set to the default value in your filter object when you instantiate it. To get around that, after creating the filter object but before assigning values from the GET array, try setting the value of the defaulting attribute to null.