ExtJS: Export Grid data to an excel instance, extjsgrid
Export function ExportExcel ()
Var config = {store: alldataStore, title: 'test title'}; var tab = tabPanel. getActiveTab (); // The PanelExportExcel (tab, config) of the current active state; // call the export Function
ExportGridToExcel. js
Var Base64 = {// private property _ keyStr: "Callback +/=", // 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 & 15) <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 out Put = ""; 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 & 15) <4) | (Enc3> 2); chr3 = (enc3 & 3) <6) | enc4; output = output + String. fromCharCode (chr1); if (enc3! = 64) {output = output + String. fromCharCode (chr2);} if (enc4! = 64) {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 <128) {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 <128) {string + = String. fromCharCode (c); I ++;} else if (c> 191) & (c <224) {c2 = utftext. charCodeAt (I + 1); string + = String. fromCharCode (c & 31) <6) | (c2 & 63); I + = 2;} else {c2 = utftext. charCodeAt (I + 1); c3 = utftext. charCodeAt (I + 2); string + = String. fromCharCode (c & 15) <12) | (c2 & 63) <6) | (c3 & 63 )); I + = 3 ;}} return string ;}}; Ext. override (Ext. grid. panel, {getExcelXml: function (includeHidden, config) {var worksheet = this. createWorksheet (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: office "> '+' <o: DocumentProperties> <o: title> '+ innertitle +' </o: Title> </o: DocumentProperties> '+' <ss: ExcelWorkbook> '+' <ss: Running wheight> '+ worksheet. height + '</ss: Running wheight>' + '<ss: Running wwidth>' + worksheet. width + '</ss: WindowW Idth> '+' <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> '+' <s S: 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: NumberFormat ss: Format =" yyyy \-m \-d; @ "/> '+' </ss: style> '+' <ss: Style ss: Parent = "even" ss: ID = "evenint"> '+' <ss: NumberFormat ss: format = "0"/> '+' </ss: Style> '+' <ss: Style ss: Pare Nt = "even" ss: ID = "evenfloat"> '+' <ss: NumberFormat ss: Format = "0.00" type = "codeph" text = "codeph"/> '+' </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 = "[ENG] [$-409] dd \-mmm \-yyyy; @ "/> '+' </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> '+ worksheet. xml + '</ss: Workbook>';}, createWorksheet: function (includeHidden, config) {// Calculate cell data types and extra class names which affect formatting var cellType = []; var cellTypeClass = []; // var cm = this. getColumnModel (); var totalWidthInPixel S = 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 = "String"> '+ this. columns [I]. text + '</ss: Data>' + '<ss: NamedCell ss: Name = "Print_Titles"/> </ss: Cell>'; var metadata = innerstore. model. prototype. fields. it [I-1]. type; switch (optional. 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. p Ush (""); 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: NamedRange 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 =" 38 ">' + '<ss: Cell ss: styleID = "title" ss: merge1_ss = "'+ (visibleColumnCount-1) +'"> '+' <ss: Data xmlns: html = "http://www.w3.org/TR/REC-html40" ss: type = "String"> '+'