From a46a2ddaaa6afc1c5a9d691ed773760bbc5fb0a9 Mon Sep 17 00:00:00 2001 From: Travis Clarke Date: Tue, 18 Dec 2018 21:23:57 -0800 Subject: [PATCH] support for customizing worksheet name, #163 --- dist/js/tableexport.js | 33 +++++++++++++++----------------- dist/js/tableexport.min.js | 2 +- src/stable/js/tableexport.js | 33 +++++++++++++++----------------- src/stable/js/tableexport.min.js | 2 +- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index 449a65b..fdc7eab 100644 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -81,14 +81,8 @@ context.rows = settings.headers ? _nodesArray(el.querySelectorAll("thead > tr")).concat(context.rows) : context.rows; context.rows = settings.footers ? context.rows.concat(_nodesArray(el.querySelectorAll("tfoot > tr"))) : context.rows; context.thAdj = settings.headers ? el.querySelectorAll("thead > tr").length : 0; - context.filename = - settings.filename === "id" - ? el.getAttribute("id") - ? el.getAttribute("id") - : self.defaultFilename - : settings.filename - ? settings.filename - : self.defaultFilename; + context.filename = settings.filename === "id" ? el.getAttribute("id") || self.defaultFilename : settings.filename || self.defaultFilename; + context.sheetname = settings.sheetname === "id" ? el.getAttribute("id") || self.defaultFilename : settings.sheetname || self.defaultFilename; context.uuid = _uuid(el); /** @@ -164,7 +158,8 @@ ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file(s) (default: null) ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file(s) (default: null) trimWhitespace: true, // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s) (default: false) - RTL: false // (Boolean), set direction of the worksheet to right-to-left (default: false) + RTL: false, // (Boolean), set direction of the worksheet to right-to-left (default: false) + sheetname: "id" // (id, String), sheet name for the exported spreadsheet, (default: 'id') }, /** * Constants @@ -398,7 +393,8 @@ mimeType: format.mimeType, fileExtension: format.fileExtension, merges: rcMap.merges, - RTL: settings.RTL + RTL: settings.RTL, + sheetname: settings.sheetname }); var hashKey = _hashCode({ uuid: context.uuid, type: key }); @@ -542,8 +538,9 @@ mimeType = object.mimeType, fileExtension = object.fileExtension, merges = object.merges, - RTL = object.RTL; - this.export2file(data, mimeType, filename, fileExtension, merges, RTL); + RTL = object.RTL, + sheetname = object.sheetname; + this.export2file(data, mimeType, filename, fileExtension, merges, RTL, sheetname); }, /** * Excel Workbook constructor @@ -577,9 +574,9 @@ * @param merges {Object[]} * @param RTL {Boolean} */ - export2file: function(data, mime, name, extension, merges, RTL) { + export2file: function(data, mime, name, extension, merges, RTL, sheetname) { var format = extension.slice(1); - data = this.getRawData(data, extension, name, merges, RTL); + data = this.getRawData(data, extension, name, merges, RTL, sheetname); if (_isMobile && (format === _FORMAT.CSV || format === _FORMAT.TXT)) { var dataURI = "data:" + mime + ";" + this.charset + "," + data; @@ -605,7 +602,7 @@ return key; } }, - getRawData: function(data, extension, name, merges, RTL) { + getRawData: function(data, extension, name, merges, RTL, sheetname) { var key = extension.substring(1); if (_isEnhanced(key)) { @@ -613,9 +610,9 @@ ws = this.createSheet(data, merges), bookType = this.getBookType(key); - name = name || ""; - wb.SheetNames.push(name); - wb.Sheets[name] = ws; + sheetname = sheetname || ""; + wb.SheetNames.push(sheetname); + wb.Sheets[sheetname] = ws; wb.Workbook.Views[0] = { RTL: RTL }; var wopts = { bookType: bookType, diff --git a/dist/js/tableexport.min.js b/dist/js/tableexport.min.js index 6157546..a7a0015 100644 --- a/dist/js/tableexport.min.js +++ b/dist/js/tableexport.min.js @@ -16,4 +16,4 @@ * limitations under the License. * */ -!function(t,r){if("function"==typeof define&&define.amd)define(function(t){var e;try{e=t("jquery")}catch(t){}return r(e,t("blobjs"),t("file-saverjs"),t("xlsx"))});else if("object"==typeof exports&&"string"!=typeof exports.nodeName){var e;try{e=require("jquery")}catch(t){}module.exports=r(e,require("blobjs"),require("file-saverjs"),require("xlsx"))}else t.TableExport=r(t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this,function(e,l,p,u){"use strict";var o=function(t,e){var a=this;if(!t)return S('"selectors" is required. \nUsage: TableExport(selectors, options)');if(!a)return new o(t,e);a.settings=C({},a.defaults,e),a.selectors=w(t);var i=a.settings;i.ignoreRows=i.ignoreRows instanceof Array?i.ignoreRows:[i.ignoreRows],i.ignoreCols=i.ignoreCols instanceof Array?i.ignoreCols:[i.ignoreCols],i.ignoreCSS=a.ignoreCSS instanceof Array?a.ignoreCSS:[a.ignoreCSS],i.emptyCSS=a.emptyCSS instanceof Array?a.emptyCSS:[a.emptyCSS],i.formatValue=a.formatValue.bind(this,i.trimWhitespace),i.bootstrapSettings=function(t,e,r){var o={};o.bootstrapSpacing=t?(o.bootstrapClass=e[0]+" ",o.bootstrapTheme=e[1]+" ",e[2]+" "):(o.bootstrapClass=r+" ",o.bootstrapTheme="","");return o}(i.bootstrap,a.bootstrapConfig,a.defaultButton);var s={};a.getExportData=function(){return s},a.selectors.forEach(function(r){var o={};o.rows=w(r.querySelectorAll("tbody > tr")),o.rows=i.headers?w(r.querySelectorAll("thead > tr")).concat(o.rows):o.rows,o.rows=i.footers?o.rows.concat(w(r.querySelectorAll("tfoot > tr"))):o.rows,o.thAdj=i.headers?r.querySelectorAll("thead > tr").length:0,o.filename="id"===i.filename?r.getAttribute("id")?r.getAttribute("id"):a.defaultFilename:i.filename?i.filename:a.defaultFilename,o.uuid=v(r),o.checkCaption=function(t){var e=r.querySelectorAll("caption."+a.defaultCaptionClass);e.length?e[0].appendChild(t):((e=document.createElement("caption")).className=i.bootstrapSettings.bootstrapSpacing+a.defaultCaptionClass,e.style.cssText="caption-side: "+i.position,e.appendChild(t),r.insertBefore(e,r.firstChild))},o.setExportData=function(t){var e=c.getInstance().getItem(t),r=t.substring(t.indexOf("-")+1);s[o.uuid]=s[o.uuid]||{},s[o.uuid][r]=JSON.parse(e)},o.rcMap=(new f).build(o,i);var n=g.reduce(function(t,e){return t[e]=0,t},{});i.formats.forEach(function(t){return e=t,~g.indexOf(e)?function(t){var e;switch(t){case m.TXT:case m.CSV:case m.XLS:e=!0;break;default:e=h(t)}return e}(t)?void(n[t]||(o.setExportData(a.exporters.build.call(a,o,t)),n[t]++)):S('"'+t+'" requires "js-xlsx".'):S('"'+t+'" is not a valid format. \nFormats: '+g.join(", "));var e})});var r=document.querySelectorAll("button["+a.storageKey+"]");return n(r,"click",a.downloadHandler,a),a};o.prototype={version:"5.1.0",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0,RTL:!1},CONSTANTS:{FORMAT:{XLSX:"xlsx",XLSM:"xlsm",XLSB:"xlsb",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",defaultCaptionClass:"tableexport-caption",defaultNamespace:"tableexport-",tableKey:"tableexport-key",storageKey:"tableexport-id",ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",bootstrapConfig:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xlsm:{defaultClass:"xlsm",buttonContent:"Export to xlsm",mimeType:"application/vnd.ms-excel.sheet.macroEnabled.main+xml",fileExtension:".xlsm"},xlsb:{defaultClass:"xlsb",buttonContent:"Export to xlsb",mimeType:"application/vnd.ms-excel.sheet.binary.macroEnabled.main",fileExtension:".xlsb"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls",enforceStrictRFC4180:!1},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv",enforceStrictRFC4180:!0},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt",enforceStrictRFC4180:!0}},typeConfig:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},boolean:{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{build:function(t,n){var a=this,i=a.settings,e=a.formatConfig[n],s=e.separator,l=t.rcMap,r=w(t.rows).map(function(t,o){return l.isIgnore(o)?l.handleRowColMapProp(l.TYPE.IGNORE):l.isEmpty(o)?l.handleRowColMapProp(l.TYPE.EMPTY):w(t.querySelectorAll("th, td")).map(function(t,e){var r=function(t){if(h(n))return{v:i.formatValue(t.textContent),t:a.getType(t.className)};switch(n){case m.CSV:return'"'+i.formatValue(t.textContent.replace(/"/g,'""'))+'"';default:return i.formatValue(t.textContent)}}(t);return l.isIgnore(o,e)?l.handleRowColMapProp(l.TYPE.IGNORE):l.isEmpty(o,e)?l.handleRowColMapProp(l.TYPE.EMPTY):l.handleRowColMapProp(l.TYPE.DEFAULT,o,e,n,r,s)}).processCols(n,s)}).processRows(n,a.rowDel),o=JSON.stringify({data:r,filename:t.filename,mimeType:e.mimeType,fileExtension:e.fileExtension,merges:l.merges,RTL:i.RTL}),p=y({uuid:t.uuid,type:n});return i.exportButtons&&t.checkCaption(a.createObjButton(p,o,e.buttonContent,e.defaultClass,i.bootstrapSettings)),c.getInstance().setItem(p,o,!0)}},createObjButton:function(t,e,r,o,n){var a=document.createElement("button");return a.setAttribute("type","button"),a.setAttribute(this.storageKey,t),a.className=n.bootstrapClass+n.bootstrapTheme+o,a.textContent=r,a},escapeHtml:function(t){var e=this;return String(t).replace(/[&<>'\/]/g,function(t){return e.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=this.typeConfig;return~t.indexOf(e.string.defaultClass)?b.STRING:~t.indexOf(e.number.defaultClass)?b.NUMBER:~t.indexOf(e.boolean.defaultClass)?b.BOOLEAN:~t.indexOf(e.date.defaultClass)?b.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=(Date.parse(t)-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(r)},createSheet:function(t,e){for(var r={},o={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=this.typeConfig,a=0;a!==t.length;++a)for(var i=0;i!==t[a].length;++i){o.s.r>a&&(o.s.r=a),o.s.c>i&&(o.s.c=i),o.e.r tr")),o.rows=i.headers?w(r.querySelectorAll("thead > tr")).concat(o.rows):o.rows,o.rows=i.footers?o.rows.concat(w(r.querySelectorAll("tfoot > tr"))):o.rows,o.thAdj=i.headers?r.querySelectorAll("thead > tr").length:0,o.filename="id"===i.filename?r.getAttribute("id")||a.defaultFilename:i.filename||a.defaultFilename,o.sheetname="id"===i.sheetname?r.getAttribute("id")||a.defaultFilename:i.sheetname||a.defaultFilename,o.uuid=v(r),o.checkCaption=function(t){var e=r.querySelectorAll("caption."+a.defaultCaptionClass);e.length?e[0].appendChild(t):((e=document.createElement("caption")).className=i.bootstrapSettings.bootstrapSpacing+a.defaultCaptionClass,e.style.cssText="caption-side: "+i.position,e.appendChild(t),r.insertBefore(e,r.firstChild))},o.setExportData=function(t){var e=u.getInstance().getItem(t),r=t.substring(t.indexOf("-")+1);s[o.uuid]=s[o.uuid]||{},s[o.uuid][r]=JSON.parse(e)},o.rcMap=(new l).build(o,i);var n=g.reduce(function(t,e){return t[e]=0,t},{});i.formats.forEach(function(t){return e=t,~g.indexOf(e)?function(t){var e;switch(t){case h.TXT:case h.CSV:case h.XLS:e=!0;break;default:e=m(t)}return e}(t)?void(n[t]||(o.setExportData(a.exporters.build.call(a,o,t)),n[t]++)):S('"'+t+'" requires "js-xlsx".'):S('"'+t+'" is not a valid format. \nFormats: '+g.join(", "));var e})});var r=document.querySelectorAll("button["+a.storageKey+"]");return n(r,"click",a.downloadHandler,a),a};o.prototype={version:"5.1.0",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0,RTL:!1,sheetname:"id"},CONSTANTS:{FORMAT:{XLSX:"xlsx",XLSM:"xlsm",XLSB:"xlsb",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",defaultCaptionClass:"tableexport-caption",defaultNamespace:"tableexport-",tableKey:"tableexport-key",storageKey:"tableexport-id",ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",bootstrapConfig:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xlsm:{defaultClass:"xlsm",buttonContent:"Export to xlsm",mimeType:"application/vnd.ms-excel.sheet.macroEnabled.main+xml",fileExtension:".xlsm"},xlsb:{defaultClass:"xlsb",buttonContent:"Export to xlsb",mimeType:"application/vnd.ms-excel.sheet.binary.macroEnabled.main",fileExtension:".xlsb"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls",enforceStrictRFC4180:!1},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv",enforceStrictRFC4180:!0},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt",enforceStrictRFC4180:!0}},typeConfig:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},boolean:{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{build:function(t,n){var a=this,i=a.settings,e=a.formatConfig[n],s=e.separator,l=t.rcMap,r=w(t.rows).map(function(t,o){return l.isIgnore(o)?l.handleRowColMapProp(l.TYPE.IGNORE):l.isEmpty(o)?l.handleRowColMapProp(l.TYPE.EMPTY):w(t.querySelectorAll("th, td")).map(function(t,e){var r=function(t){if(m(n))return{v:i.formatValue(t.textContent),t:a.getType(t.className)};switch(n){case h.CSV:return'"'+i.formatValue(t.textContent.replace(/"/g,'""'))+'"';default:return i.formatValue(t.textContent)}}(t);return l.isIgnore(o,e)?l.handleRowColMapProp(l.TYPE.IGNORE):l.isEmpty(o,e)?l.handleRowColMapProp(l.TYPE.EMPTY):l.handleRowColMapProp(l.TYPE.DEFAULT,o,e,n,r,s)}).processCols(n,s)}).processRows(n,a.rowDel),o=JSON.stringify({data:r,filename:t.filename,mimeType:e.mimeType,fileExtension:e.fileExtension,merges:l.merges,RTL:i.RTL,sheetname:i.sheetname}),p=y({uuid:t.uuid,type:n});return i.exportButtons&&t.checkCaption(a.createObjButton(p,o,e.buttonContent,e.defaultClass,i.bootstrapSettings)),u.getInstance().setItem(p,o,!0)}},createObjButton:function(t,e,r,o,n){var a=document.createElement("button");return a.setAttribute("type","button"),a.setAttribute(this.storageKey,t),a.className=n.bootstrapClass+n.bootstrapTheme+o,a.textContent=r,a},escapeHtml:function(t){var e=this;return String(t).replace(/[&<>'\/]/g,function(t){return e.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=this.typeConfig;return~t.indexOf(e.string.defaultClass)?b.STRING:~t.indexOf(e.number.defaultClass)?b.NUMBER:~t.indexOf(e.boolean.defaultClass)?b.BOOLEAN:~t.indexOf(e.date.defaultClass)?b.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=(Date.parse(t)-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(r)},createSheet:function(t,e){for(var r={},o={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=this.typeConfig,a=0;a!==t.length;++a)for(var i=0;i!==t[a].length;++i){o.s.r>a&&(o.s.r=a),o.s.c>i&&(o.s.c=i),o.e.r tr")).concat(context.rows) : context.rows; context.rows = settings.footers ? context.rows.concat(_nodesArray(el.querySelectorAll("tfoot > tr"))) : context.rows; context.thAdj = settings.headers ? el.querySelectorAll("thead > tr").length : 0; - context.filename = - settings.filename === "id" - ? el.getAttribute("id") - ? el.getAttribute("id") - : self.defaultFilename - : settings.filename - ? settings.filename - : self.defaultFilename; + context.filename = settings.filename === "id" ? el.getAttribute("id") || self.defaultFilename : settings.filename || self.defaultFilename; + context.sheetname = settings.sheetname === "id" ? el.getAttribute("id") || self.defaultFilename : settings.sheetname || self.defaultFilename; context.uuid = _uuid(el); /** @@ -164,7 +158,8 @@ ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file(s) (default: null) ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file(s) (default: null) trimWhitespace: true, // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s) (default: false) - RTL: false // (Boolean), set direction of the worksheet to right-to-left (default: false) + RTL: false, // (Boolean), set direction of the worksheet to right-to-left (default: false) + sheetname: "id" // (id, String), sheet name for the exported spreadsheet, (default: 'id') }, /** * Constants @@ -398,7 +393,8 @@ mimeType: format.mimeType, fileExtension: format.fileExtension, merges: rcMap.merges, - RTL: settings.RTL + RTL: settings.RTL, + sheetname: settings.sheetname }); var hashKey = _hashCode({ uuid: context.uuid, type: key }); @@ -542,8 +538,9 @@ mimeType = object.mimeType, fileExtension = object.fileExtension, merges = object.merges, - RTL = object.RTL; - this.export2file(data, mimeType, filename, fileExtension, merges, RTL); + RTL = object.RTL, + sheetname = object.sheetname; + this.export2file(data, mimeType, filename, fileExtension, merges, RTL, sheetname); }, /** * Excel Workbook constructor @@ -577,9 +574,9 @@ * @param merges {Object[]} * @param RTL {Boolean} */ - export2file: function(data, mime, name, extension, merges, RTL) { + export2file: function(data, mime, name, extension, merges, RTL, sheetname) { var format = extension.slice(1); - data = this.getRawData(data, extension, name, merges, RTL); + data = this.getRawData(data, extension, name, merges, RTL, sheetname); if (_isMobile && (format === _FORMAT.CSV || format === _FORMAT.TXT)) { var dataURI = "data:" + mime + ";" + this.charset + "," + data; @@ -605,7 +602,7 @@ return key; } }, - getRawData: function(data, extension, name, merges, RTL) { + getRawData: function(data, extension, name, merges, RTL, sheetname) { var key = extension.substring(1); if (_isEnhanced(key)) { @@ -613,9 +610,9 @@ ws = this.createSheet(data, merges), bookType = this.getBookType(key); - name = name || ""; - wb.SheetNames.push(name); - wb.Sheets[name] = ws; + sheetname = sheetname || ""; + wb.SheetNames.push(sheetname); + wb.Sheets[sheetname] = ws; wb.Workbook.Views[0] = { RTL: RTL }; var wopts = { bookType: bookType, diff --git a/src/stable/js/tableexport.min.js b/src/stable/js/tableexport.min.js index 6157546..a7a0015 100644 --- a/src/stable/js/tableexport.min.js +++ b/src/stable/js/tableexport.min.js @@ -16,4 +16,4 @@ * limitations under the License. * */ -!function(t,r){if("function"==typeof define&&define.amd)define(function(t){var e;try{e=t("jquery")}catch(t){}return r(e,t("blobjs"),t("file-saverjs"),t("xlsx"))});else if("object"==typeof exports&&"string"!=typeof exports.nodeName){var e;try{e=require("jquery")}catch(t){}module.exports=r(e,require("blobjs"),require("file-saverjs"),require("xlsx"))}else t.TableExport=r(t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this,function(e,l,p,u){"use strict";var o=function(t,e){var a=this;if(!t)return S('"selectors" is required. \nUsage: TableExport(selectors, options)');if(!a)return new o(t,e);a.settings=C({},a.defaults,e),a.selectors=w(t);var i=a.settings;i.ignoreRows=i.ignoreRows instanceof Array?i.ignoreRows:[i.ignoreRows],i.ignoreCols=i.ignoreCols instanceof Array?i.ignoreCols:[i.ignoreCols],i.ignoreCSS=a.ignoreCSS instanceof Array?a.ignoreCSS:[a.ignoreCSS],i.emptyCSS=a.emptyCSS instanceof Array?a.emptyCSS:[a.emptyCSS],i.formatValue=a.formatValue.bind(this,i.trimWhitespace),i.bootstrapSettings=function(t,e,r){var o={};o.bootstrapSpacing=t?(o.bootstrapClass=e[0]+" ",o.bootstrapTheme=e[1]+" ",e[2]+" "):(o.bootstrapClass=r+" ",o.bootstrapTheme="","");return o}(i.bootstrap,a.bootstrapConfig,a.defaultButton);var s={};a.getExportData=function(){return s},a.selectors.forEach(function(r){var o={};o.rows=w(r.querySelectorAll("tbody > tr")),o.rows=i.headers?w(r.querySelectorAll("thead > tr")).concat(o.rows):o.rows,o.rows=i.footers?o.rows.concat(w(r.querySelectorAll("tfoot > tr"))):o.rows,o.thAdj=i.headers?r.querySelectorAll("thead > tr").length:0,o.filename="id"===i.filename?r.getAttribute("id")?r.getAttribute("id"):a.defaultFilename:i.filename?i.filename:a.defaultFilename,o.uuid=v(r),o.checkCaption=function(t){var e=r.querySelectorAll("caption."+a.defaultCaptionClass);e.length?e[0].appendChild(t):((e=document.createElement("caption")).className=i.bootstrapSettings.bootstrapSpacing+a.defaultCaptionClass,e.style.cssText="caption-side: "+i.position,e.appendChild(t),r.insertBefore(e,r.firstChild))},o.setExportData=function(t){var e=c.getInstance().getItem(t),r=t.substring(t.indexOf("-")+1);s[o.uuid]=s[o.uuid]||{},s[o.uuid][r]=JSON.parse(e)},o.rcMap=(new f).build(o,i);var n=g.reduce(function(t,e){return t[e]=0,t},{});i.formats.forEach(function(t){return e=t,~g.indexOf(e)?function(t){var e;switch(t){case m.TXT:case m.CSV:case m.XLS:e=!0;break;default:e=h(t)}return e}(t)?void(n[t]||(o.setExportData(a.exporters.build.call(a,o,t)),n[t]++)):S('"'+t+'" requires "js-xlsx".'):S('"'+t+'" is not a valid format. \nFormats: '+g.join(", "));var e})});var r=document.querySelectorAll("button["+a.storageKey+"]");return n(r,"click",a.downloadHandler,a),a};o.prototype={version:"5.1.0",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0,RTL:!1},CONSTANTS:{FORMAT:{XLSX:"xlsx",XLSM:"xlsm",XLSB:"xlsb",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",defaultCaptionClass:"tableexport-caption",defaultNamespace:"tableexport-",tableKey:"tableexport-key",storageKey:"tableexport-id",ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",bootstrapConfig:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xlsm:{defaultClass:"xlsm",buttonContent:"Export to xlsm",mimeType:"application/vnd.ms-excel.sheet.macroEnabled.main+xml",fileExtension:".xlsm"},xlsb:{defaultClass:"xlsb",buttonContent:"Export to xlsb",mimeType:"application/vnd.ms-excel.sheet.binary.macroEnabled.main",fileExtension:".xlsb"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls",enforceStrictRFC4180:!1},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv",enforceStrictRFC4180:!0},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt",enforceStrictRFC4180:!0}},typeConfig:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},boolean:{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{build:function(t,n){var a=this,i=a.settings,e=a.formatConfig[n],s=e.separator,l=t.rcMap,r=w(t.rows).map(function(t,o){return l.isIgnore(o)?l.handleRowColMapProp(l.TYPE.IGNORE):l.isEmpty(o)?l.handleRowColMapProp(l.TYPE.EMPTY):w(t.querySelectorAll("th, td")).map(function(t,e){var r=function(t){if(h(n))return{v:i.formatValue(t.textContent),t:a.getType(t.className)};switch(n){case m.CSV:return'"'+i.formatValue(t.textContent.replace(/"/g,'""'))+'"';default:return i.formatValue(t.textContent)}}(t);return l.isIgnore(o,e)?l.handleRowColMapProp(l.TYPE.IGNORE):l.isEmpty(o,e)?l.handleRowColMapProp(l.TYPE.EMPTY):l.handleRowColMapProp(l.TYPE.DEFAULT,o,e,n,r,s)}).processCols(n,s)}).processRows(n,a.rowDel),o=JSON.stringify({data:r,filename:t.filename,mimeType:e.mimeType,fileExtension:e.fileExtension,merges:l.merges,RTL:i.RTL}),p=y({uuid:t.uuid,type:n});return i.exportButtons&&t.checkCaption(a.createObjButton(p,o,e.buttonContent,e.defaultClass,i.bootstrapSettings)),c.getInstance().setItem(p,o,!0)}},createObjButton:function(t,e,r,o,n){var a=document.createElement("button");return a.setAttribute("type","button"),a.setAttribute(this.storageKey,t),a.className=n.bootstrapClass+n.bootstrapTheme+o,a.textContent=r,a},escapeHtml:function(t){var e=this;return String(t).replace(/[&<>'\/]/g,function(t){return e.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=this.typeConfig;return~t.indexOf(e.string.defaultClass)?b.STRING:~t.indexOf(e.number.defaultClass)?b.NUMBER:~t.indexOf(e.boolean.defaultClass)?b.BOOLEAN:~t.indexOf(e.date.defaultClass)?b.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=(Date.parse(t)-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(r)},createSheet:function(t,e){for(var r={},o={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=this.typeConfig,a=0;a!==t.length;++a)for(var i=0;i!==t[a].length;++i){o.s.r>a&&(o.s.r=a),o.s.c>i&&(o.s.c=i),o.e.r tr")),o.rows=i.headers?w(r.querySelectorAll("thead > tr")).concat(o.rows):o.rows,o.rows=i.footers?o.rows.concat(w(r.querySelectorAll("tfoot > tr"))):o.rows,o.thAdj=i.headers?r.querySelectorAll("thead > tr").length:0,o.filename="id"===i.filename?r.getAttribute("id")||a.defaultFilename:i.filename||a.defaultFilename,o.sheetname="id"===i.sheetname?r.getAttribute("id")||a.defaultFilename:i.sheetname||a.defaultFilename,o.uuid=v(r),o.checkCaption=function(t){var e=r.querySelectorAll("caption."+a.defaultCaptionClass);e.length?e[0].appendChild(t):((e=document.createElement("caption")).className=i.bootstrapSettings.bootstrapSpacing+a.defaultCaptionClass,e.style.cssText="caption-side: "+i.position,e.appendChild(t),r.insertBefore(e,r.firstChild))},o.setExportData=function(t){var e=u.getInstance().getItem(t),r=t.substring(t.indexOf("-")+1);s[o.uuid]=s[o.uuid]||{},s[o.uuid][r]=JSON.parse(e)},o.rcMap=(new l).build(o,i);var n=g.reduce(function(t,e){return t[e]=0,t},{});i.formats.forEach(function(t){return e=t,~g.indexOf(e)?function(t){var e;switch(t){case h.TXT:case h.CSV:case h.XLS:e=!0;break;default:e=m(t)}return e}(t)?void(n[t]||(o.setExportData(a.exporters.build.call(a,o,t)),n[t]++)):S('"'+t+'" requires "js-xlsx".'):S('"'+t+'" is not a valid format. \nFormats: '+g.join(", "));var e})});var r=document.querySelectorAll("button["+a.storageKey+"]");return n(r,"click",a.downloadHandler,a),a};o.prototype={version:"5.1.0",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0,RTL:!1,sheetname:"id"},CONSTANTS:{FORMAT:{XLSX:"xlsx",XLSM:"xlsm",XLSB:"xlsb",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",defaultCaptionClass:"tableexport-caption",defaultNamespace:"tableexport-",tableKey:"tableexport-key",storageKey:"tableexport-id",ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",bootstrapConfig:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xlsm:{defaultClass:"xlsm",buttonContent:"Export to xlsm",mimeType:"application/vnd.ms-excel.sheet.macroEnabled.main+xml",fileExtension:".xlsm"},xlsb:{defaultClass:"xlsb",buttonContent:"Export to xlsb",mimeType:"application/vnd.ms-excel.sheet.binary.macroEnabled.main",fileExtension:".xlsb"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls",enforceStrictRFC4180:!1},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv",enforceStrictRFC4180:!0},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt",enforceStrictRFC4180:!0}},typeConfig:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},boolean:{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{build:function(t,n){var a=this,i=a.settings,e=a.formatConfig[n],s=e.separator,l=t.rcMap,r=w(t.rows).map(function(t,o){return l.isIgnore(o)?l.handleRowColMapProp(l.TYPE.IGNORE):l.isEmpty(o)?l.handleRowColMapProp(l.TYPE.EMPTY):w(t.querySelectorAll("th, td")).map(function(t,e){var r=function(t){if(m(n))return{v:i.formatValue(t.textContent),t:a.getType(t.className)};switch(n){case h.CSV:return'"'+i.formatValue(t.textContent.replace(/"/g,'""'))+'"';default:return i.formatValue(t.textContent)}}(t);return l.isIgnore(o,e)?l.handleRowColMapProp(l.TYPE.IGNORE):l.isEmpty(o,e)?l.handleRowColMapProp(l.TYPE.EMPTY):l.handleRowColMapProp(l.TYPE.DEFAULT,o,e,n,r,s)}).processCols(n,s)}).processRows(n,a.rowDel),o=JSON.stringify({data:r,filename:t.filename,mimeType:e.mimeType,fileExtension:e.fileExtension,merges:l.merges,RTL:i.RTL,sheetname:i.sheetname}),p=y({uuid:t.uuid,type:n});return i.exportButtons&&t.checkCaption(a.createObjButton(p,o,e.buttonContent,e.defaultClass,i.bootstrapSettings)),u.getInstance().setItem(p,o,!0)}},createObjButton:function(t,e,r,o,n){var a=document.createElement("button");return a.setAttribute("type","button"),a.setAttribute(this.storageKey,t),a.className=n.bootstrapClass+n.bootstrapTheme+o,a.textContent=r,a},escapeHtml:function(t){var e=this;return String(t).replace(/[&<>'\/]/g,function(t){return e.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=this.typeConfig;return~t.indexOf(e.string.defaultClass)?b.STRING:~t.indexOf(e.number.defaultClass)?b.NUMBER:~t.indexOf(e.boolean.defaultClass)?b.BOOLEAN:~t.indexOf(e.date.defaultClass)?b.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=(Date.parse(t)-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(r)},createSheet:function(t,e){for(var r={},o={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=this.typeConfig,a=0;a!==t.length;++a)for(var i=0;i!==t[a].length;++i){o.s.r>a&&(o.s.r=a),o.s.c>i&&(o.s.c=i),o.e.r