This is my first extension ever :). It is a wrapper of PHPExcel that extends from CGrivView. The main idea is to easily export already defined grids to excel files. You can use the same array of parameters that the grid uses plus an aditional specific params, which are:
Configuraiton ¶
Document properties
- creator - The creator of the document
- title - Title of the excel document
- subject, description, category
Other params
- libPath - path to PHPExcel, defaults to 'ext.phpexcel.Classes.PHPExcel'
- autoWidth - whether to auto extend cells for the content(default true)
- exportType - the type of the export, all possible types of PHPExcel lib(Excel5, Excel2007,PDF, HTML)
- disablePaging - if set to true, it will export all data (default true)
- filename - the full path of the filename to export to. If null it will stream to the browser
- stream - true/false stream to browser or save to file.
- grid_mode - Whether to display grid or to export it to selected format. Possible values(grid, export)
- grid_mode_var - defaults to 'grid_mode' GET var for the grid mode
Requirements ¶
Yii 1.1 or above and PHPExcel library
Usage ¶
The usage is like using CGridView:
$this->widget('EExcelView', array(
'dataProvider'=> $dataprovider,
'title'=>'Title',
'autoWidth'=>false,
..... other options
));
Note ¶
The path of the PHPExcel library is hardcoded to: application.extensions.phpexcel.Classes.PHPExcel
Asuming that you have extracted the lib under extensions folder. I will change that later.
ver 0.32 ¶
- Fixed the CButtonColumn bug "Property "CButtonColumn"."name" is not defined"...
- Fixed the issues with multiple level of buffering(le top)
- Fixed export buttons column bug(le top)
- Added documetation of all properties in the extension page.
ver 0.31 ¶
Mainly bug fix release. I also modified the extension to be able to run in console mode(although its a widget). I realy needed something to send me reports in xls. Here is the code snippet:
$factory = new CWidgetFactory();
$widget = $factory->createWidget($this, 'EExcelView', array(
'dataProvider'=>$provider,
'grid_mode'=>'export',
'title'=>'Title',
'filename'=>'report.xlsx',
'stream'=>false,
'exportType'=>'Excel2007',
'columns'=>array(
'col1',
'col2',
),
));
$widget->init();
$widget->run();
ver 0.3 ¶
Major change EExceView now can fully replace CGridView. There is an optional parameter 'gridmode'(default "grid") and when not set it acts just like normal grid. If gridmode="export" it exports the grid in the selected "exportType"(default "Excel5"). The path to PHPExcel can now be customized via "libPath" variable. If the lib is not found a warning is generated and export is disabled.
- Added: "gridmode" possible values(grid, export). When set to grid acts like normal grid.
- Added: "libPath" property, defaults to "application.extensions.phpexcel.Classes.PHPExcel". The location of PHP Excel lib.
- Added: "grid_mode_var" the GET variable name which can be used to change the grid mode. defaults to "grid_mode"
- Added: new template item "exportbuttons" which renders export links. Example: .... 'template'=>"{summary}\n{items}\n{exportbuttons}\n{pager}" ....
- Added: config for export buttons. "exportButtonsCSS"(default="summary") css class for the div which wraps the buttons. "exportButtons" - array of exportTypes, for each item it renders link which exports the grid. If you specify an array you can customize the caption of the link. All export type have default captions. Example: array('Excel5'=>array('caption'=>'*.xls'), PDF). Property exportText which defines the text before the links, deault = "Export to: ".
- Added: renders CLinkColumns. Just the text of the links.
- Added: support for footer, just like normal footer.
- Added: callback functions called after processing of the cell.$cell is the php excel cell object. Refer to php excel documentation for help. $data is the same var the grids uses for expressions. $value is the text the extension had put in the cell :
- onRenderHeaderCell(PHPExcel_Cell $cell, string $value)
- onRenderDataCell(PHPExcel_Cell $cell, $data, string $value)
- onRenderFooterCell(PHPExcel_Cell $cell, string $value)
Thanks to all who have written me with ideas how to extend this extension. Sorry by I've been realy busy lately so I didnt have time to bring this earlier. I have tested the extension but if you find any bug or something you'd like me to add, feel free to write. Happy yiister :)
ver 0.2 ¶
- Fixed: Error when saving to filename.
- Fixed: bug in column indexing when > 26
- Added: support for CSV
- Added: new param "stream"(default true) when set to true streams to browser else save to local filename
- Added: get real column headers
- Added: get title from page title when not specified
forum topic
forum topic for this ext:
Your text to link here...
Changes
I've made a couple changes, adding CSV support and sending the title, if set, or the pageTitle as the filename, also fixing the bug I just mentioned in the last comment
If you are interest, create some post in the forum for your extension, as some1 already mentioned
Cheers
Gustavo
Excellent extension
Most useful I found so far.
Thanks.
I changed a couple of things for putting labeled attributes as headers instead of database fields. (taking advantage of the attributeLabels() function that is in every single model generated by yii). Also, I'm passing parameters for telling the actionExcel (in my case) in the controller, which attributes must be ignored. Finally, I'm checking if exists a function (getAttributeName()) in the model for retrieving human readable values instead of codes. This might be useful if you want to print the correspondent values of foreign keys in your current model.
I'll explain it in more detail in the forum :)
more changes for relationships
Hello
I made a new modification
incorporate relationships
the code is adapted from code zii
hopefully useful
see changes
v 0.2 beta
Just posted a new version of the extension. I've used almost all of the recommendations you made and a couple of things from me. Please comment.
v 2.0
Thanks for the effort and to add a couple of suggestion I've made
Will try it as soon as I need again
Gustavo
Cell type
Thank you for your efforts developing such a nice extension.
But I have a problem.
I have column which holds a text consisting of a series of numbers so it will be automatically formatted as numerical value, i.e. 12.333E+12. Is there any way to prevent this?
Thanks
Documentation?
Please add installation documentation too.
Thanks.
Simple fix for rendering the footer of the gridview
Hello i modified the code a little bit to add renderFooter functionality
paste.org/pastebin/view/40197
Added footer and relationships to eexcelview
Hi i modified eexcelview to support footer and db relationships
http://francisja.tumblr.com/post/18486330299/extended-eexcelview-with-relational-database-and-footer
Improved performance and fixed minor bugs
Hi phreak, I uploaded some modifications to the code improved by francies, please take a look.
Forum link
Thanks!
Config
Thanks for this extension, it looks like just what I needed, but where do I store EExcelView.php?
I have extracted PHPExcel at extensions/phpexcel/
Thanks.
@glicious
You may put it anywhere as long as it has path to it :) or you use path alias when creating the widget.
PP: I have removed the download of the extension since I found a minor bug :) I'll get it back online tomorrow.
It's more then tomorrow
It's more then tomorrow already. Have you forgot about us? :)
Also, why do you user GPL license? Why not MIT or at least LGPL?
here you are
here is the extension, I just needed this to be able to run in console so I delayed it :)
@undsoft well I can change the licence if that will make you happy. I dont realy care, I give it for free to the Yii comunity and want nothing in return. I'll be happy if it helps you and makes you life easier.
license
I modified the license to MIT. Have a nice day :)
Thanks
Thanks,
Now I can use it in commercial projects in my work.
suggestion
I needed to add an option to format the value of a cell. This option is useful for text that contains a value, but must remain a digital text format in the Excel file. Here's how I modified the method 'renderRow ()': start at row 147 in the file
if($column instanceof CLinkColumn) { if($column->labelExpression!==null) $value=$column->evaluateExpression($column->labelExpression,array('data'=>$data[$row],'row'=>$row)); else $value=$column->label; } elseif($column->value!==null) $value=$this->evaluateExpression($column->value ,array('data'=>$data[$row])); elseif($column->name!==null) { $value=$data[$row][$column->name]; if ($column->type!='text') { $value=$value===null ? "" : $column->grid->getFormatter()->format($value,'raw'); } else { $value = $value===null ? "" : $column->grid->getFormatter()->format($value,'text'); } } $a++; if ($column->type=='text') { $cell = $this->objPHPExcel->getActiveSheet()->getCell($this->columnName($a).($row+2))->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING); } else { $cell = $this->objPHPExcel->getActiveSheet()->setCellValue($this->columnName($a).($row+2) , strip_tags($value), true); }
Now i can use the property 'type' description column :
... array( 'name'=>'columnName', 'value'=>$data=>columnValue, 'type'=>'text', )...
so that the value '09548 'is correctly written in the cell
another way
thnx valery.merlet . I was thinking about adding some types of columns handling to the extension but I thought that it would be more easy to create callback functions so that you can do whatever custom modification to the the cell you want. So in your case you could just use onRenderDataCell(PHPExcel_Cell $cell, $data, string $value) and then
Anyway I may add your modification in the next release :) 10x for using EExcelView.
MIT License
Hi
Thanks for the extension (I haven't tried it yet).
The web page says 'MIT' license, but the file still says 'GPL'.
Kind regards
MIT License
Well it was GPL first, then I updated the site with MIT but have forgotten to update the file. Feel free to use it under MIT license I will udate it .
Some issues / no fixes yet
Hi
I am now testing the extension ;-).
Making it work for all users still requires some work ;-=.
Some reports on issues (maybe fixes later):
I changed that to
$content[] = CHtml::link($item['caption'], Yii::app()->controller->createUrl('',array_merge($_GET,array('exportType'=>$type,$this->grid_mode_var=>'export'))));
But even then, the 'grid-id' information is missing from the link to make sure that the link is only applied to 1 grid on the page;
When exporting, any output "rendered" before getting to the grid rendering, and after the grid rendering, is also rendered. This invalidates the file format.
It may be possible to clear the output buffer before the grid, and surely avoid the rendering after.
My 'buttons column' makes the 'export' fail. The error is '"CButtonColumn.value"' is not defined. The definition for this column looks like this:
array( 'template' =>'{update}', 'header'=>Yii::t('app','header.configure'), 'buttons'=>array( 'update'=>array( 'click'=>'js:function(){updateAlert(jQuery(this).parents(".grid-view").first().attr("id"));return true;}', //'imageUrl'=>'', 'label'=>Yii::t('app','header.configure'), ), ), )
ob_end_clean
The extra output was due to my setup having multiple levels of views embedded in each other.
By adding:
private static function cleanOutput() { for($level=ob_get_level();$level>0;--$level) { @ob_end_clean(); } }
gleaned from the ErrorHandler and calling 'cleanOutput' in stead of 'ob_end_clean' inside 'run', document creation works better.
Bug in export buttons rendering
Hi
Great work !!!! Many improvements from the version i was using.
I found two little bugs in renderExportButtons()
Change it from:
$content[] = CHtml::link($item['caption'], '?'.$url['query'].'exportType='.$type.'&'.$this->grid_mode_var.'=export');
To:
if (key_exists('query', $url)) $content[] = CHtml::link($item['caption'], '?'.$url['query'].'&exportType='.$type.'&'.$this->grid_mode_var.'=export'); else $content[] = CHtml::link($item['caption'], '?exportType='.$type.'&'.$this->grid_mode_var.'=export');
See the & before exportType ?
That was the problem. The URL is not well formed and the exportType is never used
The other change is because when the uri does not contain the query part it throws an error
Undefined index: query
PS: Could you please document the options in the extension page ? Thanks!!
doesn't work for me
Installed out of the box says: "Property "CButtonColumn"."name" is not defined"...
v 0.32
Just uploaded new ver with bugfixes. Also added some documentation to the extension page.
Bug
Found a bug in renderExportButtons() - Line 252
need to move the following out of the foreach:
if($content) echo CHtml::tag('div', array('class'=>$this->exportButtonsCSS), $this->exportText.implode(', ',$content));
As if you set multiple exports options in exportButtons array it'll render the button row for each entry.
10x Jaggi
Fixed and uploaded new ver 0.33
Great extension
Does what it says, perfect: it was all set up in minutes!
Thanks and keep up the good job.
Document properties encoding (Creator / Subject / Description)
If you notice strange characters instead of accented ones in those fields (in the generated document's properties), you'll most likely have to encode those strings into ISO-8859-1.
$locale = 'fr_FR'; date_default_timezone_set('UTC'); setlocale(LC_ALL, $locale); $this->widget('EExcelView', array( 'id' => 'some-grid', 'dataProvider' => $model->search(), 'grid_mode' => 'export', 'title' => 'Some report - ' . date('d-m-Y - H-i-s'), 'creator' => 'John Doe', 'subject' => mb_convert_encoding('Etat en français généré le ' . utf8_encode(strftime('%e %B %Y')), 'ISO-8859-1', 'UTF-8'), 'description' => mb_convert_encoding('Description en français avec des caractères accentués pour montrer que c\'est possible :-)', 'ISO-8859-1', 'UTF-8'),
Does anyone know how to deal with non-Latin languages?
PS I'm not talking about sheet contents, they're alright in UTF-8.
Minor additions to EExcelView
These are certainly not essential, but if someone needs to name the worksheet, or else:
--- EExcelView (v0.33) +++ EExcelView (v0.33 abennouna) @@ -14,6 +14,10 @@ public $subject = 'Subject'; public $description = ''; public $category = ''; + // abennouna + public $lastModifiedBy = ''; + public $keywords = ''; + public $sheetTitle = ''; //the PHPExcel object public $objPHPExcel = null; @@ -96,6 +100,9 @@ $this->objPHPExcel->getProperties()->setSubject($this->subject); $this->objPHPExcel->getProperties()->setDescription($this->description); $this->objPHPExcel->getProperties()->setCategory($this->category); + // abennouna + $this->objPHPExcel->getProperties()->setLastModifiedBy($this->lastModifiedBy); + $this->objPHPExcel->getProperties()->setKeywords($this->keywords); } else parent::init(); } @@ -198,6 +205,8 @@ if($this->autoWidth) foreach($this->columns as $n=>$column) $this->objPHPExcel->getActiveSheet()->getColumnDimension($this->columnName($n+1))->setAutoSize(true); + // abennouna + $this->objPHPExcel->getActiveSheet()->setTitle($this->sheetTitle); //create writer for saving $objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, $this->exportType); if(!$this->stream)
github
EExcelView is on github - https://github.com/phreakbg/EExcelView
encoding problem
Hi, I have a problem with the encoding or charset.
The browser let me download the file, but when I try to open with excel, it says that the format is incorrecte.
I assume is an encoding problem.
I can use prefectly the same program in another infrastructure ( linux).
My test is in windows xp, Spanish languaje.
Can anybodiy give a clue ?
I have some php files saved as ANSI and other as UTF-8. My /layouts/main.php file is saved as UTF-8 and in charset META field is charset= utf-8.
The browser detect UTF-8 ....
I'm lost ..
Best Regards
encoding problem
Well almost all of my reports are in cyrillic characters so I dont think there's problem with encoding. You said that there are files in ANSI, all your files should be in utf8. Could you convert everythink in utf8 an try again ?
encoding problem
Thanks for the tip phreak .
I'll try it.
I suposse that the rule is:
any other ??
Modification
Hi
Please check https://www.dropbox.com/s/afxbl8t0z1i5op0/EExcelView.zip .
Following your update I noticed that my version has some extra stuff (for extra configuration, translation, ...).
You'll have to change 'MyCGridView' in 'CGridView'.
Thank You
thank you for this very nice extension.
no problem with the hardcoded path for phpexcel
can't open excel file after downloaded.
When i downloaded excel file. i can't open it. Excel noticed that: "Excel cannot open the file ... because the file format or file extension is not valid. ...". What's wrong?
Any plans for compressing the output?
It will be a nice idea it can zip compress the output, what do you think? Will work with that.
Thanks!
zip
I'm not 100% sure, but thinnk that Excel2007 format is already zipped.
Actually it is
But for the other formats, like xls.
export button?
hi,,,
how to use export button?
when i use this extension, they will download the file directly when i reload the page..
there is no export button, they auto-download
Alternating row colors
I made an update to allow changing the background color on the rows.
Added towards the end of renderRow()
$cell = $this->objPHPExcel->getActiveSheet()->setCellValue($this->columnName($a).($row+2) , strip_tags($value), true); $worksheet = $this->objPHPExcel->getActiveSheet(); $highest_column = $worksheet->getHighestColumn(); $cell_row = $cell->getRow(); $cell_column = $cell->getColumn(); if(is_float($row/2)) { $color = $this->row_color; } else { $color = $this->row_alternate_color; } $worksheet->getStyle('A' . $cell_row . ':' . $highest_column . $cell_row)->applyFromArray(array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => $color) ) ) );
@albertski
Could you offer those changes on Github? Would make it far easier for us to upgrade our version of the extension long-term :-)
Alternating row colors Github
https://github.com/ajankowski/EExcelView
how to export row count/number
hi @albertski, how to export row count/number? i used ++$row like cgridview, but it said "Undefined variable: row"
Perhaps the best way is to do it outside of this class
@semprul Not sure what you are trying to do but perhaps its better you should handle that outside of the excel class.
Not sure if this is good but someone posted this:
$yourprovider->getItemCount() $yourprovider->getTotalItemCount(); //(idepended of pagination) or you can get it by count($yourprovider->->getData())
@albertski
this is what i mean:
i want to add collumn that contain row number.
the ++$row not working as the cgridview does...
'columns'=>array( array( 'header'=>'No.', 'value'=>'++$row', ////// ---> this not work ), 'nup', array( 'header'=>'Name', 'value'=>'$data->nup->name', ), 'time1', 'time2',
@semprul
Just tried this and it worked:
array( 'header'=>'Number', 'value'=>'$row+1', );
I am using a DataProvider and it seems like you are not. I think you will need to use a DataProvider or if you are look if there is an issue there.
@albertski
i used CAvtiveDataProvider as data provider..
I can get the downloaded file in Excel
I use the following action in my controller
public function actionExcel() { $model = new News('search'); $factory = new CWidgetFactory(); $widget = $factory->createWidget($this, 'EExcelView', array( 'dataProvider' => $model->search(), 'grid_mode' => 'export', 'title' => 'Title', 'filename' => 'report.xlsx', 'stream' => false, 'exportType' => 'Excel2007', 'columns' => array( 'pkreportid', 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', */ array( 'class' => 'bootstrap.widgets.TbButtonColumn', ), ), )); $widget->init(); $widget->run(); exit; }
I got the blank html page, i want to get Excel sheet, please help
try this
Amjad Khan try to set grid_mode to 'grid' and see if the grid is rendered normally. Do you have any errors in the log.
Port to Yii2
Hi
I recently published a port of your extension to Yii2
Hope you have the time to test it and give some feedback
setting TCPDF
Hi
In order to export to PDF, you must configure the path to tcpdf. To do this you must change ext.PHPExcel/Classes/PHPExcel/Settings.php adding
/ ** PATH_TCPDF root directory. ext.tcpdf * / if (! defined ('PATH_TCPDF')) { / ** *ignore * / define ('PATH_TCPDF', dirname (__ FILE__) '/../../../tcpdf'.); }
and setting
private static $_pdfRendererName = self::PDF_RENDERER_TCPDF; private static $_pdfRendererPath = PATH_TCPDF;
Problem there is a space after row export
After I export from database to excel there is an empty field row after row that field with data.. For example I have 1000 data and I export to excel, at row 1001 there is empty field but it fill with something null..
So when I want the excel file to import again to database, there is an empty input after 1000 data imported, it is like row 1001 but it is null or ""
How to clear that??
thnks for help
Export Large Dataset
Hi,
I have a problem exporting large dataset, 20000 plus rows with 36 columns. It does work with few thousands of rows but goes blank with larger dataset.
There is no specific error that the plugin produces or any errors in the application log.
Did you guy ever experienced this problem with the plugin?
Thanks!
large dataset problem
@hendrey this is most probably due to high memory usage. Try to increase the memory with memory_limit e.g. ini_set('memory_limit', '1G') and try again. The version of PHPExcel this extension uses is really using a lot of memory.
Multiple export button on same page
I have multiple grid and each has separate export buttons but when I click on export button of any grid it always exports the data of the grid which comes first in the view.. Can anyone help me solve this problem..
Caching
I've tried to activate PHPExcel framework cache by inserting this code in "EExcelView.php":
public function init() { ... Yii::import($this->libPath, true); // CACHING $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp; $cacheSettings = array('memoryCacheSize' => '32MB'); if (!PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings)) { die($cacheMethod . " caching method is not available" . EOL); } // CACHING END $this->objPHPExcel = new PHPExcel(); ... }
But it doesn't work. After a day of debug, I found out that by calling "$this->dataProvider->getData()" anywhere in the script, the caching framework stops working.
$this->dataProvider->getData() is called in two required methods renderRow() and renderBody()
Anyone has found a solution?
Thanks in advance!
row
how to create custom row ? or create specific row
Problem with datetime field
When I export the data you change the format datetime fields. The result of a date is as follows: 13 05: 20: 7/4/2015 and right must be 04/13/2015 5:20:07.
As resulevo this ??
datetime field
Hi
I specify a datetime field like this and the export is fine in my case:
array( 'name' => 'posCreditValidDate', 'type' => 'datetime' )
datetime field
when use
array( 'name' => 'posCreditValidDate', 'type' => 'datetime' )
The result is this in all records :(
01 Jan, 1970 01:01:00 am
Datetime (2)
Did you replace 'posCreditValidDate' by the actual name of your field?
datetime field
Yes
array( 'name' => 'fecha', 'type' => 'datetime' ),
instead of dataprovider can we pass array or model->findAll data?
can we pass array data OR model->findAll() data as dataprovider instead of data provider.
please advice,
Array / Dataprovider
You can use 'CArrayDataProvider' to adapt the array to the required interface.
Upgrading to PHP 7.0
Upgrading to PHP 7.0 broke this extension from working on my server. Here the steps I followed to fix it up. This is not very clean but at least could work.
I installed via composer the new PhpSpreadSheet which replace PHPExcel
Don't forget after installing PHP7.0 the requested extensions
# If not already do, install the required extensions sudo apt-get install php7.0-zip sudo apt-get install php7.0-xml sudo apt-get install php7.0-gd # Install Spreadsheet in the vendor directory (default) cd protected/extensions composer require phpoffice/phpspreadsheet
Update the EExcelView.php code :
// Just after the top opening php tag use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; ... // The PHPExcel object become public $spreadsheet = null; // Update the mime type public $exportType = 'Xls'; ... public $mimeTypes = array( 'Xls' => array( 'Content-type'=>'application/vnd.ms-excel', 'extension'=>'xls', 'caption'=>'Excel(*.xls)', ), 'Xlsx' => array( 'Content-type'=>'application/vnd.ms-excel', 'extension'=>'xlsx', 'caption'=>'Excel(*.xlsx)', ), 'Pdf' =>array( 'Content-type'=>'application/pdf', 'extension'=>'pdf', 'caption'=>'PDF(*.pdf)', ), 'Html' =>array( 'Content-type'=>'text/html', 'extension'=>'html', 'caption'=>'HTML(*.html)', ), 'Csv' =>array( 'Content-type'=>'application/csv', 'extension'=>'csv', 'caption'=>'CSV(*.csv)', ) ); ... // In the init function remove the lib test (I was lazy to replace it ^-^) // $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'); // } // Replace the lib loading if($this->grid_mode == 'export') { require_once __DIR__ . '/../extensions/vendor/autoload.php'; // Create new Spreadsheet object $this->spreadsheet = new Spreadsheet(); $this->title = $this->title ? $this->title :Yii::app()->getController()->getPageTitle(); $this->initColumns(); // And remove the old loading // spl_autoload_unregister(array('YiiBase','autoload')); // Yii::import($this->libPath, true); // $this->spreadsheet = new PHPExcel(); // spl_autoload_register(array('YiiBase','autoload'));
Replace all the $this->objPHPExcel by $this->spreadsheet
and in the run() function
// Replace in run() function according to name space ... // $objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, $this->exportType); $objWriter = IOFactory::createWriter($this->spreadsheet, $this->exportType); ...
In the widget do not forget to replace the mime type option if you do not use default one.
'exportType'=>'Xls',
hello
thank you so much for this helpful extension
but i have some problem when i have many grideview in the same page
and i want to exporst specific table data when click on export always export the data in the first grideview
i'm try to add EExelview file for each grideview but not work
please any help ?
You can create your own export buttons under every grid and then in the backend you need to specify grid_mode = export in the widget :
$this->widget('EExcelView', array(
'dataProvider'=> $dataprovider, .... 'grid_mode' => 'export'
));
this will trigger export instead of rendering the grid
You have to make "grid_mode_var" unique for every grid and make sure that it keeps the same value - avoid the automatic generated ids.
My EExcelView says:
`
phpif(!isset($this->grid_mode_var)) { $this->grid_mode_var=$this->id; } if(isset($_GET[$this->grid_mode_var])) $this->grid_mode = $_GET[$this->grid_mode_var]; if(isset($_GET['exportType'])) $this->exportType = $_GET['exportType'];
So by default "grid_mode_var" gets the grid's id as value. So if your id is unique and stable for each grid on and not generated automatically, you should get a long way.
The solution of @le_top is even better than mine, you'd better use his answer :)
fix for PHP 8.1 compatibility
@@ -460 +460,2 @@ class EExcelView extends CGridView
@jeremy I am curious when this is an issue because when the parameter is an integer or string representing an integer, the result also is:
.../php8.2.0/php -r "print gettype('28'/2);print gettype(28/2);" yields 'integerinteger'
/** * Returns the corresponding excel column.(Abdul Rehman from yii forum) * * @param int $index * @return string */ public function columnName($index) { --$index; if($index >= 0 && $index < 26) return chr(ord('A') + $index); else if ($index > 25) return ($this->columnName($index / 26)).($this->columnName($index%26 + 1)); else throw new Exception("Invalid Column # ".($index + 1)); } ```
You can find my version https://github.com/mdeweerd/EExcelView .
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.