EasyUI Forum

General Category => General Discussion => Topic started by: vuras on May 07, 2013, 01:42:15 AM



Title: export to excel
Post by: vuras on May 07, 2013, 01:42:15 AM
Hi,  I was wondering about creating a button to export easyui datagrid to excel file. Is there a way?


Title: Re: export to excel
Post by: mzeddd on May 07, 2013, 02:47:04 AM
Hi,

Check this https://github.com/PHPOffice/PHPExcel (https://github.com/PHPOffice/PHPExcel)

It seems very friendly. I use it for couple of years already.

And yes, I have special "Excel" export button on my DataGrid and TreeGrid.


Title: Re: export to excel
Post by: vuras on May 07, 2013, 09:02:23 AM
thanks, for your response and help. Maybe you could put me into right direction by showing one of your examples how to implement this plugin with easyui datagrid?


Title: Re: export to excel
Post by: mzeddd on May 08, 2013, 06:01:03 AM
Lots of PHPExcel example could be found here: https://github.com/PHPOffice/PHPExcel/tree/develop/Examples (https://github.com/PHPOffice/PHPExcel/tree/develop/Examples)

On client side I have the following code:

Code:
function myButtonClick(){
getFile('phpExcelTest.php',$("#myForm").serialize());
}

function getFile(address,parameters){
$.messager.progress({text:'Processing. Please wait...'});
$.post(address,
parameters,
function(data){
$.messager.progress('close');
if(isNaN(data)==false){
javascript:window.location='getFile.php?p='+data;
} else {
$.messager.alert('ERROR',data);
}
}
);
}

In my case PHP script generates/saves file and sends its integer ID back to getFile function.
If I get integet value than it is OK and I could call for already generated file ohtervise show message from PHP script.

If you 100% sure that your Excel file will be generated without any problems you can call for Excel file directly via "javascript:window.location=" for example