PDA

View Full Version : export data to excelfile in store's load event



byp2426091
26 Aug 2012, 6:36 PM
can not show save dialog,but that called on the outside of load has not problem ?

scottmartin
27 Aug 2012, 1:07 PM
Do you want to export from the grid? or load from server?

Please provide more detail.

Scott.

byp2426091
27 Aug 2012, 5:05 PM
grid.store.addListener('load',loadPageDataFunction.createDelegate(grid.store,[includeHidden,cm,dataIndex,cellType,cellTypeClass,fldType,colcount,t,pagebar,pageSize,activePage],true)
.createSequence(function(){
result.xml = t.toString()
+ '</ss:Table>'
+ '<x:WorksheetOptions>'
+ '<x:PageSetup>'
+ '<x:Layout x:CenterHorizontal="1" x:Orientation="Landscape" />'
+ '<x:Footer x:Data="Page &amp;P of &amp;N" x:Margin="0.5" />'
+ '<x:PageMargins x:Top="0.5" x:Right="0.5" x:Left="0.5" x:Bottom="0.8" />'
+ '</x:PageSetup>' + '<x:FitToPage />' + '<x:Print>'
+ '<x:PrintErrors>Blank</x:PrintErrors>'
+ '<x:FitWidth>1</x:FitWidth>'
+ '<x:FitHeight>32767</x:FitHeight>' + '<x:ValidPrinterInfo />'
+ '<x:VerticalResolution>600</x:VerticalResolution>'
+ '</x:Print>' + '<x:Selected />'
+ '<x:DoNotDisplayGridlines />'
+ '<x:ProtectObjects>False</x:ProtectObjects>'
+ '<x:ProtectScenarios>False</x:ProtectScenarios>'
+ '</x:WorksheetOptions>' + '</ss:Worksheet>';
var totalWidth = grid.getColumnModel().getTotalWidth(includeHidden);
data= '<xml version="1.0" encoding="UTF-8">'
+ '<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office">'
+ '<o:DocumentProperties><o:Title>'
+ (title?title:grid.title)
+ '</o:Title></o:DocumentProperties>'
+ '<ss:ExcelWorkbook>'
+ '<ss:WindowHeight>'
+ result.height
+ '</ss:WindowHeight>'
+ '<ss:WindowWidth>'
+ result.width
+ '</ss:WindowWidth>'
+ '<ss:ProtectStructure>False</ss:ProtectStructure>'
+ '<ss:ProtectWindows>False</ss:ProtectWindows>'
+ '</ss:ExcelWorkbook>'
+ '<ss:Styles>'
+ '<ss:Style ss:ID="Default">'
+ '<ss:Alignment ss:Vertical="Top" ss:WrapText="1" />'
+ '<ss:Font ss:FontName="arial" ss:Size="10" />'
+ '<ss:Borders>'
+ '<ss:Border ss:Color="#e4e4e4" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Top" />'
+ '<ss:Border ss:Color="#e4e4e4" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Bottom" />'
+ '<ss:Border ss:Color="#e4e4e4" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Left" />'
+ '<ss:Border ss:Color="#e4e4e4" ss:Weight="1" ss:LineStyle="Continuous" ss:Position="Right" />'
+ '</ss:Borders>'
+ '<ss:Interior />'
+ '<ss:NumberFormat />'
+ '<ss:Protection />'
+ '</ss:Style>'
+ '<ss:Style ss:ID="title">'
+ '<ss:Borders />'
+ '<ss:Font />'
+ '<ss:Alignment ss:WrapText="1" ss:Vertical="Center" ss:Horizontal="Center" />'
+ '<ss:NumberFormat ss:Format="@" />' + '</ss:Style>'
+ '<ss:Style ss:ID="headercell">'
+ '<ss:Font ss:Bold="1" ss:Size="10" />'
+ '<ss:Alignment ss:WrapText="1" ss:Horizontal="Center" />'
+ '<ss:Interior ss:Pattern="Solid" ss:Color="#A3C9F1" />'
+ '</ss:Style>' + '<ss:Style ss:ID="even">'
+ '<ss:Interior ss:Pattern="Solid" ss:Color="#CCFFFF" />'
+ '</ss:Style>'
+ '<ss:Style ss:Parent="even" ss:ID="evendate">'
+ '<ss:NumberFormat ss:Format="yyyy-mm-dd" />' + '</ss:Style>'
+ '<ss:Style ss:Parent="even" ss:ID="evenint">'
+ '<ss:NumberFormat ss:Format="0" />' + '</ss:Style>'
+ '<ss:Style ss:Parent="even" ss:ID="evenfloat">'
+ '<ss:NumberFormat ss:Format="0.00" />' + '</ss:Style>'
+ '<ss:Style ss:ID="odd">'
+ '<ss:Interior ss:Pattern="Solid" ss:Color="#CCCCFF" />'
+ '</ss:Style>' + '<ss:Style ss:Parent="odd" ss:ID="odddate">'
+ '<ss:NumberFormat ss:Format="yyyy-mm-dd" />' + '</ss:Style>'
+ '<ss:Style ss:Parent="odd" ss:ID="oddint">'
+ '<ss:NumberFormat ss:Format="0" />' + '</ss:Style>'
+ '<ss:Style ss:Parent="odd" ss:ID="oddfloat">'
+ '<ss:NumberFormat ss:Format="0.00" />' + '</ss:Style>'
+ '</ss:Styles>' + result.xml + '</ss:Workbook></xml>';

if (!Ext.fly('frmDummy')) {
var frame = document.createElement('iframe');
frame.id='frmDummyExceldatas';
frame.name='frmDummyExceldatas';
frame.className= 'x-hidden';
frame.src=Ext.SSL_SECURE_URL;
document.body.appendChild(frame);

var frm = document.createElement('form');
frm.id = 'frmDummy';
frm.name = 'frmDummy';
frm.action = AppBasepath+'/jsp/public/excel.jsp?filename='+fileName;
frm.method='POST';
frm.encoding = 'multipart/form-data';
frm.enctype = 'multipart/form-data';
frm.target = 'frmDummyExceldatas';
frm.className = 'x-hidden';
frm.timeout=60*30; var inp = document.createElement('input');
inp.type = "hidden";
inp.value = data;
inp.id = "exceldatas";
inp.name = "exceldatas"
frm.appendChild(inp);

document.body.appendChild(frm);
frm.submit();
inp.value = '';
}else{
var inp =document.getElementById("exceldatas");
inp.value=data;
var frmDummy =document.getElementById("frmDummy");
frmDummy.action = AppBasepath+'/jsp/public/excel.jsp?filename='+fileName;
frmDummy.submit();
inp.value = '';
}
},this),this,{single:true});
loadPageDataFunction:this func is used to get xml string
of all datas
os