forked from hhurz/tableExport.jquery.plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tableExport.min.js
69 lines (66 loc) · 30.9 KB
/
tableExport.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
tableExport.jquery.plugin
Copyright (c) 2015-2017 hhurz, https://github.com/hhurz
Original Work Copyright (c) 2014 Giri Raj
Licensed under the MIT License
*/
(function(c){c.fn.extend({tableExport:function(n){function N(b){var a=[];c(b).find("thead").first().find("th").each(function(b,f){void 0!==c(f).attr("data-field")?a[b]=c(f).attr("data-field"):a[b]=b.toString()});return a}function y(b,m,e,f,K){if(-1==c.inArray(e,a.ignoreRow)&&-1==c.inArray(e-f,a.ignoreRow)){var r=c(b).filter(function(){return"none"!=c(this).data("tableexport-display")&&(c(this).is(":visible")||"always"==c(this).data("tableexport-display")||"always"==c(this).closest("table").data("tableexport-display"))}).find(m),
k=0;r.each(function(b){if(("always"==c(this).data("tableexport-display")||"none"!=c(this).css("display")&&"hidden"!=c(this).css("visibility")&&"none"!=c(this).data("tableexport-display"))&&"function"===typeof K){var f,m=1,t=1;var d=r.length;if("undefined"!=typeof z[e]&&0<z[e].length){var g=b;for(f=0;f<=g;f++)"undefined"!=typeof z[e][f]&&(K(null,e,f),delete z[e][f],g++);b+=z[e].length;d+=z[e].length}c(this).is("[colspan]")&&(m=parseInt(c(this).attr("colspan"))||1,k+=0<m?m-1:0);c(this).is("[rowspan]")&&
(t=parseInt(c(this).attr("rowspan"))||1);f=d;d=b+k;g=!1;0<a.ignoreColumn.length&&(-1!=c.inArray(d,a.ignoreColumn)||-1!=c.inArray(d-f,a.ignoreColumn)||H.length>d&&"undefined"!=typeof H[d]&&-1!=c.inArray(H[d],a.ignoreColumn))&&(g=!0);if(!1===g)for(K(this,e,b),f=1;f<m;f++)K(null,e,b+f);if(1<t)for(d=1;d<t;d++)for("undefined"==typeof z[e+d]&&(z[e+d]=[]),z[e+d][b+k]="",f=1;f<m;f++)z[e+d][b+k-f]=""}});if("undefined"!=typeof z[e]&&0<z[e].length)for(b=0;b<=z[e].length;b++)"undefined"!=typeof z[e][b]&&(K(null,
e,b),delete z[e][b])}}function aa(b,m){!0===a.consoleLog&&console.log(b.output());if("string"===a.outputMode)return b.output();if("base64"===a.outputMode)return D(b.output());if("window"===a.outputMode)window.open(URL.createObjectURL(b.output("blob")));else try{var e=b.output("blob");saveAs(e,a.fileName+".pdf")}catch(f){A(a.fileName+".pdf","data:application/pdf"+(m?"":";base64")+",",m?e:b.output())}}function ba(b,a,e){var f=0;"undefined"!=typeof e&&(f=e.colspan);if(0<=f){for(var m=b.width,c=b.textPos.x,
k=a.table.columns.indexOf(a.column),t=1;t<f;t++)m+=a.table.columns[k+t].width;1<f&&("right"===b.styles.halign?c=b.textPos.x+m-b.width:"center"===b.styles.halign&&(c=b.textPos.x+(m-b.width)/2));b.width=m;b.textPos.x=c;"undefined"!=typeof e&&1<e.rowspan&&(b.height*=e.rowspan);if("middle"===b.styles.valign||"bottom"===b.styles.valign)e=("string"===typeof b.text?b.text.split(/\r\n|\r|\n/g):b.text).length||1,2<e&&(b.textPos.y-=(2-1.15)/2*a.row.styles.fontSize*(e-2)/3);return!0}return!1}function ca(b,a,
e){"undefined"!=typeof e.images&&a.each(function(){var a=c(this).children();if(c(this).is("img")){var m=da(this.src);e.images[m]={url:this.src,src:this.src}}"undefined"!=typeof a&&0<a.length&&ca(b,a,e)})}function ma(b,a){function e(b){if(b.url){var f=new Image;m=++c;f.crossOrigin="Anonymous";f.onerror=f.onload=function(){if(f.complete&&(0===f.src.indexOf("data:image/")&&(f.width=b.width||f.width||0,f.height=b.height||f.height||0),f.width+f.height)){var e=document.createElement("canvas"),k=e.getContext("2d");
e.width=f.width;e.height=f.height;k.drawImage(f,0,0);b.src=e.toDataURL("image/jpeg")}--c||a(m)};f.src=b.url}}var f,m=0,c=0;if("undefined"!=typeof b.images)for(f in b.images)b.images.hasOwnProperty(f)&&e(b.images[f]);(f=c)||(a(m),f=void 0);return f}function ea(b,m,e){m.each(function(){var f=c(this).children();if(c(this).is("div")){var m=O(E(this,"background-color"),[255,255,255]),r=O(E(this,"border-top-color"),[0,0,0]),k=P(this,"border-top-width",a.jspdf.unit),t=this.getBoundingClientRect(),d=this.offsetLeft*
e.dw;var g=this.offsetTop*e.dh;var h=t.width*e.dw,t=t.height*e.dh;e.doc.setDrawColor.apply(void 0,r);e.doc.setFillColor.apply(void 0,m);e.doc.setLineWidth(k);e.doc.rect(b.x+d,b.y+g,h,t,k?"FD":"F")}else if(c(this).is("img")&&"undefined"!=typeof e.images&&(g=da(this.src),m=e.images[g],"undefined"!=typeof m)){r=b.width/b.height;k=this.width/this.height;d=b.width;h=b.height;t=19.049976/25.4;g=0;k<=r?(h=Math.min(b.height,this.height),d=this.width*h/this.height):k>r&&(d=Math.min(b.width,this.width),h=this.height*
d/this.width);d*=t;h*=t;h<b.height&&(g=(b.height-h)/2);try{e.doc.addImage(m.src,b.textPos.x,b.y+g,d,h)}catch(qa){}b.textPos.x+=d}"undefined"!=typeof f&&0<f.length&&ea(b,f,e)})}function fa(b,a,e){if("function"===typeof e.onAutotableText)e.onAutotableText(e.doc,b,a);else{var f=b.textPos.x,m=b.textPos.y,r={halign:b.styles.halign,valign:b.styles.valign};if(a.length){for(a=a[0];a.previousSibling;)a=a.previousSibling;for(var k=!1,t=!1;a;){var d=a.innerText||a.textContent||"",d=(d.length&&" "==d[0]?" ":
"")+c.trim(d)+(1<d.length&&" "==d[d.length-1]?" ":"");c(a).is("br")&&(f=b.textPos.x,m+=e.doc.internal.getFontSize());c(a).is("b")?k=!0:c(a).is("i")&&(t=!0);(k||t)&&e.doc.setFontType(k&&t?"bolditalic":k?"bold":"italic");var g=e.doc.getStringUnitWidth(d)*e.doc.internal.getFontSize();if(g){if("linebreak"===b.styles.overflow&&f>b.textPos.x&&f+g>b.textPos.x+b.width){if(0<=".,!%*;:=-".indexOf(d.charAt(0))){var h=d.charAt(0),g=e.doc.getStringUnitWidth(h)*e.doc.internal.getFontSize();f+g<=b.textPos.x+b.width&&
(e.doc.autoTableText(h,f,m,r),d=d.substring(1,d.length));g=e.doc.getStringUnitWidth(d)*e.doc.internal.getFontSize()}f=b.textPos.x;m+=e.doc.internal.getFontSize()}for(;d.length&&f+g>b.textPos.x+b.width;)d=d.substring(0,d.length-1),g=e.doc.getStringUnitWidth(d)*e.doc.internal.getFontSize();e.doc.autoTableText(d,f,m,r);f+=g}if(k||t)c(a).is("b")?k=!1:c(a).is("i")&&(t=!1),e.doc.setFontType(k||t?k?"bold":"italic":"normal");a=a.nextSibling}b.textPos.x=f;b.textPos.y=m}else e.doc.autoTableText(b.text,b.textPos.x,
b.textPos.y,r)}}function Q(b,a,e){return b.replace(new RegExp(a.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),e)}function U(b){b=Q(b||"0",a.numbers.html.thousandsSeparator,"");b=Q(b,a.numbers.html.decimalMark,".");return"number"===typeof b||!1!==jQuery.isNumeric(b)?b:!1}function w(b,m,e){var f="";if(null!==b){var d=c(b);if(d[0].hasAttribute("data-tableexport-value"))var r=(r=d.data("tableexport-value"))?r+"":"";else if(r=d.html(),"function"===typeof a.onCellHtmlData)r=a.onCellHtmlData(d,m,e,
r);else if(""!=r){b=c.parseHTML(r);var k=0,t=0;r="";c.each(b,function(){if(c(this).is("input"))r+=d.find("input").eq(k++).val();else if(c(this).is("select"))r+=d.find("select option:selected").eq(t++).text();else if("undefined"===typeof c(this).html())r+=c(this).text();else if(void 0===jQuery().bootstrapTable||!0!==c(this).hasClass("filterControl"))r+=c(this).html()})}if(!0===a.htmlContent)f=c.trim(r);else if(r&&""!=r){var g=r.replace(/\n/g,"\u2028").replace(/<br\s*[\/]?>/gi,"\u2060");b=c("<div/>").html(g).contents();
g="";c.each(b.text().split("\u2028"),function(b,a){0<b&&(g+=" ");g+=c.trim(a)});c.each(g.split("\u2060"),function(b,a){0<b&&(f+="\n");f+=c.trim(a).replace(/\u00AD/g,"")});if("json"==a.type||"excel"===a.type&&"xmlss"===a.excelFileFormat||!1===a.numbers.output)b=U(f),!1!==b&&(f=Number(b));else if(a.numbers.html.decimalMark!=a.numbers.output.decimalMark||a.numbers.html.thousandsSeparator!=a.numbers.output.thousandsSeparator)if(b=U(f),!1!==b){var h=(""+b.substr(0>b?1:0)).split(".");1==h.length&&(h[1]=
"");var l=3<h[0].length?h[0].length%3:0,f=(0>b?"-":"")+(a.numbers.output.thousandsSeparator?(l?h[0].substr(0,l)+a.numbers.output.thousandsSeparator:"")+h[0].substr(l).replace(/(\d{3})(?=\d)/g,"$1"+a.numbers.output.thousandsSeparator):h[0])+(h[1].length?a.numbers.output.decimalMark+h[1]:"")}}!0===a.escape&&(f=escape(f));"function"===typeof a.onCellData&&(f=a.onCellData(d,m,e,f))}return f}function na(b,a,e){return a+"-"+e.toLowerCase()}function O(b,a){var e=/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.exec(b),
f=a;e&&(f=[parseInt(e[1]),parseInt(e[2]),parseInt(e[3])]);return f}function ga(b){var a=E(b,"text-align"),e=E(b,"font-weight"),f=E(b,"font-style"),d="";"start"==a&&(a="rtl"==E(b,"direction")?"right":"left");700<=e&&(d="bold");"italic"==f&&(d+=f);""===d&&(d="normal");a={style:{align:a,bcolor:O(E(b,"background-color"),[255,255,255]),color:O(E(b,"color"),[0,0,0]),fstyle:d},colspan:parseInt(c(b).attr("colspan"))||0,rowspan:parseInt(c(b).attr("rowspan"))||0};null!==b&&(b=b.getBoundingClientRect(),a.rect=
{width:b.width,height:b.height});return a}function E(a,c){try{return window.getComputedStyle?(c=c.replace(/([a-z])([A-Z])/,na),window.getComputedStyle(a,null).getPropertyValue(c)):a.currentStyle?a.currentStyle[c]:a.style[c]}catch(e){}return""}function P(a,c,e){c=E(a,c).match(/\d+/);if(null!==c){c=c[0];a=a.parentElement;var b=document.createElement("div");b.style.overflow="hidden";b.style.visibility="hidden";a.appendChild(b);b.style.width=100+e;e=100/b.offsetWidth;a.removeChild(b);return c*e}return 0}
function V(){if(!(this instanceof V))return new V;this.SheetNames=[];this.Sheets={}}function oa(a){for(var b=new ArrayBuffer(a.length),e=new Uint8Array(b),f=0;f!=a.length;++f)e[f]=a.charCodeAt(f)&255;return b}function pa(a){for(var b={},e={s:{c:1E7,r:1E7},e:{c:0,r:0}},f=0;f!=a.length;++f)for(var c=0;c!=a[f].length;++c){e.s.r>f&&(e.s.r=f);e.s.c>c&&(e.s.c=c);e.e.r<f&&(e.e.r=f);e.e.c<c&&(e.e.c=c);var d={v:a[f][c]};if(null!==d.v){var k=XLSX.utils.encode_cell({c:c,r:f});if("number"===typeof d.v)d.t="n";
else if("boolean"===typeof d.v)d.t="b";else if(d.v instanceof Date){d.t="n";d.z=XLSX.SSF._table[14];var t=d;var g=(Date.parse(d.v)-new Date(Date.UTC(1899,11,30)))/864E5;t.v=g}else d.t="s";b[k]=d}}1E7>e.s.c&&(b["!ref"]=XLSX.utils.encode_range(e));return b}function da(a){var b=0,c;if(0===a.length)return b;var f=0;for(c=a.length;f<c;f++){var d=a.charCodeAt(f);b=(b<<5)-b+d;b|=0}return b}function A(a,c,e){var b=window.navigator.userAgent;if(!1!==a&&(0<b.indexOf("MSIE ")||b.match(/Trident.*rv\:11\./)))if(window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(new Blob([e]),
a);else{if(c=document.createElement("iframe"))document.body.appendChild(c),c.setAttribute("style","display:none"),c.contentDocument.open("txt/html","replace"),c.contentDocument.write(e),c.contentDocument.close(),c.focus(),c.contentDocument.execCommand("SaveAs",!0,a),document.body.removeChild(c)}else if(b=document.createElement("a")){var d=null;b.style.display="none";!1!==a?b.download=a:b.target="_blank";"object"==typeof e?(d=window.URL.createObjectURL(e),b.href=d):0<=c.toLowerCase().indexOf("base64,")?
b.href=c+D(e):b.href=c+encodeURIComponent(e);document.body.appendChild(b);if(document.createEvent)null===R&&(R=document.createEvent("MouseEvents")),R.initEvent("click",!0,!1),b.dispatchEvent(R);else if(document.createEventObject)b.fireEvent("onclick");else if("function"==typeof b.onclick)b.onclick();d&&window.URL.revokeObjectURL(d);document.body.removeChild(b)}}function D(a){var b="",c,f=0;a=a.replace(/\x0d\x0a/g,"\n");var d="";for(c=0;c<a.length;c++){var g=a.charCodeAt(c);128>g?d+=String.fromCharCode(g):
(127<g&&2048>g?d+=String.fromCharCode(g>>6|192):(d+=String.fromCharCode(g>>12|224),d+=String.fromCharCode(g>>6&63|128)),d+=String.fromCharCode(g&63|128))}for(a=d;f<a.length;){var k=a.charCodeAt(f++);d=a.charCodeAt(f++);c=a.charCodeAt(f++);g=k>>2;k=(k&3)<<4|d>>4;var t=(d&15)<<2|c>>6;var h=c&63;isNaN(d)?t=h=64:isNaN(c)&&(h=64);b=b+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(k)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(t)+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(h)}return b}var a={consoleLog:!1,csvEnclosure:'"',csvSeparator:",",csvUseBOM:!0,displayTableName:!1,escape:!1,excelFileFormat:"xlshtml",excelstyles:[],fileName:"tableExport",htmlContent:!1,ignoreColumn:[],ignoreRow:[],jsonScope:"all",jspdf:{orientation:"p",unit:"pt",format:"a4",margins:{left:20,right:10,top:10,bottom:10},autotable:{styles:{cellPadding:2,rowHeight:12,fontSize:8,fillColor:255,textColor:50,fontStyle:"normal",
overflow:"ellipsize",halign:"left",valign:"middle"},headerStyles:{fillColor:[52,73,94],textColor:255,fontStyle:"bold",halign:"center"},alternateRowStyles:{fillColor:245},tableExport:{onAfterAutotable:null,onBeforeAutotable:null,onAutotableText:null,onTable:null,outputImages:!0}}},numbers:{html:{decimalMark:".",thousandsSeparator:","},output:{decimalMark:".",thousandsSeparator:","}},onCellData:null,onCellHtmlData:null,onMsoNumberFormat:null,outputMode:"file",pdfmake:{enabled:!1,docDefinition:{pageOrientation:"portrait",
defaultStyle:{font:"Roboto"}},fonts:{}},tbodySelector:"tr",tfootSelector:"tr",theadSelector:"tr",tableName:"myTableName",type:"csv",worksheetName:"Worksheet"},u=this,R=null,q=[],g=[],p=0,z=[],h="",H=[];c.extend(!0,a,n);H=N(u);if("csv"==a.type||"tsv"==a.type||"txt"==a.type){var C="",I=0,p=0,W=function(b,d,e){b.each(function(){h="";y(this,d,p,e+b.length,function(b,c,e){var f=h,d="";if(null!==b)if(b=w(b,c,e),c=null===b||""===b?"":b.toString(),"tsv"==a.type)b instanceof Date&&b.toLocaleString(),d=Q(c,
"\t"," ");else if(b instanceof Date)d=a.csvEnclosure+b.toLocaleString()+a.csvEnclosure;else if(d=Q(c,a.csvEnclosure,a.csvEnclosure+a.csvEnclosure),0<=d.indexOf(a.csvSeparator)||/[\r\n ]/g.test(d))d=a.csvEnclosure+d+a.csvEnclosure;h=f+(d+("tsv"==a.type?"\t":a.csvSeparator))});h=c.trim(h).substring(0,h.length-1);0<h.length&&(0<C.length&&(C+="\n"),C+=h);p++});return b.length},I=I+W(c(u).find("thead").first().find(a.theadSelector),"th,td",I);c(u).find("tbody").each(function(){I+=W(c(this).find(a.tbodySelector),
"td,th",I)});a.tfootSelector.length&&W(c(u).find("tfoot").first().find(a.tfootSelector),"td,th",I);C+="\n";!0===a.consoleLog&&console.log(C);if("string"===a.outputMode)return C;if("base64"===a.outputMode)return D(C);if("window"===a.outputMode){A(!1,"data:text/"+("csv"==a.type?"csv":"plain")+";charset=utf-8,",C);return}try{var x=new Blob([C],{type:"text/"+("csv"==a.type?"csv":"plain")+";charset=utf-8"});saveAs(x,a.fileName+"."+a.type,"csv"!=a.type||!1===a.csvUseBOM)}catch(b){A(a.fileName+"."+a.type,
"data:text/"+("csv"==a.type?"csv":"plain")+";charset=utf-8,"+("csv"==a.type&&a.csvUseBOM?"\ufeff":""),C)}}else if("sql"==a.type){var p=0,v="INSERT INTO `"+a.tableName+"` (",q=c(u).find("thead").first().find(a.theadSelector);q.each(function(){y(this,"th,td",p,q.length,function(a,c,e){v+="'"+w(a,c,e)+"',"});p++;v=c.trim(v);v=c.trim(v).substring(0,v.length-1)});v+=") VALUES ";c(u).find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,c(u).find("tfoot").find(a.tfootSelector));
c(g).each(function(){h="";y(this,"td,th",p,q.length+g.length,function(a,c,e){h+="'"+w(a,c,e)+"',"});3<h.length&&(v+="("+h,v=c.trim(v).substring(0,v.length-1),v+="),");p++});v=c.trim(v).substring(0,v.length-1);v+=";";!0===a.consoleLog&&console.log(v);if("string"===a.outputMode)return v;if("base64"===a.outputMode)return D(v);try{x=new Blob([v],{type:"text/plain;charset=utf-8"}),saveAs(x,a.fileName+".sql")}catch(b){A(a.fileName+".sql","data:application/sql;charset=utf-8,",v)}}else if("json"==a.type){var J=
[],q=c(u).find("thead").first().find(a.theadSelector);q.each(function(){var a=[];y(this,"th,td",p,q.length,function(b,c,f){a.push(w(b,c,f))});J.push(a)});var X=[];c(u).find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,c(u).find("tfoot").find(a.tfootSelector));c(g).each(function(){var a={},d=0;y(this,"td,th",p,q.length+g.length,function(b,c,m){J.length?a[J[J.length-1][d]]=w(b,c,m):a[d]=w(b,c,m);d++});!1===c.isEmptyObject(a)&&X.push(a);
p++});n="";n="head"==a.jsonScope?JSON.stringify(J):"data"==a.jsonScope?JSON.stringify(X):JSON.stringify({header:J,data:X});!0===a.consoleLog&&console.log(n);if("string"===a.outputMode)return n;if("base64"===a.outputMode)return D(n);try{x=new Blob([n],{type:"application/json;charset=utf-8"}),saveAs(x,a.fileName+".json")}catch(b){A(a.fileName+".json","data:application/json;charset=utf-8;base64,",n)}}else if("xml"===a.type){p=0;var B='<?xml version="1.0" encoding="utf-8"?>';B+="<tabledata><fields>";
q=c(u).find("thead").first().find(a.theadSelector);q.each(function(){y(this,"th,td",p,q.length,function(a,c,d){B+="<field>"+w(a,c,d)+"</field>"});p++});B+="</fields><data>";var ha=1;c(u).find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,c(u).find("tfoot").find(a.tfootSelector));c(g).each(function(){var a=1;h="";y(this,"td,th",p,q.length+g.length,function(b,c,d){h+="<column-"+a+">"+w(b,c,d)+"</column-"+a+">";a++});0<h.length&&"<column-1></column-1>"!=
h&&(B+='<row id="'+ha+'">'+h+"</row>",ha++);p++});B+="</data></tabledata>";!0===a.consoleLog&&console.log(B);if("string"===a.outputMode)return B;if("base64"===a.outputMode)return D(B);try{x=new Blob([B],{type:"application/xml;charset=utf-8"}),saveAs(x,a.fileName+".xml")}catch(b){A(a.fileName+".xml","data:application/xml;charset=utf-8;base64,",B)}}else if("excel"===a.type&&"xmlss"===a.excelFileFormat){var l=c(u).filter(function(){return"none"!=c(this).data("tableexport-display")&&(c(this).is(":visible")||
"always"==c(this).data("tableexport-display"))});var Y=[];l.each(function(){var b=c(this),d="";p=0;H=N(this);q=b.find("thead").first().find(a.theadSelector);var d=d+"<Table>",e=0;q.each(function(){h="";y(this,"th,td",p,q.length,function(a,b,c){null!==a&&(h+='<Cell><Data ss:Type="String">'+w(a,b,c)+"</Data></Cell>",e++)});0<h.length&&(d+="<Row>"+h+"</Row>");p++});g=[];b.find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});c(g).each(function(){c(this);h="";y(this,"td,th",p,
q.length+g.length,function(a,b,c){if(null!==a){var d="String",e="";a=w(a,b,c);!1!==jQuery.isNumeric(a)?d="Number":(b=a,-1<b.indexOf("%")?(b=U(b.replace(/%/g,"")),!1!==b&&(b/=100)):b=!1,number=b,!1!==number&&(a=number,d="Number",e=' ss:StyleID="pct1"'));"Number"!==d&&(a=a.replace(/\n/g,"<br>"));h+="<Cell"+e+'><Data ss:Type="'+d+'">'+a+"</Data></Cell>"}});0<h.length&&(d+="<Row>"+h+"</Row>");p++});d+="</Table>";Y.push(d);!0===a.consoleLog&&console.log(d)});l='<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <Created>'+
(new Date).toISOString()+'</Created> </DocumentProperties> <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"> <AllowPNG/> </OfficeDocumentSettings> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>9000</WindowHeight> <WindowWidth>13860</WindowWidth> <WindowTopX>0</WindowTopX> <WindowTopY>0</WindowTopY> <ProtectStructure>False</ProtectStructure> <ProtectWindows>False</ProtectWindows> </ExcelWorkbook> <Styles> <Style ss:ID="Default" ss:Name="Default"> <Alignment ss:Vertical="Center"/> <Borders/> <Font/> <Interior/> <NumberFormat/> <Protection/> </Style> <Style ss:ID="Normal" ss:Name="Normal"/> <Style ss:ID="pct1"> <NumberFormat ss:Format="Percent"/> </Style> </Styles>';
for(n=0;n<Y.length;n++)l+='<Worksheet ss:Name="'+("string"===typeof a.worksheetName?a.worksheetName+" "+(n+1):"undefined"!==typeof a.worksheetName[n]?a.worksheetName[n]:"Table "+(n+1))+'">'+Y[n]+"<WorksheetOptions/> </Worksheet>";l+="</Workbook>";!0===a.consoleLog&&console.log(l);if("string"===a.outputMode)return l;if("base64"===a.outputMode)return D(l);try{x=new Blob([l],{type:"application/xml;charset=utf-8"}),saveAs(x,a.fileName+".xml")}catch(b){A(a.fileName+".xml","data:application/xml;charset=utf-8;base64,",
B)}}else if("excel"==a.type||"xls"==a.type||"word"==a.type||"doc"==a.type){n="excel"==a.type||"xls"==a.type?"excel":"word";var F="excel"==n?"xls":"doc",S='xmlns:x="urn:schemas-microsoft-com:office:'+n+'"';l=c(u).filter(function(){return"none"!=c(this).data("tableexport-display")&&(c(this).is(":visible")||"always"==c(this).data("tableexport-display"))});var G="";l.each(function(){var b=c(this);p=0;H=N(this);G+="<table><thead>";q=b.find("thead").first().find(a.theadSelector);q.each(function(){h="";
y(this,"th,td",p,q.length,function(b,d,f){if(null!==b){var e="";h+="<th";for(var g in a.excelstyles)if(a.excelstyles.hasOwnProperty(g)){var k=c(b).css(a.excelstyles[g]);""!==k&&"0px none rgb(0, 0, 0)"!=k&&"rgba(0, 0, 0, 0)"!=k&&(e+=""===e?'style="':";",e+=a.excelstyles[g]+":"+k)}""!==e&&(h+=" "+e+'"');c(b).is("[colspan]")&&(h+=' colspan="'+c(b).attr("colspan")+'"');c(b).is("[rowspan]")&&(h+=' rowspan="'+c(b).attr("rowspan")+'"');h+=">"+w(b,d,f)+"</th>"}});0<h.length&&(G+="<tr>"+h+"</tr>");p++});G+=
"</thead><tbody>";b.find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,b.find("tfoot").find(a.tfootSelector));c(g).each(function(){var b=c(this);h="";y(this,"td,th",p,q.length+g.length,function(d,f,g){if(null!==d){var e="",k=c(d).data("tableexport-msonumberformat");"undefined"==typeof k&&"function"===typeof a.onMsoNumberFormat&&(k=a.onMsoNumberFormat(d,f,g));"undefined"!=typeof k&&""!==k&&(e="style=\"mso-number-format:'"+k+"'");for(var m in a.excelstyles)a.excelstyles.hasOwnProperty(m)&&
(k=c(d).css(a.excelstyles[m]),""===k&&(k=b.css(a.excelstyles[m])),""!==k&&"0px none rgb(0, 0, 0)"!=k&&"rgba(0, 0, 0, 0)"!=k&&(e+=""===e?'style="':";",e+=a.excelstyles[m]+":"+k));h+="<td";""!==e&&(h+=" "+e+'"');c(d).is("[colspan]")&&(h+=' colspan="'+c(d).attr("colspan")+'"');c(d).is("[rowspan]")&&(h+=' rowspan="'+c(d).attr("rowspan")+'"');h+=">"+w(d,f,g).replace(/\n/g,"<br>")+"</td>"}});0<h.length&&(G+="<tr>"+h+"</tr>");p++});a.displayTableName&&(G+="<tr><td></td></tr><tr><td></td></tr><tr><td>"+w(c("<p>"+
a.tableName+"</p>"))+"</td></tr>");G+="</tbody></table>";!0===a.consoleLog&&console.log(G)});l='<html xmlns:o="urn:schemas-microsoft-com:office:office" '+S+' xmlns="http://www.w3.org/TR/REC-html40">'+('<meta http-equiv="content-type" content="application/vnd.ms-'+n+'; charset=UTF-8">')+"<head>";"excel"===n&&(l+="\x3c!--[if gte mso 9]>",l+="<xml>",l+="<x:ExcelWorkbook>",l+="<x:ExcelWorksheets>",l+="<x:ExcelWorksheet>",l+="<x:Name>",l+=a.worksheetName,l+="</x:Name>",l+="<x:WorksheetOptions>",l+="<x:DisplayGridlines/>",
l+="</x:WorksheetOptions>",l+="</x:ExcelWorksheet>",l+="</x:ExcelWorksheets>",l+="</x:ExcelWorkbook>",l+="</xml>",l+="<![endif]--\x3e");l+="<style>br {mso-data-placement:same-cell;}</style>";l+="</head>";l+="<body>";l+=G;l+="</body>";l+="</html>";!0===a.consoleLog&&console.log(l);if("string"===a.outputMode)return l;if("base64"===a.outputMode)return D(l);try{x=new Blob([l],{type:"application/vnd.ms-"+a.type}),saveAs(x,a.fileName+"."+F)}catch(b){A(a.fileName+"."+F,"data:application/vnd.ms-"+n+";base64,",
l)}}else if("xlsx"==a.type){var ia=[],Z=[],p=0,g=c(u).find("thead").first().find(a.theadSelector);c(u).find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,c(u).find("tfoot").find(a.tfootSelector));c(g).each(function(){var a=[];y(this,"th,td",p,g.length,function(b,c,d){if("undefined"!==typeof b&&null!==b){var e=parseInt(b.getAttribute("colspan")),f=parseInt(b.getAttribute("rowspan"));b=w(b,c,d);""!==b&&b==+b&&(b=+b);Z.forEach(function(b){if(p>=
b.s.r&&p<=b.e.r&&a.length>=b.s.c&&a.length<=b.e.c)for(var c=0;c<=b.e.c-b.s.c;++c)a.push(null)});if(f||e)e=e||1,Z.push({s:{r:p,c:a.length},e:{r:p+(f||1)-1,c:a.length+e-1}});a.push(""!==b?b:null);if(e)for(f=0;f<e-1;++f)a.push(null)}});ia.push(a);p++});n=new V;F=pa(ia);F["!merges"]=Z;n.SheetNames.push(a.worksheetName);n.Sheets[a.worksheetName]=F;n=XLSX.write(n,{bookType:a.type,bookSST:!1,type:"binary"});try{x=new Blob([oa(n)],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8"}),
saveAs(x,a.fileName+"."+a.type)}catch(b){A(a.fileName+"."+a.type,"data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8,",x)}}else if("png"==a.type)html2canvas(c(u)[0]).then(function(b){b=b.toDataURL();for(var c=atob(b.substring(22)),d=new ArrayBuffer(c.length),f=new Uint8Array(d),g=0;g<c.length;g++)f[g]=c.charCodeAt(g);!0===a.consoleLog&&console.log(c);if("string"===a.outputMode)return c;if("base64"===a.outputMode)return D(b);if("window"===a.outputMode)window.open(b);
else try{x=new Blob([d],{type:"image/png"}),saveAs(x,a.fileName+".png")}catch(r){A(a.fileName+".png","data:image/png,",x)}});else if("pdf"==a.type)if(!0===a.pdfmake.enabled){n=[];var ja=[],p=0,F=function(a,d,e){var b=0;c(a).each(function(){var a=[];y(this,d,p,e,function(b,c,d){if("undefined"!==typeof b&&null!==b){var e=parseInt(b.getAttribute("colspan")),f=parseInt(b.getAttribute("rowspan"));b=w(b,c,d)||" ";1<e||1<f?a.push({colSpan:e||1,rowSpan:f||1,text:b}):a.push(b)}else a.push(" ")});a.length&&
ja.push(a);b<a.length&&(b=a.length);p++});return b},q=c(this).find("thead").first().find(a.theadSelector);l=F(q,"th,td",q.length);for(S=n.length;S<l;S++)n.push("*");c(this).find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,c(this).find("tfoot").find(a.tfootSelector));F(g,"th,td",q.length+g.length);n={content:[{table:{headerRows:q.length,widths:n,body:ja}}]};c.extend(!0,n,a.pdfmake.docDefinition);pdfMake.fonts={Roboto:{normal:"Roboto-Regular.ttf",
bold:"Roboto-Medium.ttf",italics:"Roboto-Italic.ttf",bolditalics:"Roboto-MediumItalic.ttf"}};c.extend(!0,pdfMake.fonts,a.pdfmake.fonts);pdfMake.createPdf(n).getBuffer(function(b){try{var c=new Blob([b],{type:"application/pdf"});saveAs(c,a.fileName+".pdf")}catch(e){A(a.fileName+".pdf","data:application/pdf;base64,",b)}})}else if(!1===a.jspdf.autotable){n={dim:{w:P(c(u).first().get(0),"width","mm"),h:P(c(u).first().get(0),"height","mm")},pagesplit:!1};var ka=new jsPDF(a.jspdf.orientation,a.jspdf.unit,
a.jspdf.format);ka.addHTML(c(u).first(),a.jspdf.margins.left,a.jspdf.margins.top,n,function(){aa(ka,!1)})}else{var d=a.jspdf.autotable.tableExport;if("string"===typeof a.jspdf.format&&"bestfit"===a.jspdf.format.toLowerCase()){var L={a0:[2383.94,3370.39],a1:[1683.78,2383.94],a2:[1190.55,1683.78],a3:[841.89,1190.55],a4:[595.28,841.89]},T="",M="",la=0;c(u).filter(":visible").each(function(){if("none"!=c(this).css("display")){var a=P(c(this).get(0),"width","pt");if(a>la){a>L.a0[0]&&(T="a0",M="l");for(var d in L)L.hasOwnProperty(d)&&
L[d][1]>a&&(T=d,M="l",L[d][0]>a&&(M="p"));la=a}}});a.jspdf.format=""===T?"a4":T;a.jspdf.orientation=""===M?"w":M}d.doc=new jsPDF(a.jspdf.orientation,a.jspdf.unit,a.jspdf.format);!0===d.outputImages&&(d.images={});"undefined"!=typeof d.images&&(c(u).filter(function(){return"none"!=c(this).data("tableexport-display")&&(c(this).is(":visible")||"always"==c(this).data("tableexport-display"))}).each(function(){var b=0;q=c(this).find("thead").find(a.theadSelector);c(this).find("tbody").each(function(){g.push.apply(g,
c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,c(this).find("tfoot").find(a.tfootSelector));c(g).each(function(){y(this,"td,th",q.length+b,q.length+g.length,function(a,b,f){"undefined"!==typeof a&&null!==a&&(b=c(a).children(),"undefined"!=typeof b&&0<b.length&&ca(a,b,d))});b++})}),q=[],g=[]);ma(d,function(b){c(u).filter(function(){return"none"!=c(this).data("tableexport-display")&&(c(this).is(":visible")||"always"==c(this).data("tableexport-display"))}).each(function(){var b,
e=0;H=N(this);d.columns=[];d.rows=[];d.rowoptions={};if("function"===typeof d.onTable&&!1===d.onTable(c(this),a))return!0;a.jspdf.autotable.tableExport=null;var f=c.extend(!0,{},a.jspdf.autotable);a.jspdf.autotable.tableExport=d;f.margin={};c.extend(!0,f.margin,a.jspdf.margins);f.tableExport=d;"function"!==typeof f.beforePageContent&&(f.beforePageContent=function(a){1==a.pageCount&&a.table.rows.concat(a.table.headerRow).forEach(function(b){0<b.height&&(b.height+=(2-1.15)/2*b.styles.fontSize,a.table.height+=
(2-1.15)/2*b.styles.fontSize)})});"function"!==typeof f.createdHeaderCell&&(f.createdHeaderCell=function(a,b){a.styles=c.extend({},b.row.styles);if("undefined"!=typeof d.columns[b.column.dataKey]){var e=d.columns[b.column.dataKey];if("undefined"!=typeof e.rect){a.contentWidth=e.rect.width;if("undefined"==typeof d.heightRatio||0===d.heightRatio){var g=b.row.raw[b.column.dataKey].rowspan?b.row.raw[b.column.dataKey].rect.height/b.row.raw[b.column.dataKey].rowspan:b.row.raw[b.column.dataKey].rect.height;
d.heightRatio=a.styles.rowHeight/g}g=b.row.raw[b.column.dataKey].rect.height*d.heightRatio;g>a.styles.rowHeight&&(a.styles.rowHeight=g)}"undefined"!=typeof e.style&&!0!==e.style.hidden&&(a.styles.halign=e.style.align,"inherit"===f.styles.fillColor&&(a.styles.fillColor=e.style.bcolor),"inherit"===f.styles.textColor&&(a.styles.textColor=e.style.color),"inherit"===f.styles.fontStyle&&(a.styles.fontStyle=e.style.fstyle))}});"function"!==typeof f.createdCell&&(f.createdCell=function(a,b){var c=d.rowoptions[b.row.index+
":"+b.column.dataKey];"undefined"!=typeof c&&"undefined"!=typeof c.style&&!0!==c.style.hidden&&(a.styles.halign=c.style.align,"inherit"===f.styles.fillColor&&(a.styles.fillColor=c.style.bcolor),"inherit"===f.styles.textColor&&(a.styles.textColor=c.style.color),"inherit"===f.styles.fontStyle&&(a.styles.fontStyle=c.style.fstyle))});"function"!==typeof f.drawHeaderCell&&(f.drawHeaderCell=function(a,b){var c=d.columns[b.column.dataKey];return(!0!==c.style.hasOwnProperty("hidden")||!0!==c.style.hidden)&&
0<=c.rowIndex?ba(a,b,c):!1});"function"!==typeof f.drawCell&&(f.drawCell=function(a,b){var c=d.rowoptions[b.row.index+":"+b.column.dataKey];if(ba(a,b,c))if(d.doc.rect(a.x,a.y,a.width,a.height,a.styles.fillStyle),"undefined"!=typeof c&&"undefined"!=typeof c.kids&&0<c.kids.length){var e=a.height/c.rect.height;if(e>d.dh||"undefined"==typeof d.dh)d.dh=e;d.dw=a.width/c.rect.width;e=a.textPos.y;ea(a,c.kids,d);a.textPos.y=e;fa(a,c.kids,d)}else fa(a,{},d);return!1});d.headerrows=[];q=c(this).find("thead").find(a.theadSelector);
q.each(function(){b=0;d.headerrows[e]=[];y(this,"th,td",e,q.length,function(a,c,f){var g=ga(a);g.title=w(a,c,f);g.key=b++;g.rowIndex=e;d.headerrows[e].push(g)});e++});if(0<e)for(var h=e-1;0<=h;)c.each(d.headerrows[h],function(){var a=this;0<h&&null===this.rect&&(a=d.headerrows[h-1][this.key]);null!==a&&0<=a.rowIndex&&(!0!==a.style.hasOwnProperty("hidden")||!0!==a.style.hidden)&&d.columns.push(a)}),h=0<d.columns.length?-1:h-1;var l=0;g=[];c(this).find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});
a.tfootSelector.length&&g.push.apply(g,c(this).find("tfoot").find(a.tfootSelector));c(g).each(function(){var a=[];b=0;y(this,"td,th",e,q.length+g.length,function(e,f,g){if("undefined"===typeof d.columns[b]){var h={title:"",key:b,style:{hidden:!0}};d.columns.push(h)}"undefined"!==typeof e&&null!==e?(h=ga(e),h.kids=c(e).children()):(h=c.extend(!0,{},d.rowoptions[l+":"+(b-1)]),h.colspan=-1);d.rowoptions[l+":"+b++]=h;a.push(w(e,f,g))});a.length&&(d.rows.push(a),l++);e++});if("function"===typeof d.onBeforeAutotable)d.onBeforeAutotable(c(this),
d.columns,d.rows,f);d.doc.autoTable(d.columns,d.rows,f);if("function"===typeof d.onAfterAutotable)d.onAfterAutotable(c(this),f);a.jspdf.autotable.startY=d.doc.autoTableEndPosY()+f.margin.top});aa(d.doc,"undefined"!=typeof d.images&&!1===jQuery.isEmptyObject(d.images));"undefined"!=typeof d.headerrows&&(d.headerrows.length=0);"undefined"!=typeof d.columns&&(d.columns.length=0);"undefined"!=typeof d.rows&&(d.rows.length=0);delete d.doc;d.doc=null})}return this}})})(jQuery);