You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
9.1 KiB
19 lines
9.1 KiB
/*!
|
|
* TableExport.js v3.3.13 (https://www.travismclarke.com)
|
|
*
|
|
* Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
*/
|
|
!function(t,e){"function"==typeof define&&define.amd?define(["exports","jquery","blobjs","file-saverjs","xlsx-js"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?e(exports,require("jquery"),require("blobjs"),require("file-saverjs"),require("xlsx-js")):e(t,t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this||window,function(t,e,o,n,r){"use strict";var s=function(t,o,n){var i=this;i.settings=n?o:e.extend({},s.prototype.defaults,o),i.selectors=t;var a,p,f,l=s.prototype.rowDel,u=i.settings.trimWhitespace,c=i.settings.ignoreRows instanceof Array?i.settings.ignoreRows:[i.settings.ignoreRows],x=i.settings.ignoreCols instanceof Array?i.settings.ignoreCols:[i.settings.ignoreCols],y=i.settings.ignoreCSS instanceof Array?i.settings.ignoreCSS.join(", "):i.settings.ignoreCSS,d=i.settings.emptyCSS instanceof Array?i.settings.emptyCSS.join(", "):i.settings.emptyCSS;return i.settings.bootstrap?(a=s.prototype.bootstrap[0]+" ",p=s.prototype.bootstrap[1]+" ",f=s.prototype.bootstrap[2]+" "):(a=s.prototype.defaultButton+" ",p=f=""),i.selectors.each(function(){function t(t){var e=m.find("caption:not(.head)");e.length?e.append(t):m.prepend('<caption class="'+f+i.settings.position+'">'+t+"</caption>")}function o(e,o,n){var r="<button data-fileblob='"+e+"' class='"+a+p+n+"'>"+o+"</button>";t(r)}var m=e(this);n&&m.find("caption:not(.head)").remove();var g=m.find("tbody").find("tr"),g=i.settings.headings?g.add(m.find("thead>tr")):g,g=i.settings.footers?g.add(m.find("tfoot>tr")):g,b=i.settings.headings?m.find("thead>tr").length:0,v="id"===i.settings.fileName?m.attr("id")?m.attr("id"):s.prototype.defaultFileName:i.settings.fileName,h={xlsx:function(t,n){var r={},i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(y)){var n=e(o).find("th, td");return[n.map(function(o,n){if(!~x.indexOf(o)&&!e(n).is(y)){if(e(n).is(d))return" ";if(n.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][o+1]=n.getAttribute("colspan")-1),n.hasAttribute("rowspan"))for(var i=1;i<n.getAttribute("rowspan");i++)r[t+i]=r[t+i]||{},r[t+i][o]=1;if(r[t]){for(var a=o+1,p=0,f=0,i=0;i<=Math.max.apply(Math,Object.keys(r[t]))&&(r[t][i]?p=f>=o?p+r[t][i]:p:f++,f!==a);i++);return new Array(p).concat({v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))})}return{v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))}}}).get()]}}).get(),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.xlsx.mimeType,fileExtension:s.prototype.xlsx.fileExtension})),p=s.prototype.xlsx.buttonContent,f=s.prototype.xlsx.defaultClass;o(a,p,f)},xlsm:function(t,n){var r={},i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(y)){var n=e(o).find("th, td");return[n.map(function(o,n){if(!~x.indexOf(o)&&!e(n).is(y)){if(e(n).is(d))return" ";if(n.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][o+1]=n.getAttribute("colspan")-1),n.hasAttribute("rowspan"))for(var i=1;i<n.getAttribute("rowspan");i++)r[t+i]=r[t+i]||{},r[t+i][o]=1;if(r[t]){for(var a=o+1,p=0,f=0,i=0;i<=Math.max.apply(Math,Object.keys(r[t]))&&(r[t][i]?p=f>=o?p+r[t][i]:p:f++,f!==a);i++);return new Array(p).concat({v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))})}return{v:s.prototype.formatValue(u,e(n).text()),t:s.prototype.getType(e(n).attr("class"))}}}).get()]}}).get(),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.xls.mimeType,fileExtension:s.prototype.xls.fileExtension})),p=s.prototype.xls.buttonContent,f=s.prototype.xls.defaultClass;o(a,p,f)},xls:function(t,n){var r=s.prototype.xls.separator,i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(y)){var n=e(o).find("th, td");return n.map(function(t,o){if(!~x.indexOf(t)&&!e(o).is(y))return e(o).is(d)?" ":{v:s.prototype.formatValue(u,e(o).text()),t:s.prototype.getType(e(o).attr("class"))}}).get().join(r)}}).get().join(t),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.xls.mimeType,fileExtension:s.prototype.xls.fileExtension})),p=s.prototype.xls.buttonContent,f=s.prototype.xls.defaultClass;o(a,p,f)},csv:function(t,n){var r=s.prototype.csv.separator,i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(y)){var n=e(o).find("th, td");return n.map(function(t,o){if(!~x.indexOf(t)&&!e(o).is(y))return e(o).is(d)?" ":'"'+s.prototype.formatValue(u,e(o).text().replace(/"/g,'""'))+'"'}).get().join(r)}}).get().join(t),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.csv.mimeType,fileExtension:s.prototype.csv.fileExtension})),p=s.prototype.csv.buttonContent,f=s.prototype.csv.defaultClass;o(a,p,f)},txt:function(t,n){var r=s.prototype.txt.separator,i=g.map(function(t,o){if(!~c.indexOf(t-b)&&!e(o).is(y)){var n=e(o).find("th, td");return n.map(function(t,o){if(!~x.indexOf(t)&&!e(o).is(y))return e(o).is(d)?" ":s.prototype.formatValue(u,e(o).text())}).get().join(r)}}).get().join(t),a=s.prototype.escapeHtml(JSON.stringify({data:i,fileName:n,mimeType:s.prototype.txt.mimeType,fileExtension:s.prototype.txt.fileExtension})),p=s.prototype.txt.buttonContent,f=s.prototype.txt.defaultClass;o(a,p,f)}};i.settings.formats.forEach(function(t){!(!r||"xls"!==t)&&(t="xlsm"),!r&&"xlsx"===t&&(t=null),t&&h[t](l,v)})}),e("button[data-fileblob]").off("click").on("click",function(){var t=e(this).data("fileblob"),o=t.data,n=t.fileName,r=t.mimeType,i=t.fileExtension;s.prototype.export2file(o,r,n,i)}),i};s.prototype={version:"3.3.13",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",trimWhitespace:!1},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},types:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t.replace(/,/g,""))}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!isNaN(Date.parse(t))}}},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return s.prototype.entityMap[t]})},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=s.prototype.types;return~t.indexOf(e.string.defaultClass)?"s":~t.indexOf(e.number.defaultClass)?"n":~t.indexOf(e["boolean"].defaultClass)?"b":~t.indexOf(e.date.defaultClass)?"d":""},dateNum:function(t,e){e&&(t+=1462);var o=Date.parse(t);return(o-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},o={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=s.prototype.types,i=0;i!==t.length;++i)for(var a=0;a!==t[i].length;++a){o.s.r>i&&(o.s.r=i),o.s.c>a&&(o.s.c=a),o.e.r<i&&(o.e.r=i),o.e.c<a&&(o.e.c=a);var p=t[i][a];if(p&&p.v){var f=r.utils.encode_cell({c:a,r:i});p.t||(n.number.assert(p.v)?p.t="n":n["boolean"].assert(p.v)?p.t="b":n.date.assert(p.v)?p.t="d":p.t="s"),"d"===p.t&&(p.t="n",p.z=r.SSF._table[14],p.v=this.dateNum(p.v)),e[f]=p}}return o.s.c<1e7&&(e["!ref"]=r.utils.encode_range(o)),e},Workbook:function(){this.SheetNames=[],this.Sheets={}},string2ArrayBuffer:function(t){for(var e=new ArrayBuffer(t.length),o=new Uint8Array(e),n=0;n!==t.length;++n)o[n]=255&t.charCodeAt(n);return e},export2file:function(t,e,s,i){if(r&&".xls"===i.substr(0,4)){var a=new this.Workbook,p=this.createSheet(t);a.SheetNames.push(s),a.Sheets[s]=p;var f={bookType:i.substr(1,3)+(i.substr(4)||"m"),bookSST:!1,type:"binary"},l=r.write(a,f);t=this.string2ArrayBuffer(l)}n(new o([t],{type:e+";"+this.charset}),s+i,!0)},update:function(t){return new s(this.selectors,e.extend({},this.settings,t),(!0))},reset:function(){return new s(this.selectors,this.settings,(!0))},remove:function(){this.selectors.each(function(){e(this).find("caption:not(.head)").remove()})}},e.fn.tableExport=function(t,e){return new s(this,t,e)};for(var i in s.prototype)e.fn.tableExport[i]=s.prototype[i];return t["default"]=t.TableExport=s});
|