Yii Framework Forum: [EXTENSION]eexcelview - Yii Framework Forum

Jump to content

  • (6 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • 6
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION]eexcelview http://www.yiiframework.com/extension/eexcelview/ Rate Topic: ***** 1 Votes

#81 User is offline   jvk 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-April 11

Posted 28 July 2013 - 05:07 PM

If anyone is having trouble using the wrapper outside a controller, comment out the follow lines

if(! $this->owner instanceof CController){
      Yii::log('EExcelBehavior can only be attached to an instance of CControler', 'error', 'system.base.CBehavior');
return;
}


Alter
Create instance of CWidget,
$widget = new CWidget();

Change
$this->owner->widget('ext.eexcelview.EExcelView', $arg);
To
$widget->owner->widget('ext.eexcelview.EExcelView', $arg);
0

#82 User is offline   merbauraya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 17-December 12

Posted 31 July 2013 - 01:59 PM

Hi Kuya,
Do you mind sharing your new code with the rest of community? I'm interested in trying that because I just got started working on the latest version of PHPEXcel myself.

I'm sure phreak will be interested in the improvement. Perhaps due to his busy schedule, he's not able to respond in timely manner. Thanks in advance.

Cheers!

View Postkuya1284, on 12 June 2013 - 12:16 PM, said:

Hi phreak,

I refactored your original code with a lot of major changes to improve the performance, support PHPExcel 1.7.8+ (they removed the PDF Renderer), and made it so that the extension could be used as a component. Just to give an idea on the performance increase, for an Excel5 document containing 72 columns and 611 rows, using your extension would take about 2 minutes and 20 seconds, while now it's taking about 26 seconds. This is also with using Yii's cache capabilities.

Anyway, there are a lot of significant changes that I wanted to share. Rather than create a new extension, and take away any credit from you, I wanted to send you my file and a description of changes for you to review. If you're interested and have some time, please let me know. If you prefer that I just fork your project on Github and create a new extension, that's fine as well. I just wanted to run it by you first.

Thanks.

0

#83 User is offline   Johnny Gan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 30-May 13

Posted 06 August 2013 - 03:54 PM

eexcelview is very good extension of PHPExcel for Yii. But document is too simple. Fortunately, there are some good example code in the forum. I also provide my simple code here to help someone first to use eexcelview. Hope it can save you a couple of hours to discover this cool tool.

This code is assume you already created model and curd code by GII. (See http://www.yiiframew...1/en/topics.gii)

Then we try to add the export function into admin action.

Before you can add the code, down load PHPExcel from http://phpexcel.codeplex.com/
I download version 1.7.9

and also get newest eexcelview 0.3.3 from
http://www.yiiframew...ion/eexcelview/

Step 1. add export button into _search.php, so you can export search result into CSV file. PHPExcel create CSV file very fast. So I use this in the sample code, you can change that to excel, pdf, html or other format.

<div class="row buttons">
	<?php echo CHtml::submitButton('Search', array('name'=>'search','id'=>'search')); ?>
	<?php echo CHtml::resetButton('Clear'); ?>
</div>
<!-- here is new code -->
<div class="row buttons">
<?php echo CHtml::submitButton('Export to CSV', array('name'=>'exportToExcel','id'=>'exportToExcel')); ?>
</div>
<!-- new code end -->


Step 2. add onclick response in admin.php
See below code, the new function is $('#exportToExcel').click(function(), this code will create extra passing HTTP request parameter export to admin action.
Yii::app()->clientScript->registerScript('search', "
$('#exportToExcel').click(function(){	
	window.location = '". $this->createUrl('admin')  . "?' + $(this).parents('form').serialize() + '&export=true';
    return false;
});
$('#search').click(function(){	
	$('#export').val('');
});
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#tool-grid').yiiGridView('update', {
		data: $(this).serialize()
	});	
	return false;
});
");


Step 3: Add export code into actionAdmin which is in your Controller.php file
public function actionAdmin()
{
	$model=new Tool('search');
	$model->unsetAttributes();  // clear any default values
	if(isset($_GET['Tool']))
		$model->attributes=$_GET['Tool'];

	//below is code we added for export search result to CSV file.
	if(isset($_GET['export']))
	{
		$this->widget('ext.EExcelView', array(
			'id'=>'tool-grid',
			'dataProvider'=>$model->search(),
			'title'=>'Report',
			'grid_mode'=>'export',
			'filename'=>'csvreport',
			'exportType'=>'CSV',
			'autoWidth'=>false,
			'stream'=>TRUE, //make sure you output to browser
			'columns'=>array(
			//you columns from model.
			...
			),
		));
		//some people add Yii::app()->end(); here, but it's not necessary, see EExcelView.php source code.
	}
	$this->render('admin',array(
		'model'=>$model,
	));
}


Now, you can test your code, if it works, then you can add your own code based on that.
1

#84 User is offline   phreak 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 19-February 09

Posted 10 September 2013 - 02:47 AM

View Postkuya1284, on 12 June 2013 - 12:16 PM, said:

Hi phreak,

I refactored your original code with a lot of major changes to improve the performance, support PHPExcel 1.7.8+ (they removed the PDF Renderer), and made it so that the extension could be used as a component. Just to give an idea on the performance increase, for an Excel5 document containing 72 columns and 611 rows, using your extension would take about 2 minutes and 20 seconds, while now it's taking about 26 seconds. This is also with using Yii's cache capabilities.

Anyway, there are a lot of significant changes that I wanted to share. Rather than create a new extension, and take away any credit from you, I wanted to send you my file and a description of changes for you to review. If you're interested and have some time, please let me know. If you prefer that I just fork your project on Github and create a new extension, that's fine as well. I just wanted to run it by you first.

Thanks.


Hi kuya1284, I'm changing the job so lately I really dont have any free time. Anyway if you give me the code or better make a pull request in github I will gladly update the extension. The main goal is to give something good the the yii comunity after all :).

I also updated a little the documentaion in github with step by step installation and usage guide. Pls check it out and let me know if things are more clear now.
0

#85 User is offline   marine 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 12-August 13

Posted 24 September 2013 - 10:49 AM

Hi everybody,
I'm trying to implement this extension. On my local server (WAMP & MAMP) it works fine, but when I try to export data from the server version (NGINX) it doesn't work.
No error displaying, no log, just a white page.
:blink:
I tried to put grid_mode = grid and it works, so maybe I'm facing a problem with PHPExcel?
Can somebody help me please?
0

#86 User is offline   simonweb 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 10-April 11
  • Location:London

Posted 14 October 2013 - 07:04 AM

View Postmarine, on 24 September 2013 - 10:49 AM, said:

Hi everybody,
I'm trying to implement this extension. On my local server (WAMP & MAMP) it works fine, but when I try to export data from the server version (NGINX) it doesn't work.
No error displaying, no log, just a white page.
:blink:
I tried to put grid_mode = grid and it works, so maybe I'm facing a problem with PHPExcel?
Can somebody help me please?


Im having the same issue, anyone have any ideas? I'm running on an Apache server
My Yii powered websites:

0

#87 User is offline   raiethan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 10-February 12

Posted 17 October 2013 - 09:43 PM

i have a problem when i export 800+ record with 34 columns i got error..
0

#88 User is offline   learningyii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 18-January 13

Posted 15 December 2013 - 11:48 PM

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
0

#89 User is offline   learningyii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 18-January 13

Posted 17 December 2013 - 04:15 AM

View Postlearningyii, on 15 December 2013 - 11:48 PM, said:

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
0

#90 User is offline   btilley 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 21-February 12

Posted 17 December 2013 - 09:26 AM

View Postsimonweb, on 14 October 2013 - 07:04 AM, said:

Im having the same issue, anyone have any ideas? I'm running on an Apache server


@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.
0

#91 User is offline   learningyii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 18-January 13

Posted 18 December 2013 - 09:35 PM

View Postphreak, on 05 August 2012 - 06:03 AM, said:

Well OK :) I've created a small example for you :

In you controller:
	public function actionIndex()
	{
		$rawData=array(
           array('id'=>1, 'username'=>'from', 'email'=>'array'),
           array('id'=>2, 'username'=>'test 2', 'email'=>'hello@example.com'),
       );
       $data = new CArrayDataProvider($rawData);
	   $this->render('index', compact('data'));
	}
    
    public function onRenderHeaderCell(PHPExcel_Cell $cell, $value)
    {
        $worksheet = $cell->getParent();
        $worksheet->getStyle($cell->getCoordinate())->getFont()->setBold(true);
        if($value == 'email')
            $worksheet->getStyle($cell->getCoordinate())->getFont()->setItalic(true);
        
    }


In you view:
<?php 
    $this->widget('ext.EExcelView', array(
        'dataProvider'=>$data,
        'template'=>"{summary}\n{items}\n{exportbuttons}\n{pager}",
        'onRenderHeaderCell'=>array($this, 'onRenderHeaderCell'),
    ));
?>


So now you have all headers bold and the "email" is bold and italic :)

Have fun !



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
0

#92 User is offline   learningyii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 18-January 13

Posted 24 December 2013 - 06:19 AM

View Postlearningyii, on 18 December 2013 - 09:35 PM, said:

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
0

#93 User is offline   FunnyDj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 17-July 13

Posted 07 January 2014 - 03:40 PM

View Postlearningyii, on 17 December 2013 - 04:15 AM, said:

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


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

Someone could help me exporting in pdf please?
0

#94 User is offline   iredan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 11-September 13

Posted 09 January 2014 - 03:59 AM

View Posttzoll, on 02 May 2013 - 01:41 PM, said:

Hello. Is this possible to export all dbtable columns? Because in my cgridview i'm displaying only 5 columns, but in dbtable i have 10 columns. I export data using this code in my view:
$this->widget('EExcelView', array(
     'dataProvider'=> $dataprovider,
     'title'=>'Title',
     'autoWidth'=>false,
     'columns'=>array(
                'col1',
                'col2',
                'col3',
                'col4',
                'col5',
));



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.
0

#95 User is offline   FunnyDj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 17-July 13

Posted 09 January 2014 - 02:38 PM

View Postiredan, on 09 January 2014 - 03:59 AM, said:

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...
1

#96 User is offline   iredan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 11-September 13

Posted 09 January 2014 - 08:31 PM

@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! :-)
Thanks for your help!
0

#97 User is offline   FunnyDj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 17-July 13

Posted 10 January 2014 - 10:36 AM

View Postiredan, on 09 January 2014 - 08:31 PM, said:

@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?
...

Sorry i forgot it. I used the eexcel behavior (http://www.yiiframew...ension/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',
             ...
            )
       
));

1

#98 User is offline   iredan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 11-September 13

Posted 11 January 2014 - 04:36 AM

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

#99 User is offline   Giris 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 12-November 13

Posted 11 February 2014 - 01:17 AM

View Postlearningyii, on 17 December 2013 - 04:15 AM, said:

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


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

#100 User is offline   turi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 10-December 12

Posted 18 February 2014 - 02:34 AM

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
0

Share this topic:


  • (6 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • 6
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users