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