-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtableExport.min.js
9 lines (7 loc) · 26.1 KB
/
tableExport.min.js
1
2
3
4
5
6
7
8
9
/*
tableExport.jquery.plugin
Copyright (c) 2015,2016 hhurz, https://github.com/hhurz/tableExport.jquery.plugin
Original work Copyright (c) 2014 Giri Raj, https://github.com/kayalshri/
Licensed under the MIT License, http://opensource.org/licenses/mit-license
*/
!function(t){t.fn.extend({tableExport:function(e){function n(e){var n=[];return t(e).find("thead").first().find("th").each(function(e,o){void 0!==t(o).attr("data-field")?n[e]=t(o).attr("data-field"):n[e]=e.toString()}),n}function o(e,n){var o=!1;return D.ignoreColumn.length>0&&("string"==typeof D.ignoreColumn[0]?H.length>n&&"undefined"!=typeof H[n]&&-1!=t.inArray(H[n],D.ignoreColumn)&&(o=!0):"number"==typeof D.ignoreColumn[0]&&(-1!=t.inArray(n,D.ignoreColumn)||-1!=t.inArray(n-e.length,D.ignoreColumn))&&(o=!0)),o}function a(e,n,a,i,r){if(-1==t.inArray(a,D.ignoreRow)&&-1==t.inArray(a-i,D.ignoreRow)){var l=t(e).filter(function(){return"none"!=t(this).data("tableexportDisplay")&&(t(this).is(":visible")||"always"==t(this).data("tableexportDisplay")||"always"==t(this).closest("table").data("tableexportDisplay"))}).find(n),s=0,f=0;if(l.each(function(e){if(("always"==t(this).data("tableexportDisplay")||"none"!=t(this).css("display")&&"hidden"!=t(this).css("visibility")&&"none"!=t(this).data("tableexportDisplay"))&&o(l,e)===!1&&"function"==typeof r){var n,i,c=0,d=0;if("undefined"!=typeof I[a]&&I[a].length>0)for(n=0;e>=n;n++)"undefined"!=typeof I[a][n]&&(r(null,a,n),delete I[a][n],e++);for(f=e,t(this).is("[colspan]")&&(c=parseInt(t(this).attr("colspan")),s+=c>0?c-1:0),t(this).is("[rowspan]")&&(d=parseInt(t(this).attr("rowspan"))),r(this,a,e),n=0;c-1>n;n++)r(null,a,e+n);if(d)for(i=1;d>i;i++)for("undefined"==typeof I[a+i]&&(I[a+i]=[]),I[a+i][e+s]="",n=1;c>n;n++)I[a+i][e+s-n]=""}}),"undefined"!=typeof I[a]&&I[a].length>0)for(var c=0;c<=I[a].length;c++)"undefined"!=typeof I[a][c]&&(r(null,a,c),delete I[a][c])}}function i(t){if(D.consoleLog===!0&&console.log(t.output()),"string"===D.outputMode)return t.output();if("base64"===D.outputMode)return j(t.output());if("window"===D.outputMode)return void window.open(URL.createObjectURL(t.output("blob")));try{var e=t.output("blob");saveAs(e,D.fileName+".pdf"),D.postCallback()}catch(n){N(D.fileName+".pdf","data:application/pdf;base64,",t.output())}}function r(t,e,n){var o=0;if("undefined"!=typeof n&&(o=n.colspan),o>=0){for(var a=t.width,i=t.textPos.x,r=e.table.columns.indexOf(e.column),l=1;o>l;l++){var s=e.table.columns[r+l];a+=s.width}if(o>1&&("right"===t.styles.halign?i=t.textPos.x+a-t.width:"center"===t.styles.halign&&(i=t.textPos.x+(a-t.width)/2)),t.width=a,t.textPos.x=i,"undefined"!=typeof n&&n.rowspan>1&&(t.height=t.height*n.rowspan),"middle"===t.styles.valign||"bottom"===t.styles.valign){var f="string"==typeof t.text?t.text.split(/\r\n|\r|\n/g):t.text,c=f.length||1;c>2&&(t.textPos.y-=(2-O)/2*e.row.styles.fontSize*(c-2)/3)}return!0}return!1}function l(e,n,o){"undefined"!=typeof o.images&&n.each(function(){var n=t(this).children();if(t(this).is("img")){var a=A(this.src);o.images[a]={url:this.src,src:this.src}}"undefined"!=typeof n&&n.length>0&&l(e,n,o)})}function s(t,e){function n(){e(i)}function o(t){if(t.url){var e=new Image;i=++r,e.crossOrigin="Anonymous",e.onerror=e.onload=function(){if(e.complete&&(0===e.src.indexOf("data:image/")&&(e.width=t.width||e.width||0,e.height=t.height||e.height||0),e.width+e.height)){var o=document.createElement("canvas"),a=o.getContext("2d");o.width=e.width,o.height=e.height,a.drawImage(e,0,0),t.src=o.toDataURL("image/jpeg")}--r||n()},e.src=t.url}}var a,i=0,r=0;if("undefined"!=typeof t.images)for(a in t.images)t.images.hasOwnProperty(a)&&o(t.images[a]);return r||n()}function f(e,n,o){n.each(function(){var n=t(this).children();if(t(this).is("div")){var a=g(b(this,"background-color"),[255,255,255]),i=g(b(this,"border-top-color"),[0,0,0]),r=w(this,"border-top-width",D.jspdf.unit),l=this.getBoundingClientRect(),s=this.offsetLeft*o.dw,c=this.offsetTop*o.dh,d=l.width*o.dw,h=l.height*o.dh;o.doc.setDrawColor.apply(void 0,i),o.doc.setFillColor.apply(void 0,a),o.doc.setLineWidth(r),o.doc.rect(e.x+s,e.y+c,d,h,r?"FD":"F")}else if(t(this).is("img")&&"undefined"!=typeof o.images){var u=A(this.src),p=o.images[u];if("undefined"!=typeof p){var y=e.width/e.height,m=this.width/this.height,v=e.width,x=e.height,c=0;y>m?(x=Math.min(e.height,this.height),v=this.width*x/this.height):m>y&&(v=Math.min(e.width,this.width),x=this.height*v/this.width),x<e.height&&(c=(e.height-x)/2),o.doc.addImage(p.src,e.textPos.x,e.y+c,v,x),e.textPos.x+=v}}"undefined"!=typeof n&&n.length>0&&f(e,n,o)})}function c(t){return t.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")}function d(t,e,n){return t.replace(new RegExp(c(e),"g"),n)}function h(t,e,n){var o="";if(null!==t){var a=p(t,e,n),i=null===a||""===a?"":a.toString();a instanceof Date?o=D.csvEnclosure+a.toLocaleString()+D.csvEnclosure:(o=d(i,D.csvEnclosure,D.csvEnclosure+D.csvEnclosure),(o.indexOf(D.csvSeparator)>=0||/[\r\n ]/g.test(o))&&(o=D.csvEnclosure+o+D.csvEnclosure))}return o}function u(t){return t=t||"0",t=d(t,D.numbers.html.decimalMark,"."),t=d(t,D.numbers.html.thousandsSeparator,""),"number"==typeof t||jQuery.isNumeric(t)!==!1?t:!1}function p(e,n,o){var a="";if(null!==e){var i,r=t(e),l=r[0].hasAttribute("data-tableexport-value");if(i=l?r.data("tableexportValue"):r.html(),!l&&""!=i){var s=t.parseHTML(i);i="",t.each(s,function(){if(t(this).is("input"))i+=r.find("input").val();else{if(!t(this).is("select"))return i+=r.html(),!1;i+=r.find("select option:selected").text()}})}if("function"==typeof D.onCellHtmlData&&(i=D.onCellHtmlData(r,n,o,i)),D.htmlContent===!0)a=t.trim(i);else{var f=i.replace(/\n/g,"\u2028").replace(/<br\s*[\/]?>/gi,""),c=t("<div/>").html(f).contents();if(f="",t.each(c.text().split("\u2028"),function(e,n){e>0&&(f+=" "),f+=t.trim(n)}),t.each(f.split(""),function(e,n){e>0&&(a+="\n"),a+=t.trim(n).replace(/\u00AD/g,"")}),D.numbers.html.decimalMark!=D.numbers.output.decimalMark||D.numbers.html.thousandsSeparator!=D.numbers.output.thousandsSeparator){var d=u(a);if(d!==!1){var h=(""+d).split(".");1==h.length&&(h[1]="");var p=h[0].length>3?h[0].length%3:0;a=(0>d?"-":"")+(D.numbers.output.thousandsSeparator?(p?h[0].substr(0,p)+D.numbers.output.thousandsSeparator:"")+h[0].substr(p).replace(/(\d{3})(?=\d)/g,"$1"+D.numbers.output.thousandsSeparator):h[0])+(h[1].length?D.numbers.output.decimalMark+h[1]:"")}}}D.escape===!0&&(a=escape(a)),"function"==typeof D.onCellData&&(a=D.onCellData(r,n,o,a))}return a}function y(t,e,n){return e+"-"+n.toLowerCase()}function g(t,e){var n=/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,o=n.exec(t),a=e;return o&&(a=[parseInt(o[1]),parseInt(o[2]),parseInt(o[3])]),a}function m(e){var n=b(e,"text-align"),o=b(e,"font-weight"),a=b(e,"font-style"),i="";"start"==n&&(n="rtl"==b(e,"direction")?"right":"left"),o>=700&&(i="bold"),"italic"==a&&(i+=a),""===i&&(i="normal");var r={style:{align:n,bcolor:g(b(e,"background-color"),[255,255,255]),color:g(b(e,"color"),[0,0,0]),fstyle:i},colspan:parseInt(t(e).attr("colspan"))||0,rowspan:parseInt(t(e).attr("rowspan"))||0};if(null!==e){var l=e.getBoundingClientRect();r.rect={width:l.width,height:l.height}}return r}function b(t,e){try{return window.getComputedStyle?(e=e.replace(/([a-z])([A-Z])/,y),window.getComputedStyle(t,null).getPropertyValue(e)):t.currentStyle?t.currentStyle[e]:t.style[e]}catch(n){}return""}function v(t,e,n){var o=100,a=document.createElement("div");a.style.overflow="hidden",a.style.visibility="hidden",t.appendChild(a),a.style.width=o+n;var i=o/a.offsetWidth;return t.removeChild(a),e*i}function w(t,e,n){var o=b(t,e),a=o.match(/\d+/);return null!==a?(a=a[0],v(t.parentElement,a,n)):0}function x(){return this instanceof x?(this.SheetNames=[],void(this.Sheets={})):new x}function S(t){for(var e=new ArrayBuffer(t.length),n=new Uint8Array(e),o=0;o!=t.length;++o)n[o]=255&t.charCodeAt(o);return e}function C(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5}function k(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},o=0;o!=t.length;++o)for(var a=0;a!=t[o].length;++a){n.s.r>o&&(n.s.r=o),n.s.c>a&&(n.s.c=a),n.e.r<o&&(n.e.r=o),n.e.c<a&&(n.e.c=a);var i={v:t[o][a]};if(null!==i.v){var r=XLSX.utils.encode_cell({c:a,r:o});"number"==typeof i.v?i.t="n":"boolean"==typeof i.v?i.t="b":i.v instanceof Date?(i.t="n",i.z=XLSX.SSF._table[14],i.v=C(i.v)):i.t="s",e[r]=i}}return n.s.c<1e7&&(e["!ref"]=XLSX.utils.encode_range(n)),e}function A(t){var e,n,o,a=0;if(0===t.length)return a;for(e=0,o=t.length;o>e;e++)n=t.charCodeAt(e),a=(a<<5)-a+n,a|=0;return a}function N(t,e,n){var o=window.navigator.userAgent;if(t!==!1&&(o.indexOf("MSIE ")>0||o.match(/Trident.*rv\:11\./)))if(window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(new Blob([n]),t);else{var a=document.createElement("iframe");a&&(document.body.appendChild(a),a.setAttribute("style","display:none"),a.contentDocument.open("txt/html","replace"),a.contentDocument.write(n),a.contentDocument.close(),a.focus(),a.contentDocument.execCommand("SaveAs",!0,t),document.body.removeChild(a),D.postCallback())}else{var i=document.createElement("a");i&&(i.style.display="none",t!==!1?i.download=t:i.target="_blank",e.toLowerCase().indexOf("base64,")>=0?i.href=e+j(n):i.href=e+encodeURIComponent(n),document.body.appendChild(i),document.createEvent?(null===T&&(T=document.createEvent("MouseEvents")),T.initEvent("click",!0,!1),i.dispatchEvent(T)):document.createEventObject?i.fireEvent("onclick"):"function"==typeof i.onclick&&i.onclick(),document.body.removeChild(i))}D.postCallback()}function E(t){t=t.replace(/\x0d\x0a/g,"\n");for(var e="",n=0;n<t.length;n++){var o=t.charCodeAt(n);128>o?e+=String.fromCharCode(o):o>127&&2048>o?(e+=String.fromCharCode(o>>6|192),e+=String.fromCharCode(63&o|128)):(e+=String.fromCharCode(o>>12|224),e+=String.fromCharCode(o>>6&63|128),e+=String.fromCharCode(63&o|128))}return e}function j(t){var e,n,o,a,i,r,l,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",f="",c=0;for(t=E(t);c<t.length;)e=t.charCodeAt(c++),n=t.charCodeAt(c++),o=t.charCodeAt(c++),a=e>>2,i=(3&e)<<4|n>>4,r=(15&n)<<2|o>>6,l=63&o,isNaN(n)?r=l=64:isNaN(o)&&(l=64),f=f+s.charAt(a)+s.charAt(i)+s.charAt(r)+s.charAt(l);return f}var M,D={test:"asdf",consoleLog:!1,csvEnclosure:'"',csvSeparator:",",csvUseBOM:!0,displayTableName:!1,escape:!1,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,onTable:null,outputImages:!0}}},numbers:{html:{decimalMark:".",thousandsSeparator:","},output:{decimalMark:".",thousandsSeparator:","}},onCellData:null,onCellHtmlData:null,outputMode:"file",pdfmake:{enabled:!1},tbodySelector:"tr",tfootSelector:"tr",theadSelector:"tr",tableName:"myTableName",type:"csv",worksheetName:"xlsWorksheetName",postCallback:function(){}},O=1.15,L=this,T=null,B=[],P=[],R=0,I=[],U="",H=[];if(t.extend(!0,D,e),H=n(L),"csv"==D.type||"txt"==D.type){var W="",F=0;R=0;var K=function(e,n,o){return e.each(function(){U="",a(this,n,R,o+e.length,function(t,e,n){U+=h(t,e,n)+D.csvSeparator}),U=t.trim(U).substring(0,U.length-1),U.length>0&&(W.length>0&&(W+="\n"),W+=U),R++}),e.length};if(F+=K(t(L).find("thead").first().find(D.theadSelector),"th,td",F),t(L).find("tbody").each(function(){F+=K(t(this).find(D.tbodySelector),"td,th",F)}),D.tfootSelector.length&&K(t(L).find("tfoot").first().find(D.tfootSelector),"td,th",F),W+="\n",D.consoleLog===!0&&console.log(W),"string"===D.outputMode)return W;if("base64"===D.outputMode)return j(W);if("window"===D.outputMode)return void N(!1,"data:text/"+("csv"==D.type?"csv":"plain")+";charset=utf-8,",W);try{M=new Blob([W],{type:"text/"+("csv"==D.type?"csv":"plain")+";charset=utf-8"}),saveAs(M,D.fileName+"."+D.type,"csv"!=D.type||D.csvUseBOM===!1),D.postCallback()}catch(X){N(D.fileName+"."+D.type,"data:text/"+("csv"==D.type?"csv":"plain")+";charset=utf-8,"+("csv"==D.type&&D.csvUseBOM?"\ufeff":""),W)}}else if("sql"==D.type){R=0;var z="INSERT INTO `"+D.tableName+"` (";if(B=t(L).find("thead").first().find(D.theadSelector),B.each(function(){a(this,"th,td",R,B.length,function(t,e,n){z+="'"+p(t,e,n)+"',"}),R++,z=t.trim(z),z=t.trim(z).substring(0,z.length-1)}),z+=") VALUES ",t(L).find("tbody").each(function(){P.push.apply(P,t(this).find(D.tbodySelector))}),D.tfootSelector.length&&P.push.apply(P,t(L).find("tfoot").find(D.tfootSelector)),t(P).each(function(){U="",a(this,"td,th",R,B.length+P.length,function(t,e,n){U+="'"+p(t,e,n)+"',"}),U.length>3&&(z+="("+U,z=t.trim(z).substring(0,z.length-1),z+="),"),R++}),z=t.trim(z).substring(0,z.length-1),z+=";",D.consoleLog===!0&&console.log(z),"string"===D.outputMode)return z;if("base64"===D.outputMode)return j(z);try{M=new Blob([z],{type:"text/plain;charset=utf-8"}),saveAs(M,D.fileName+".sql"),D.postCallback()}catch(X){N(D.fileName+".sql","data:application/sql;charset=utf-8,",z)}}else if("json"==D.type){var q=[];B=t(L).find("thead").first().find(D.theadSelector),B.each(function(){var t=[];a(this,"th,td",R,B.length,function(e,n,o){t.push(p(e,n,o))}),q.push(t)});var J=[];t(L).find("tbody").each(function(){P.push.apply(P,t(this).find(D.tbodySelector))}),D.tfootSelector.length&&P.push.apply(P,t(L).find("tfoot").find(D.tfootSelector)),t(P).each(function(){var e={},n=0;a(this,"td,th",R,B.length+P.length,function(t,o,a){q.length?e[q[q.length-1][n]]=p(t,o,a):e[n]=p(t,o,a),n++}),t.isEmptyObject(e)===!1&&J.push(e),R++});var V="";if(V="head"==D.jsonScope?JSON.stringify(q):"data"==D.jsonScope?JSON.stringify(J):JSON.stringify({header:q,data:J}),D.consoleLog===!0&&console.log(V),"string"===D.outputMode)return V;if("base64"===D.outputMode)return j(V);try{M=new Blob([V],{type:"application/json;charset=utf-8"}),saveAs(M,D.fileName+".json"),D.postCallback()}catch(X){N(D.fileName+".json","data:application/json;charset=utf-8;base64,",V)}}else if("xml"===D.type){R=0;var $='<?xml version="1.0" encoding="utf-8"?>';$+="<tabledata><fields>",B=t(L).find("thead").first().find(D.theadSelector),B.each(function(){a(this,"th,td",R,B.length,function(t,e,n){$+="<field>"+p(t,e,n)+"</field>"}),R++}),$+="</fields><data>";var _=1;if(t(L).find("tbody").each(function(){P.push.apply(P,t(this).find(D.tbodySelector))}),D.tfootSelector.length&&P.push.apply(P,t(L).find("tfoot").find(D.tfootSelector)),t(P).each(function(){var t=1;U="",a(this,"td,th",R,B.length+P.length,function(e,n,o){U+="<column-"+t+">"+p(e,n,o)+"</column-"+t+">",t++}),U.length>0&&"<column-1></column-1>"!=U&&($+='<row id="'+_+'">'+U+"</row>",_++),R++}),$+="</data></tabledata>",D.consoleLog===!0&&console.log($),"string"===D.outputMode)return $;if("base64"===D.outputMode)return j($);try{M=new Blob([$],{type:"application/xml;charset=utf-8"}),saveAs(M,D.fileName+".xml"),D.postCallback()}catch(X){N(D.fileName+".xml","data:application/xml;charset=utf-8;base64,",$)}}else if("excel"==D.type||"xls"==D.type||"word"==D.type||"doc"==D.type){var Q="excel"==D.type||"xls"==D.type?"excel":"word",Y="excel"==Q?"xls":"doc",G='xmlns:x="urn:schemas-microsoft-com:office:'+Q+'"',Z=t(L).filter(function(){return"none"!=t(this).data("tableexportDisplay")&&(t(this).is(":visible")||"always"==t(this).data("tableexportDisplay"))}),tt="";Z.each(function(){var e=t(this);R=0,H=n(this),tt+="<table><thead>",B=e.find("thead").first().find(D.theadSelector),B.each(function(){U="",a(this,"th,td",R,B.length,function(e,n,o){if(null!==e){var a="";U+="<th";for(var i in D.excelstyles)if(D.excelstyles.hasOwnProperty(i)){var r=t(e).css(D.excelstyles[i]);""!==r&&"0px none rgb(0, 0, 0)"!=r&&"rgba(0, 0, 0, 0)"!=r&&(a+=""===a?'style="':";",a+=D.excelstyles[i]+":"+r)}""!==a&&(U+=" "+a+'"'),t(e).is("[colspan]")&&(U+=' colspan="'+t(e).attr("colspan")+'"'),t(e).is("[rowspan]")&&(U+=' rowspan="'+t(e).attr("rowspan")+'"'),U+=">"+p(e,n,o)+"</th>"}}),U.length>0&&(tt+="<tr>"+U+"</tr>"),R++}),tt+="</thead><tbody>",e.find("tbody").each(function(){P.push.apply(P,t(this).find(D.tbodySelector))}),D.tfootSelector.length&&P.push.apply(P,e.find("tfoot").find(D.tfootSelector)),t(P).each(function(){var e=t(this);U="",a(this,"td,th",R,B.length+P.length,function(n,o,a){if(null!==n){var i="",r=t(n).data("tableexportMsonumberformat");"undefined"==typeof r&&"function"==typeof D.onMsoNumberFormat&&(r=D.onMsoNumberFormat(n,o,a)),"undefined"!=typeof r&&""!==r&&(i="style=\"mso-number-format:'"+r+"'");for(var l in D.excelstyles)D.excelstyles.hasOwnProperty(l)&&(r=t(n).css(D.excelstyles[l]),""===r&&(r=e.css(D.excelstyles[l])),""!==r&&"0px none rgb(0, 0, 0)"!=r&&"rgba(0, 0, 0, 0)"!=r&&(i+=""===i?'style="':";",i+=D.excelstyles[l]+":"+r));U+="<td",""!==i&&(U+=" "+i+'"'),t(n).is("[colspan]")&&(U+=' colspan="'+t(n).attr("colspan")+'"'),t(n).is("[rowspan]")&&(U+=' rowspan="'+t(n).attr("rowspan")+'"'),U+=">"+p(n,o,a).replace(/\n/g,"<br>")+"</td>"}}),U.length>0&&(tt+="<tr>"+U+"</tr>"),R++}),D.displayTableName&&(tt+="<tr><td></td></tr><tr><td></td></tr><tr><td>"+p(t("<p>"+D.tableName+"</p>"))+"</td></tr>"),tt+="</tbody></table>",D.consoleLog===!0&&console.log(tt)});var et='<html xmlns:o="urn:schemas-microsoft-com:office:office" '+G+' xmlns="http://www.w3.org/TR/REC-html40">';if(et+='<meta http-equiv="content-type" content="application/vnd.ms-'+Q+'; charset=UTF-8">',et+="<head>","excel"===Q&&(et+="<!--[if gte mso 9]>",et+="<xml>",et+="<x:ExcelWorkbook>",et+="<x:ExcelWorksheets>",et+="<x:ExcelWorksheet>",et+="<x:Name>",et+=D.worksheetName,et+="</x:Name>",et+="<x:WorksheetOptions>",et+="<x:DisplayGridlines/>",et+="</x:WorksheetOptions>",et+="</x:ExcelWorksheet>",et+="</x:ExcelWorksheets>",et+="</x:ExcelWorkbook>",et+="</xml>",et+="<![endif]-->"),et+="<style>br {mso-data-placement:same-cell;}</style>",et+="</head>",et+="<body>",et+=tt,et+="</body>",et+="</html>",D.consoleLog===!0&&console.log(et),"string"===D.outputMode)return et;if("base64"===D.outputMode)return j(et);try{M=new Blob([et],{type:"application/vnd.ms-"+D.type}),saveAs(M,D.fileName+"."+Y),D.postCallback()}catch(X){N(D.fileName+"."+Y,"data:application/vnd.ms-"+Q+";base64,",et)}}else if("xlsx"==D.type){var nt=[],ot=[];R=0,P=t(L).find("thead").first().find(D.theadSelector),t(L).find("tbody").each(function(){P.push.apply(P,t(this).find(D.tbodySelector))}),D.tfootSelector.length&&P.push.apply(P,t(L).find("tfoot").find(D.tfootSelector)),t(P).each(function(){var t=[];a(this,"th,td",R,P.length,function(e,n,o){if("undefined"!=typeof e&&null!==e){var a=parseInt(e.getAttribute("colspan")),i=parseInt(e.getAttribute("rowspan")),r=p(e,n,o);if(""!==r&&r==+r&&(r=+r),ot.forEach(function(e){if(R>=e.s.r&&R<=e.e.r&&t.length>=e.s.c&&t.length<=e.e.c)for(var n=0;n<=e.e.c-e.s.c;++n)t.push(null)}),(i||a)&&(i=i||1,a=a||1,ot.push({s:{r:R,c:t.length},e:{r:R+i-1,c:t.length+a-1}})),t.push(""!==r?r:null),a)for(var l=0;a-1>l;++l)t.push(null)}}),nt.push(t),R++});var at=new x,it=k(nt);it["!merges"]=ot,at.SheetNames.push(D.worksheetName),at.Sheets[D.worksheetName]=it;var rt=XLSX.write(at,{bookType:D.type,bookSST:!1,type:"binary"});try{M=new Blob([S(rt)],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8"}),saveAs(M,D.fileName+"."+D.type),D.postCallback()}catch(X){N(D.fileName+"."+D.type,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8",nt)}}else if("png"==D.type)html2canvas(t(L)[0]).then(function(t){for(var e=t.toDataURL(),n=atob(e.substring(22)),o=new ArrayBuffer(n.length),a=new Uint8Array(o),i=0;i<n.length;i++)a[i]=n.charCodeAt(i);if(D.consoleLog===!0&&console.log(n),"string"===D.outputMode)return n;if("base64"===D.outputMode)return j(e);if("window"===D.outputMode)return void window.open(e);try{M=new Blob([o],{type:"image/png"}),saveAs(M,D.fileName+".png"),D.postCallback()}catch(r){N(D.fileName+".png","data:image/png,",e)}});else if("pdf"==D.type)if(D.pdfmake.enabled===!0){var lt=[],st=[];R=0,B=t(this).find("thead").first().find(D.theadSelector),B.each(function(){var t=[];a(this,"th,td",R,B.length,function(e,n,o){t.push(p(e,n,o))}),t.length&&st.push(t);for(var e=lt.length;e<t.length;e++)lt.push("*");R++}),t(this).find("tbody").each(function(){P.push.apply(P,t(this).find(D.tbodySelector))}),D.tfootSelector.length&&P.push.apply(P,t(this).find("tfoot").find(D.tfootSelector)),t(P).each(function(){var t=[];a(this,"td,th",R,B.length+P.length,function(e,n,o){t.push(p(e,n,o))}),t.length&&st.push(t),R++});var ft={pageOrientation:"landscape",content:[{table:{headerRows:B.length,widths:lt,body:st}}]};pdfMake.createPdf(ft).getBuffer(function(t){try{var e=new Blob([t],{type:"application/pdf"});saveAs(e,D.fileName+".pdf"),D.postCallback()}catch(n){N(D.fileName+".pdf","data:application/pdf;base64,",t)}})}else if(D.jspdf.autotable===!1){var ct={dim:{w:w(t(L).first().get(0),"width","mm"),h:w(t(L).first().get(0),"height","mm")},pagesplit:!1},dt=new jsPDF(D.jspdf.orientation,D.jspdf.unit,D.jspdf.format);dt.addHTML(t(L).first(),D.jspdf.margins.left,D.jspdf.margins.top,ct,function(){i(dt)})}else{var ht=D.jspdf.autotable.tableExport;if("string"==typeof D.jspdf.format&&"bestfit"===D.jspdf.format.toLowerCase()){var ut={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]},pt="",yt="",gt=0;t(L).filter(":visible").each(function(){if("none"!=t(this).css("display")){var e=w(t(this).get(0),"width","pt");if(e>gt){e>ut.a0[0]&&(pt="a0",yt="l");for(var n in ut)ut.hasOwnProperty(n)&&ut[n][1]>e&&(pt=n,yt="l",ut[n][0]>e&&(yt="p"));gt=e}}}),D.jspdf.format=""===pt?"a4":pt,D.jspdf.orientation=""===yt?"w":yt}ht.doc=new jsPDF(D.jspdf.orientation,D.jspdf.unit,D.jspdf.format),ht.outputImages===!0&&(ht.images={}),"undefined"!=typeof ht.images&&(t(L).filter(function(){return"none"!=t(this).data("tableexportDisplay")&&(t(this).is(":visible")||"always"==t(this).data("tableexportDisplay"))}).each(function(){var e=0;B=t(this).find("thead").find(D.theadSelector),t(this).find("tbody").each(function(){P.push.apply(P,t(this).find(D.tbodySelector))}),D.tfootSelector.length&&P.push.apply(P,t(this).find("tfoot").find(D.tfootSelector)),t(P).each(function(){a(this,"td,th",B.length+e,B.length+P.length,function(e,n,o){if("undefined"!=typeof e&&null!==e){var a=t(e).children();"undefined"!=typeof a&&a.length>0&&l(e,a,ht)}}),e++})}),B=[],P=[]),s(ht,function(e){t(L).filter(function(){return"none"!=t(this).data("tableexportDisplay")&&(t(this).is(":visible")||"always"==t(this).data("tableexportDisplay"))}).each(function(){var e,o=0;if(H=n(this),ht.columns=[],ht.rows=[],ht.rowoptions={},"function"==typeof ht.onTable&&ht.onTable(t(this),D)===!1)return!0;D.jspdf.autotable.tableExport=null;var i=t.extend(!0,{},D.jspdf.autotable);D.jspdf.autotable.tableExport=ht,i.margin={},t.extend(!0,i.margin,D.jspdf.margins),i.tableExport=ht,"function"!=typeof i.beforePageContent&&(i.beforePageContent=function(t){if(1==t.pageCount){var e=t.table.rows.concat(t.table.headerRow);e.forEach(function(e){e.height>0&&(e.height+=(2-O)/2*e.styles.fontSize,t.table.height+=(2-O)/2*e.styles.fontSize)})}}),"function"!=typeof i.createdHeaderCell&&(i.createdHeaderCell=function(e,n){if(e.styles=t.extend({},n.row.styles),"undefined"!=typeof ht.columns[n.column.dataKey]){var o=ht.columns[n.column.dataKey];if("undefined"!=typeof o.rect){var a;e.contentWidth=o.rect.width,("undefined"==typeof ht.heightRatio||0===ht.heightRatio)&&(a=n.row.raw[n.column.dataKey].rowspan?n.row.raw[n.column.dataKey].rect.height/n.row.raw[n.column.dataKey].rowspan:n.row.raw[n.column.dataKey].rect.height,ht.heightRatio=e.styles.rowHeight/a),a=n.row.raw[n.column.dataKey].rect.height*ht.heightRatio,a>e.styles.rowHeight&&(e.styles.rowHeight=a)}"undefined"!=typeof o.style&&o.style.hidden!==!0&&(e.styles.halign=o.style.align,"inherit"===i.styles.fillColor&&(e.styles.fillColor=o.style.bcolor),"inherit"===i.styles.textColor&&(e.styles.textColor=o.style.color),"inherit"===i.styles.fontStyle&&(e.styles.fontStyle=o.style.fstyle))}}),"function"!=typeof i.createdCell&&(i.createdCell=function(t,e){var n=ht.rowoptions[e.row.index+":"+e.column.dataKey];"undefined"!=typeof n&&"undefined"!=typeof n.style&&n.style.hidden!==!0&&(t.styles.halign=n.style.align,"inherit"===i.styles.fillColor&&(t.styles.fillColor=n.style.bcolor),"inherit"===i.styles.textColor&&(t.styles.textColor=n.style.color),"inherit"===i.styles.fontStyle&&(t.styles.fontStyle=n.style.fstyle))}),"function"!=typeof i.drawHeaderCell&&(i.drawHeaderCell=function(t,e){var n=ht.columns[e.column.dataKey];return(n.style.hasOwnProperty("hidden")!==!0||n.style.hidden!==!0)&&n.rowIndex>=0?r(t,e,n):!1}),"function"!=typeof i.drawCell&&(i.drawCell=function(t,e){var n=ht.rowoptions[e.row.index+":"+e.column.dataKey];if(r(t,e,n)){if(ht.doc.rect(t.x,t.y,t.width,t.height,t.styles.fillStyle),"undefined"!=typeof n&&"undefined"!=typeof n.kids&&n.kids.length>0){var o=t.height/n.rect.height;(o>ht.dh||"undefined"==typeof ht.dh)&&(ht.dh=o),ht.dw=t.width/n.rect.width,f(t,n.kids,ht)}ht.doc.autoTableText(t.text,t.textPos.x,t.textPos.y,{halign:t.styles.halign,valign:t.styles.valign})}return!1}),ht.headerrows=[],B=t(this).find("thead").find(D.theadSelector),B.each(function(){e=0,ht.headerrows[o]=[],a(this,"th,td",o,B.length,function(t,n,a){var i=m(t);i.title=p(t,n,a),i.key=e++,i.rowIndex=o,ht.headerrows[o].push(i)}),o++}),o>0&&t.each(ht.headerrows[o-1],function(){var t=this;o>1&&null===this.rect&&(t=ht.headerrows[o-2][this.key]),null!==t&&ht.columns.push(t)});var l=0;P=[],t(this).find("tbody").each(function(){P.push.apply(P,t(this).find(D.tbodySelector))}),D.tfootSelector.length&&P.push.apply(P,t(this).find("tfoot").find(D.tfootSelector)),t(P).each(function(){var n=[];e=0,a(this,"td,th",o,B.length+P.length,function(o,a,i){if("undefined"==typeof ht.columns[e]){var r={title:"",key:e,style:{hidden:!0}};ht.columns.push(r)}if("undefined"!=typeof o&&null!==o){var r=m(o);r.kids=t(o).children(),ht.rowoptions[l+":"+e++]=r}else{var r=t.extend(!0,{},ht.rowoptions[l+":"+(e-1)]);r.colspan=-1,ht.rowoptions[l+":"+e++]=r}n.push(p(o,a,i))}),n.length&&(ht.rows.push(n),l++),o++}),"function"==typeof ht.onBeforeAutotable&&ht.onBeforeAutotable(t(this),ht.columns,ht.rows,i),ht.doc.autoTable(ht.columns,ht.rows,i),"function"==typeof ht.onAfterAutotable&&ht.onAfterAutotable(t(this),i),D.jspdf.autotable.startY=ht.doc.autoTableEndPosY()+i.margin.top}),i(ht.doc),"undefined"!=typeof ht.headerrows&&(ht.headerrows.length=0),"undefined"!=typeof ht.columns&&(ht.columns.length=0),"undefined"!=typeof ht.rows&&(ht.rows.length=0),delete ht.doc,ht.doc=null})}return this}})}(jQuery);