View Full Version : Exporting to Excel

20 Jan 2011, 9:13 AM
I need to be able to export grids to excel. I have come up with 4 different ways of achieving this with various effectiency and success.

ActiveX (IE Only)
IQY File (Excel Web Query) Produce HTML table of data from a grid, point the IQY file to that temporary URL and force browser to download IQY file.
CSV File - Write a CSV file based on a grid using Ext + Ajax
XML SpreadSheet - Using Edspencer's Ext.ux.Exporter

I would use the 4th option along with the 1st for IE, but the Excel widely used at my work is 2000 and doesnt seem to work, all i get is this: -


Any other ideas how I can export to excel? Any way I can get the above to work? Any help appreciated!


20 Jan 2011, 10:42 AM
you must have a php or something, on the server side, that provides you data for your actual grid...
for excel export, you can call another php, which, im fact can use the same select that provides your actual grid, BUT:

$whatYouWantBeFileNameToSentBackToClient = 'someFilename.xlsx' ;
header('Content-type: application/vnd.ms-excel.sheet.macroEnabled.12') ;
header('Content-Disposition: attachment; filename='.$whatYouWantBeFileNameToSentBackToClient) ;

Then, you can format all the html you want, even different (bigger or smaller than you client grid, because here you have all the freedom...). And this is browser independent.
May this help ?

20 Jan 2011, 10:56 AM

I approached this by generating the Excel spreadsheets on the server, rather than the client, using the PHPExcel library, which is very flexible at reading and writing a variety of 'real' Excel file formats. I basically send enough details of the grid configuration, including its original data source, as parameters of an XHR call that ultimately returns the file. There's a slightly fuller explanation, and some code, in my response to this thread (http://www.sencha.com/forum/showthread.php?120832-how-to-export-selected-records-to-text-file-in-Extjs-NOT-Excel-format).

Hope it helps