PHP Grid2Excel with user supplied filename

Hi,

Some simple adjustments (should be in standard :wink: ) to have some more control over exports :

generate.php

Insert this :

$excel = new gridExcelGenerator(); //--------------------------------------------------------------------------8<---------cut here // Get URL params if (getURL('creator')) $excel->creator = getURL('creator'); if (getURL('title')) $excel->title = getURL('title'); if (getURL('format')) $excel->outputType = getURL('format'); if (getURL('filename')) $excel->fileName = getURL('filename'); //--------------------------------------------------------------------------8<---------cut here $excel->printGrid($xml);
and add this function :

function getURL($var) { $urlParam = $_REQUEST; $urlParam = array_change_key_case($urlParam,CASE_UPPER); if (array_key_exists(strtoupper($var),$urlParam)) return $urlParam[strtoupper($var)]; return false; }

gridExcelGenerator.php

Add this to the top :

public $fileName = 'grid';
Change this line :

$this->wrapper->outXLS($this->title, $this->outputType); into this :

$this->wrapper->outXLS($this->title, $this->outputType[b], $this->fileName[/b]);
gridExcelWrapper.php

Change this line :

public function outXLS($title, $type = 'Excel2007') { into this :

public function outXLS($title, $type = 'Excel2007'[b], $fileName = 'grid'[/b]) {
Then change the filenames in the headers from this :

filename=grid.xls to this :

filename="'.$fileName.'.xls"
Do the similar things for the other headers.
NOTE ! The csv headers are in double quotes !

Now you can call the generate-script like this (line may wrap !) :
./grid2Excel/generate.php?creator=That would be me&title=My own title&filename=Finally some descriptive name&format=excel2007

Now you can also choose for a csv or excel2003 (.xls) export (which is all there but you can’t set it).
Omitting an option takes the (current) default.

Ofcourse you could liberate more parameters to the outside world but this was what I needed.
Hopefully someone in the DHX team is willing to making this the default way.

rg,rg

Good work!
Thank you, we will add this changes in future export versions.

Hello, have you updated this function of customising grid-export filename in generate.php? if yes, where to find the up-to-date generate.php? thanks.