Export function Exportexcel ()
var config={store:alldatastore, Title: ' Test title '};var tab=tabpanel.getactivetab ();//Panelexportexcel of the current active State (tab, config);//Call the Export function
Exportgridtoexcel.js
var Base64 = {//private property _keystr: "Abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/=", Public method for encoding encode:function (input) {var output = ""; var chr1, CHR2, CHR3, Enc1, Enc2, enc3, Enc4; var i = 0; input = Base64._utf8_encode (input); while (I < input.length) {chr1 = Input.charcodeat (i++); CHR2 = Input.charcodeat (i++); CHR3 = Input.charcodeat (i++); ENC1 = Chr1 >> 2; ENC2 = ((Chr1 & 3) << 4) | (CHR2 >> 4); Enc3 = ((CHR2 &) << 2) | (CHR3 >> 6); Enc4 = CHR3 & 63; if (IsNaN (CHR2)) {enc3 = Enc4 = 64; } else if (IsNaN (CHR3)) {Enc4 = 64; } output = output + This._keystr.charat (ENC1) + This._keystr.charat (ENC2) + this._keystr. CharAt (ENC3) + This._keystr.charat (ENC4); } rEturn output; },//Public method for decoding decode:function (input) {var output = ""; var chr1, CHR2, CHR3; var enc1, Enc2, enc3, Enc4; var i = 0; input = Input.replace (/[^a-za-z0-9\+\/\=]/g, ""); while (I < input.length) {enc1 = This._keystr.indexof (Input.charat (i++)); ENC2 = This._keystr.indexof (Input.charat (i++)); enc3 = This._keystr.indexof (Input.charat (i++)); Enc4 = This._keystr.indexof (Input.charat (i++)); CHR1 = (enc1 << 2) | (Enc2 >> 4); CHR2 = ((Enc2 &) << 4) | (enc3 >> 2); CHR3 = ((enc3 & 3) << 6) | Enc4; Output = output + String.fromCharCode (CHR1); if (enc3! =) {output = output + String.fromCharCode (CHR2); if (enc4! =) {output = output + String.fromCharCode (CHR3); }} output = Base64._utf8_decodE (output); return output; },//Private method for UTF-8 encoding _utf8_encode:function (string) {string = String.Replace (/\r\n/g, "\ n "); var utftext = ""; for (var n = 0; n < string.length; n++) {var c = string.charcodeat (n); if (c < d) {utftext + = String.fromCharCode (c); } else if ((C > 127) && (C < 2048)) {Utftext + = String.fromCharCode ((c >> 6 ) | 192); Utftext + = String.fromCharCode ((C & 63) | 128); } else {utftext + = String.fromCharCode ((c >> 12) | 224); Utftext + = String.fromCharCode (((c >> 6) & 63) | 128); Utftext + = String.fromCharCode ((C & 63) | 128); }} return utftext; },//private method for UTF-8 decoding _utf8_decode:function (utftext) {var string = ""; var i = 0; var c= C1 = C2 = 0; while (I < utftext.length) {c = utftext.charcodeat (i); if (c < +) {string + String.fromCharCode (c); i++; } else if ((C > 191) && (C < 224)) {C2 = utftext.charcodeat (i + 1); string + = String.fromCharCode (((C &) << 6) | (C2 & 63)); i + = 2; } else {c2 = utftext.charcodeat (i + 1); C3 = Utftext.charcodeat (i + 2); string + = String.fromCharCode (((C &) << 12) | ((C2 &) << 6) | (C3 & 63)); i + = 3; }} return string; }}; Ext.override (ext.grid.panel,{getexcelxml:function (includehidden, config) {var worksheet = This.creatework Sheet (Includehidden, config); var totalWidth = This.getcolumnmodel (). Gettotalwidth (Includehidden); var innertitle = '; if (config && config.title) {innertitle = Config.title; } else {innertitle = This.title; } return ' <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:o Ffice:office "> ' + ' <o:DocumentProperties><o:Title> ' + innertitle + ' </o:title></o:docum Entproperties> ' + ' <ss:ExcelWorkbook> ' + ' <ss:WindowHeight> ' + worksheet.height + ' </ss:WindowHeight> ' + ' <ss:WindowWidth> ' + worksheet.width + ' </ss:WindowWidth> ' + ' <ss:ProtectStructure>False</ss:ProtectStructure> ' + ' <ss:protectwindows>false </ss:ProtectWindows> ' + ' </ss:ExcelWorkbook> ' + ' <ss:Styles> ' + ' &L T;ss:style ss:id= "DEfault "> ' + ' <ss:alignment ss:vertical=" Top "ss:wraptext=" 1 "/> ' + ' <SS: Font ss:fontname= "Arial" ss:size= "ten"/> ' + ' <ss:Borders> ' + ' <ss:bo Rder 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"/> ' + ' &L T;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:b old= "1" ss:size= "/>" + ' <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= ' [eng][$-409]dd\-mmm\-yyyy;@ '/> ' + ' <ss:numberform At ss:format= "yyyy\-m\-d@ "/> ' + ' </ss:Style> ' + ' <ss:style ss:parent=" even "ss:id=" evenint "> ' + ' <ss:numberformat ss:format= ' 0 "/> ' + ' </ss:Style> ' + ' <ss:st YLE 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:i d= "Odddate" > ' + ' <ss:numberformat ss:format= "[eng][$-409]dd\-mmm\-yyyy;@"/> ' + ' </ss:Style> ' + ' <ss:style ss:parent= "odd" ss:id= "oddint" > ' + ' <ss:numbe Rformat ss:format= "0"/> ' + ' </ss:Style> ' + ' <ss:style ss:parent= ' odd ' ss:id= ' OD Dfloat ">" + ' <ss:numberformat ss:format= ' 0.00 '/> ' + ' </ss:Style> ' + ' </SS:STYLES&G t; ' + worksheet.xml + ' </ss:Workbook> '; }, Createworksheet:function (Includehidden, config) {//Calculate cell data types and extra class names which a Ffect formatting var celltype = []; var celltypeclass = []; var cm = This.getcolumnmodel (); var totalwidthinpixels = 0; var colxml = '; var headerxml = '; var visiblecolumncountreduction = 0; var innertitle = '; var innerstore = null; if (config && config.title) {innertitle = Config.title; } else {innertitle = This.title; } if (!innertitle | | innertitle = = ") {innertitle = ' Main Title '; } if (config && config.store) {innerstore = Config.store; } else {innerstore = This.store; } for (var i=1;i< this.columns.length;i++) {if (Includehidden | |!this.columns[i].ishidden ()) { Debugger var w = this.columns[i].getwidth (); Totalwidthinpixels + = W; if ((This.columns[i].text = = = "") | | (This.columns[i].getid () = = = "")) {Celltype.push ("None"); Celltypeclass.push (""); ++visiblecolumncountreduction; } else {colxml + = ' <ss:column ss:autofitwidth= "1" ss:width= "' + w + '"/> '; Headerxml + = ' <ss:cell ss:styleid= ' Headercell ' > ' + ' <ss:data ss:type= ' Strin G "> ' + this.columns[i].text + ' </ss:Data> ' + ' <ss:namedcell ss:name=" Print_titles "/> ;</ss:cell> '; var fld = Innerstore.model.prototype.fields.items[i-1].type; Switch (fld.type{case "int": Celltype.push ("number"); Celltypeclass.push ("int"); Break Case "float": Celltype.push ("number"); Celltypeclass.push ("float"); Break Case "BOOL": Case "Boolean": Celltype.push ("String"); Celltypeclass.push (""); Break Case "Date": Celltype.push ("DateTime"); Celltypeclass.push ("date"); Break Default:cellType.push ("String"); Celltypeclass.push (""); Break } } }} var visiblecolumncount = celltype.length-visiblecolumncountreduction; var result = {height:9000, Width:Math.floor (totalwidthinpixels*30) +50}; Generate Worksheet Header details. var t = ' <ss:worksheet ss:name= ' + innertitle + ' "> ' + ' <ss:Names> ' + ' <ss:named Range ss:name= "Print_titles" ss:refersto= "=\" + innertitle + ' \ '! R1:r2 "/> ' + ' </ss:Names> ' + ' <ss:table x:fullrows=" 1 "x:fullcolumns=" 1 "' + ' ss:expandedcolumncount= ' + (visiblecolumncount) + ' "ss:expandedrowcount=" ' + (Innerstore.getcount () + 2) + ' > ' + colxml + ' <ss:row ss:height= ' > ' + ' <ss:cell Ss:styleid= "title" ss:mergeacross= "' + (visibleColumnCount-1) + '" > ' + ' <ss:data xmlns:html= " Http://www.w3.org/TR/REC-html40 "ss:type=" String ">" + '
Extjs:grid data export to an instance of Excel