PDA

View Full Version : ExtJS 3.0.0 and Grid Export to Excel



w3bbuilder
16 May 2010, 10:50 AM
Hi,

i have a full functional grid-export-to-excel on ExtJS 2.2, but after i upgraded to 3.0.0 it's not working anymore and i can't find why. Here is my function:


if (!Ext.fly('excel-button')) {
return {
xtype: 'tbbutton',
id: 'excel-button',
text: 'Excel',
iconCls: 'b_excel_cls',
handler: function(){
//create dummy form
if (!Ext.fly('table-export')) {
var frm = document.createElement('form');
frm.id = 'table-export';
frm.name = id;
frm.className = 'x-hidden';
document.body.appendChild(frm);
}
//get attachment
Ext.Ajax.request({
url: myURL,
method : 'POST',
form: Ext.fly('table-export'),
isUpload: true,
callback: function(o, s, r){

},
failure: function(){},
success: function(){},
scope: this,
params: {
table : sTable,
excel : true,
filename : myFILENAME,
start : Ext.getCmp(oGrid).store.lastOptions.params.start,
limit : Ext.getCmp(oGrid).store.lastOptions.params.limit,
sort : Ext.getCmp(oGrid).store.lastOptions.params.sort,
dir : Ext.getCmp(oGrid).store.lastOptions.params.dir,
fields : Ext.getCmp(oGrid).store.baseParams.fields,
query : Ext.getCmp(oGrid).store.baseParams.query
}
});
}
};
}
else {
return Ext.getCmp('excel-button');
}

I assume that the url it's returning the same data, and the browser it's FF. What's wrong with this function??

I can't get the download window anymore...

jay@moduscreate.com
17 May 2010, 8:59 AM
It's hard to tell what you're expecting to happen other than a file download. Are you using a plugin?

CrazyEnigma
17 May 2010, 10:29 AM
How I exported to Excel was pretty simple, although it was a round trip to the server. I sent the parameters back to the server, and it returned a CSV with the mime-type set.

w3bbuilder
18 May 2010, 11:42 AM
Hi,

no, i'm not using a plugin. It's a simple downloading hack using a form submit and a iframe response eval.
Same PHP response headers, just diferent extjs versions.

Here are my response xml headers:



header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/octet-stream");
header('Content-type: application/ms-excel');
header("Content-Disposition:attachment;filename=".$this->input->post('filename').".xls;");



and the response xml:



<?xml version='1.0'?>
<?mso-application progid='Excel.Sheet'?>
<Workbook xmlns='urn:schemas-microsoft-com:office:spreadsheet' xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns:ss='urn:schemas-microsoft-com:office:spreadsheet' xmlns:html='http://www.w3.org/TR/REC-html40'>

<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center"/>
<Borders/>
<Font x:CharSet="238" ss:FontName="Tahoma" x:Family="Swiss"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s28">
<Borders>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
</Style>
<Style ss:ID="s27">
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
<Font ss:Color="#FF0000" ss:Bold="1"/>
<Interior ss:Color="#FFFF00" ss:Pattern="Solid"/>
<NumberFormat ss:Format="Standard"/>
</Style>
</Styles>

<Worksheet ss:Name='exceloutput'>
<Table></Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<Print>
<ValidPrinterInfo/>
<PaperSizeIndex>9</PaperSizeIndex>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>0</VerticalResolution>
</Print>
<Selected/>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet></Workbook>

jay@moduscreate.com
18 May 2010, 11:43 AM
Honestly, I don't see how the change in Ext JS would prevent this from working.

w3bbuilder
18 May 2010, 9:15 PM
Hi,

i think there is a headers mime problem. There are differences between the working version and the non working one.
After some hours of debugging i realized that server side PHP it's returning different headers:


Transfer-encoding: chunked;


The working server side code based on codeigniter 1.6.5 doesn't have that line but 2 lines more(codeigniter 1.7.0), one of them:


Content-Length:1472;


So, no ExtJS problem. But, maybe you know better than me the Headers tricks.

rekhasr
17 Jan 2013, 11:14 PM
Hi,

Can you please post the full ExtJs code of grid-export-to-excel on ExtJS 2.2. Iam using ExtJs 2.2 to export the data grid to Excel, which is not working as expected.
Need your help.

Thanks
Rekha



Hi,

i have a full functional grid-export-to-excel on ExtJS 2.2, but after i upgraded to 3.0.0 it's not working anymore and i can't find why. Here is my function:


if (!Ext.fly('excel-button')) {
return {
xtype: 'tbbutton',
id: 'excel-button',
text: 'Excel',
iconCls: 'b_excel_cls',
handler: function(){
//create dummy form
if (!Ext.fly('table-export')) {
var frm = document.createElement('form');
frm.id = 'table-export';
frm.name = id;
frm.className = 'x-hidden';
document.body.appendChild(frm);
}
//get attachment
Ext.Ajax.request({
url: myURL,
method : 'POST',
form: Ext.fly('table-export'),
isUpload: true,
callback: function(o, s, r){

},
failure: function(){},
success: function(){},
scope: this,
params: {
table : sTable,
excel : true,
filename : myFILENAME,
start : Ext.getCmp(oGrid).store.lastOptions.params.start,
limit : Ext.getCmp(oGrid).store.lastOptions.params.limit,
sort : Ext.getCmp(oGrid).store.lastOptions.params.sort,
dir : Ext.getCmp(oGrid).store.lastOptions.params.dir,
fields : Ext.getCmp(oGrid).store.baseParams.fields,
query : Ext.getCmp(oGrid).store.baseParams.query
}
});
}
};
}
else {
return Ext.getCmp('excel-button');
}

I assume that the url it's returning the same data, and the browser it's FF. What's wrong with this function??

I can't get the download window anymore...