diff --git a/tableExport.js b/tableExport.js index 66d7268e..8c751da0 100644 --- a/tableExport.js +++ b/tableExport.js @@ -805,37 +805,51 @@ var body = []; rowIndex = 0; - $hrows = $(this).find('thead').first().find(defaults.theadSelector); - $hrows.each(function () { - var h = []; + var CollectPdfmakeData = function ($rows, colselector, length) { + var rlength = 0; - ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length, - function (cell, row, col) { - if (typeof cell !== 'undefined' && cell !== null) { + $rows.each(function () { + var r = []; + + ForEachVisibleCell(this, colselector, rowIndex, length, + function (cell, row, col) { + if (typeof cell !== 'undefined' && cell !== null) { - var colspan = parseInt(cell.getAttribute('colspan')); - var rowspan = parseInt(cell.getAttribute('rowspan')); + var colspan = parseInt(cell.getAttribute('colspan')); + var rowspan = parseInt(cell.getAttribute('rowspan')); - var cellValue = parseString(cell, row, col); + var cellValue = parseString(cell, row, col) || " "; - if (colspan > 1 || rowspan > 1) { - colspan = colspan || 1; - rowspan = rowspan || 1; - h.push({colSpan: colspan, rowSpan: rowspan, text: cellValue}); + if (colspan > 1 || rowspan > 1) { + colspan = colspan || 1; + rowspan = rowspan || 1; + r.push({colSpan: colspan, rowSpan: rowspan, text: cellValue}); + } + else + r.push(cellValue); } else - h.push(cellValue); - } - }); + r.push(" "); + }); - if (h.length) - body.push(h); + if (r.length) + body.push(r); - for(var i = widths.length; i < h.length;i++) - widths.push("*"); + if ( rlength < r.length ) + rlength = r.length; - rowIndex++; - }); + rowIndex++; + }); + + return rlength; + } + + $hrows = $(this).find('thead').first().find(defaults.theadSelector); + + var colcount = CollectPdfmakeData ($hrows, 'th,td', $hrows.length); + + for(var i = widths.length; i < colcount;i++) + widths.push("*"); $(this).find('tbody').each(function() { $rows.push.apply ($rows, $(this).find(defaults.tbodySelector)); @@ -843,33 +857,7 @@ if (defaults.tfootSelector.length) $rows.push.apply ($rows, $(this).find('tfoot').find(defaults.tfootSelector)); - $($rows).each(function () { - var r = []; - - ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length, - function (cell, row, col) { - if (typeof cell !== 'undefined' && cell !== null) { - var colspan = parseInt(cell.getAttribute('colspan')); - var rowspan = parseInt(cell.getAttribute('rowspan')); - - var cellValue = parseString(cell, row, col) || " "; - - if (colspan > 1 || rowspan > 1) { - colspan = colspan || 1; - rowspan = rowspan || 1; - r.push({colSpan: colspan, rowSpan: rowspan, text: cellValue}); - } - else - r.push(cellValue); - } - else - r.push(" "); - }); - - if (r.length) - body.push(r); - rowIndex++; - }); + CollectPdfmakeData ($rows, 'th,td', $hrows.length + $rows.length); var docDefinition = { content: [ { table: { @@ -1323,47 +1311,52 @@ }).find(selector); var rowColspan = 0; - var rowColIndex = 0; $row.each(function (colIndex) { if ($(this).data("tableexport-display") == 'always' || ($(this).css('display') != 'none' && $(this).css('visibility') != 'hidden' && $(this).data("tableexport-display") != 'none')) { - if (isColumnIgnored($row, colIndex) === false) { - if (typeof (cellcallback) === "function") { - var c, Colspan = 0; - var r, Rowspan = 0; - - // handle rowspans from previous rows - if (typeof rowspans[rowIndex] != 'undefined' && rowspans[rowIndex].length > 0) { - for (c = 0; c <= colIndex; c++) { - if (typeof rowspans[rowIndex][c] != 'undefined') { - cellcallback(null, rowIndex, c); - delete rowspans[rowIndex][c]; - colIndex++; - } + if (typeof (cellcallback) === "function") { + var c, Colspan = 1; + var r, Rowspan = 1; + + // handle rowspans from previous rows + if (typeof rowspans[rowIndex] != 'undefined' && rowspans[rowIndex].length > 0) { + var colCount = colIndex; + for (c = 0; c <= colCount; c++) { + if (typeof rowspans[rowIndex][c] != 'undefined') { + cellcallback(null, rowIndex, c); + delete rowspans[rowIndex][c]; + colCount++; } } - rowColIndex = colIndex; + colIndex += rowspans[rowIndex].length; + } + if (isColumnIgnored($row, colIndex + rowColspan) === false) { if ($(this).is("[colspan]")) { - Colspan = parseInt($(this).attr('colspan')); + Colspan = parseInt($(this).attr('colspan')) || 1; + + for (c = 1; c < Colspan; c++) + if (isColumnIgnored($row, colIndex + c) === true) + Colspan--; + rowColspan += Colspan > 0 ? Colspan - 1 : 0; } if ($(this).is("[rowspan]")) - Rowspan = parseInt($(this).attr('rowspan')); + Rowspan = parseInt($(this).attr('rowspan')) || 1; // output content of current cell cellcallback(this, rowIndex, colIndex); // handle colspan of current cell - for (c = 0; c < Colspan - 1; c++) + for (c = 1; c < Colspan; c++) cellcallback(null, rowIndex, colIndex + c); // store rowspan for following rows - if (Rowspan) { + if (Rowspan > 1) { for (r = 1; r < Rowspan; r++) { if (typeof rowspans[rowIndex + r] == 'undefined') rowspans[rowIndex + r] = []; diff --git a/tableExport.min.js b/tableExport.min.js index b4fa4955..8885eeb0 100644 --- a/tableExport.min.js +++ b/tableExport.min.js @@ -7,64 +7,64 @@ Licensed under the MIT License, http://opensource.org/licenses/mit-license */ -(function(c){c.fn.extend({tableExport:function(t){function O(b){var a=[];c(b).find("thead").first().find("th").each(function(b,e){void 0!==c(e).attr("data-field")?a[b]=c(e).attr("data-field"):a[b]=b.toString()});return a}function z(b,e,d,h,k){if(-1==c.inArray(d,a.ignoreRow)&&-1==c.inArray(d-h,a.ignoreRow)){var l=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(e), -m=0;l.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")){var e=b,h=!1;0e&&"undefined"!=typeof I[e]&&-1!=c.inArray(I[e],a.ignoreColumn)&&(h=!0):"number"!=typeof a.ignoreColumn[0]||-1==c.inArray(e,a.ignoreColumn)&&-1==c.inArray(e-l.length,a.ignoreColumn)||(h=!0));if(!1===h&&"function"===typeof k){var h= -0,p,f=0;if("undefined"!=typeof B[d]&&0l&&(v=Math.min(b.width, -this.width),g=this.height*v/this.width);v*=p;g*=p;gb.textPos.x&&e+f>b.textPos.x+b.width){if(0<=".,!%*;:=-".indexOf(v.charAt(0))){var g=v.charAt(0),f=d.doc.getStringUnitWidth(g)*d.doc.internal.getFontSize(); -e+f<=b.textPos.x+b.width&&(d.doc.autoTableText(g,e,k,l),v=v.substring(1,v.length));f=d.doc.getStringUnitWidth(v)*d.doc.internal.getFontSize()}e=b.textPos.x;k+=d.doc.internal.getFontSize()}for(;v.length&&e+f>b.textPos.x+b.width;)v=v.substring(0,v.length-1),f=d.doc.getStringUnitWidth(v)*d.doc.internal.getFontSize();d.doc.autoTableText(v,e,k,l);e+=f}if(m||p)c(a).is("b")?m=!1:c(a).is("i")&&(p=!1),d.doc.setFontType(m||p?m?"bold":"italic":"normal");a=a.nextSibling}b.textPos.x=e;b.textPos.y=k}else d.doc.autoTableText(b.text, -b.textPos.x,b.textPos.y,l)}}function R(b,a,d){return b.replace(new RegExp(a.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),d)}function U(b){b=R(b||"0",a.numbers.html.thousandsSeparator,"");b=R(b,a.numbers.html.decimalMark,".");return"number"===typeof b||!1!==jQuery.isNumeric(b)?b:!1}function y(b,e,d){var h="";if(null!==b){var k=c(b);if(k[0].hasAttribute("data-tableexport-value"))var l=k.data("tableexport-value");else if(l=k.html(),"function"===typeof a.onCellHtmlData)l=a.onCellHtmlData(k,e,d, -l);else if(""!=l){b=c.parseHTML(l);var m=0,p=0;l="";c.each(b,function(){if(c(this).is("input"))l+=k.find("input").eq(m++).val();else if(c(this).is("select"))l+=k.find("select option:selected").eq(p++).text();else if("undefined"===typeof c(this).html())l+=c(this).text();else if(void 0===jQuery().bootstrapTable||!0!==c(this).hasClass("filterControl"))l+=c(this).html()})}if(!0===a.htmlContent)h=c.trim(l);else if(""!=l){var f=l.replace(/\n/g,"\u2028").replace(//gi,"\u2060");b=c("
").html(f).contents(); -f="";c.each(b.text().split("\u2028"),function(b,a){0b?"-":"")+(a.numbers.output.thousandsSeparator?(n?g[0].substr(0,n)+a.numbers.output.thousandsSeparator:"")+g[0].substr(n).replace(/(\d{3})(?=\d)/g,"$1"+a.numbers.output.thousandsSeparator):g[0])+(g[1].length?a.numbers.output.decimalMark+g[1]:"")}}!0===a.escape&&(h=escape(h));"function"===typeof a.onCellData&&(h=a.onCellData(k,e,d,h))}return h}function pa(b,a,d){return a+"-"+d.toLowerCase()}function P(b,a){var e=/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.exec(b),c=a;e&&(c= -[parseInt(e[1]),parseInt(e[2]),parseInt(e[3])]);return c}function ja(b){var a=G(b,"text-align"),d=G(b,"font-weight"),h=G(b,"font-style"),k="";"start"==a&&(a="rtl"==G(b,"direction")?"right":"left");700<=d&&(k="bold");"italic"==h&&(k+=h);""===k&&(k="normal");a={style:{align:a,bcolor:P(G(b,"background-color"),[255,255,255]),color:P(G(b,"color"),[0,0,0]),fstyle:k},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 G(b,a){try{return window.getComputedStyle?(a=a.replace(/([a-z])([A-Z])/,pa),window.getComputedStyle(b,null).getPropertyValue(a)):b.currentStyle?b.currentStyle[a]:b.style[a]}catch(d){}return""}function Q(a,e,d){e=G(a,e).match(/\d+/);if(null!==e){e=e[0];a=a.parentElement;var b=document.createElement("div");b.style.overflow="hidden";b.style.visibility="hidden";a.appendChild(b);b.style.width=100+d;d=100/b.offsetWidth;a.removeChild(b);return e*d}return 0}function V(){if(!(this instanceof -V))return new V;this.SheetNames=[];this.Sheets={}}function qa(a){for(var b=new ArrayBuffer(a.length),d=new Uint8Array(b),c=0;c!=a.length;++c)d[c]=a.charCodeAt(c)&255;return b}function ra(a){for(var b={},d={s:{c:1E7,r:1E7},e:{c:0,r:0}},c=0;c!=a.length;++c)for(var k=0;k!=a[c].length;++k){d.s.r>c&&(d.s.r=c);d.s.c>k&&(d.s.c=k);d.e.rd.s.c&&(b["!ref"]=XLSX.utils.encode_range(d));return b}function ga(a){var b=0,d;if(0===a.length)return b;var c=0;for(d=a.length;cf?k+=String.fromCharCode(f): -(127f?k+=String.fromCharCode(f>>6|192):(k+=String.fromCharCode(f>>12|224),k+=String.fromCharCode(f>>6&63|128)),k+=String.fromCharCode(f&63|128))}for(a=k;h>2;m=(m&3)<<4|k>>4;var p=(k&15)<<2|c>>6;var g=c&63;isNaN(k)?p=g=64:isNaN(c)&&(g=64);b=b+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(f)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(m)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(p)+ -"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g)}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"},w=this,S=null,u=[],g=[],q=0,B=[],n="",I=[];c.extend(!0,a,t);I=O(w);if("csv"==a.type||"tsv"==a.type||"txt"==a.type){var E="",J=0,q=0,W=function(b,e,d){b.each(function(){n="";z(this,e,q,d+b.length,function(b,c,e){var d=n,f="";if(null!==b)if(b=y(b,c,e),c=null===b||""===b?"":b.toString(),"tsv"==a.type)b instanceof Date&&b.toLocaleString(),f=R(c, -"\t"," ");else if(b instanceof Date)f=a.csvEnclosure+b.toLocaleString()+a.csvEnclosure;else if(f=R(c,a.csvEnclosure,a.csvEnclosure+a.csvEnclosure),0<=f.indexOf(a.csvSeparator)||/[\r\n ]/g.test(f))f=a.csvEnclosure+f+a.csvEnclosure;n=d+(f+("tsv"==a.type?"\t":a.csvSeparator))});n=c.trim(n).substring(0,n.length-1);0"+y(a,c,d)+""});q++});D+="";var ka=1;c(w).find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,c(w).find("tfoot").find(a.tfootSelector));c(g).each(function(){var a=1;n="";z(this,"td,th",q,u.length+g.length,function(b,c,f){n+=""+y(b,c,f)+"";a++});0"!= -n&&(D+=''+n+"",ka++);q++});D+="";!0===a.consoleLog&&console.log(D);if("string"===a.outputMode)return D;if("base64"===a.outputMode)return F(D);try{A=new Blob([D],{type:"application/xml;charset=utf-8"}),saveAs(A,a.fileName+".xml")}catch(b){C(a.fileName+".xml","data:application/xml;charset=utf-8;base64,",D)}}else if("excel"===a.type&&"xmlss"===a.excelFileFormat){var Y=c(w).filter(function(){return"none"!=c(this).data("tableexport-display")&&(c(this).is(":visible")|| -"always"==c(this).data("tableexport-display"))});var Z=[];Y.each(function(){var b=c(this),e="";q=0;I=O(this);u=b.find("thead").first().find(a.theadSelector);var e=e+"",d=0;u.each(function(){n="";z(this,"th,td",q,u.length,function(a,b,c){null!==a&&(n+=''+y(a,b,c)+"",d++)});0"+n+"");q++});g=[];b.find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});c(g).each(function(){c(this);n="";z(this,"td,th",q, -u.length+g.length,function(a,b,c){if(null!==a){var e="String",d="";a=y(a,b,c);!1!==jQuery.isNumeric(a)?e="Number":(b=a,-1"));n+="'+a+""}});0"+n+"");q++});e+="
";Z.push(e);!0===a.consoleLog&&console.log(e)});t=(new Date).toISOString();var r=' '+ -t+' 9000 13860 0 0 False False '; -for(t=0;t'+Z[t]+" ";r+="";!0===a.consoleLog&&console.log(r);if("string"===a.outputMode)return r;if("base64"===a.outputMode)return F(r);try{A=new Blob([r],{type:"application/xml;charset=utf-8"}),saveAs(A,a.fileName+".xml")}catch(b){C(a.fileName+".xml","data:application/xml;charset=utf-8;base64,", -D)}}else if("excel"==a.type||"xls"==a.type||"word"==a.type||"doc"==a.type){t="excel"==a.type||"xls"==a.type?"excel":"word";var L="excel"==t?"xls":"doc";r='xmlns:x="urn:schemas-microsoft-com:office:'+t+'"';Y=c(w).filter(function(){return"none"!=c(this).data("tableexport-display")&&(c(this).is(":visible")||"always"==c(this).data("tableexport-display"))});var H="";Y.each(function(){var b=c(this);q=0;I=O(this);H+="";u=b.find("thead").first().find(a.theadSelector);u.each(function(){n=""; -z(this,"th,td",q,u.length,function(b,d,f){if(null!==b){var e="";n+=""}});0"+n+"");q++});H+= -"";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);n="";z(this,"td,th",q,u.length+g.length,function(e,f,g){if(null!==e){var d="",m=c(e).data("tableexport-msonumberformat");"undefined"==typeof m&&"function"===typeof a.onMsoNumberFormat&&(m=a.onMsoNumberFormat(e,f,g));"undefined"!=typeof m&&""!==m&&(d="style=\"mso-number-format:'"+m+"'");for(var p in a.excelstyles)a.excelstyles.hasOwnProperty(p)&& -(m=c(e).css(a.excelstyles[p]),""===m&&(m=b.css(a.excelstyles[p])),""!==m&&"0px none rgb(0, 0, 0)"!=m&&"rgba(0, 0, 0, 0)"!=m&&(d+=""===d?'style="':";",d+=a.excelstyles[p]+":"+m));n+="")+""}});0"+n+"");q++});a.displayTableName&&(H+="");H+="
"+y(c("

"+ -a.tableName+"

"))+"
";!0===a.consoleLog&&console.log(H)});r=''+('')+"";"excel"===t&&(r+="\x3c!--[if gte mso 9]>",r+="",r+="",r+="",r+="",r+="",r+=a.worksheetName,r+="",r+="",r+="", -r+="",r+="",r+="",r+="",r+="",r+="br {mso-data-placement:same-cell;}";r+="";r+="";r+=H;r+="";r+="";!0===a.consoleLog&&console.log(r);if("string"===a.outputMode)return r;if("base64"===a.outputMode)return F(r);try{A=new Blob([r],{type:"application/vnd.ms-"+a.type}),saveAs(A,a.fileName+"."+L)}catch(b){C(a.fileName+"."+L,"data:application/vnd.ms-"+t+";base64,", -r)}}else if("xlsx"==a.type){var la=[],aa=[],q=0,g=c(w).find("thead").first().find(a.theadSelector);c(w).find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,c(w).find("tfoot").find(a.tfootSelector));c(g).each(function(){var a=[];z(this,"th,td",q,g.length,function(b,c,f){if("undefined"!==typeof b&&null!==b){var e=parseInt(b.getAttribute("colspan")),d=parseInt(b.getAttribute("rowspan"));b=y(b,c,f);""!==b&&b==+b&&(b=+b);aa.forEach(function(b){if(q>= -b.s.r&&q<=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(d||e)e=e||1,aa.push({s:{r:q,c:a.length},e:{r:q+(d||1)-1,c:a.length+e-1}});a.push(""!==b?b:null);if(e)for(d=0;dna){a>M.a0[0]&&(T="a0",N="l");for(var e in M)M.hasOwnProperty(e)&&M[e][1]>a&&(T=e,N="l",M[e][0]>a&&(N="p"));na=a}}});a.jspdf.format=""===T?"a4":T;a.jspdf.orientation=""===N?"w":N}f.doc=new jsPDF(a.jspdf.orientation,a.jspdf.unit,a.jspdf.format);!0===f.outputImages&&(f.images={});"undefined"!=typeof f.images&&(c(w).filter(function(){return"none"!= -c(this).data("tableexport-display")&&(c(this).is(":visible")||"always"==c(this).data("tableexport-display"))}).each(function(){var b=0;u=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(){z(this,"td,th",u.length+b,u.length+g.length,function(a,b,g){"undefined"!==typeof a&&null!==a&&(b=c(a).children(),"undefined"!=typeof b&& -0a.styles.rowHeight&&(a.styles.rowHeight=e)}"undefined"!=typeof d.style&&!0!==d.style.hidden&&(a.styles.halign=d.style.align,"inherit"===h.styles.fillColor&&(a.styles.fillColor=d.style.bcolor), -"inherit"===h.styles.textColor&&(a.styles.textColor=d.style.color),"inherit"===h.styles.fontStyle&&(a.styles.fontStyle=d.style.fstyle))}});"function"!==typeof h.createdCell&&(h.createdCell=function(a,b){var c=f.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"===h.styles.fillColor&&(a.styles.fillColor=c.style.bcolor),"inherit"===h.styles.textColor&&(a.styles.textColor=c.style.color),"inherit"=== -h.styles.fontStyle&&(a.styles.fontStyle=c.style.fstyle))});"function"!==typeof h.drawHeaderCell&&(h.drawHeaderCell=function(a,b){var c=f.columns[b.column.dataKey];return(!0!==c.style.hasOwnProperty("hidden")||!0!==c.style.hidden)&&0<=c.rowIndex?ea(a,b,c):!1});"function"!==typeof h.drawCell&&(h.drawCell=function(a,b){var c=f.rowoptions[b.row.index+":"+b.column.dataKey];if(ea(a,b,c))if(f.doc.rect(a.x,a.y,a.width,a.height,a.styles.fillStyle),"undefined"!=typeof c&&"undefined"!=typeof c.kids&&0f.dh||"undefined"==typeof f.dh)f.dh=d;f.dw=a.width/c.rect.width;d=a.textPos.y;ha(a,c.kids,f);a.textPos.y=d;ia(a,c.kids,f)}else ia(a,{},f);return!1});f.headerrows=[];u=c(this).find("thead").find(a.theadSelector);u.each(function(){b=0;f.headerrows[d]=[];z(this,"th,td",d,u.length,function(a,c,e){var g=ja(a);g.title=y(a,c,e);g.key=b++;g.rowIndex=d;f.headerrows[d].push(g)});d++});if(0e&&"undefined"!=typeof J[e]&&-1!=c.inArray(J[e],a.ignoreColumn)&&(d=!0):"number"!=typeof a.ignoreColumn[0]||-1==c.inArray(e,a.ignoreColumn)&&-1==c.inArray(e-b.length,a.ignoreColumn)||(d= +!0));return d}function A(b,e,d,k,h){if(-1==c.inArray(d,a.ignoreRow)&&-1==c.inArray(d-k,a.ignoreRow)){var l=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(e),m=0;l.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 h){var a,e=1,k=1;if("undefined"!=typeof B[d]&&0l&&(v=Math.min(b.width,this.width),g=this.height*v/this.width);v*=p;g*=p;gb.textPos.x&&e+f>b.textPos.x+ +b.width){if(0<=".,!%*;:=-".indexOf(v.charAt(0))){var g=v.charAt(0),f=d.doc.getStringUnitWidth(g)*d.doc.internal.getFontSize();e+f<=b.textPos.x+b.width&&(d.doc.autoTableText(g,e,h,l),v=v.substring(1,v.length));f=d.doc.getStringUnitWidth(v)*d.doc.internal.getFontSize()}e=b.textPos.x;h+=d.doc.internal.getFontSize()}for(;v.length&&e+f>b.textPos.x+b.width;)v=v.substring(0,v.length-1),f=d.doc.getStringUnitWidth(v)*d.doc.internal.getFontSize();d.doc.autoTableText(v,e,h,l);e+=f}if(m||p)c(a).is("b")?m=!1: +c(a).is("i")&&(p=!1),d.doc.setFontType(m||p?m?"bold":"italic":"normal");a=a.nextSibling}b.textPos.x=e;b.textPos.y=h}else d.doc.autoTableText(b.text,b.textPos.x,b.textPos.y,l)}}function S(a,e,d){return a.replace(new RegExp(e.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),d)}function V(b){b=S(b||"0",a.numbers.html.thousandsSeparator,"");b=S(b,a.numbers.html.decimalMark,".");return"number"===typeof b||!1!==jQuery.isNumeric(b)?b:!1}function y(b,e,d){var k="";if(null!==b){var h=c(b);if(h[0].hasAttribute("data-tableexport-value"))var l= +h.data("tableexport-value");else if(l=h.html(),"function"===typeof a.onCellHtmlData)l=a.onCellHtmlData(h,e,d,l);else if(""!=l){b=c.parseHTML(l);var m=0,p=0;l="";c.each(b,function(){if(c(this).is("input"))l+=h.find("input").eq(m++).val();else if(c(this).is("select"))l+=h.find("select option:selected").eq(p++).text();else if("undefined"===typeof c(this).html())l+=c(this).text();else if(void 0===jQuery().bootstrapTable||!0!==c(this).hasClass("filterControl"))l+=c(this).html()})}if(!0===a.htmlContent)k= +c.trim(l);else if(""!=l){var f=l.replace(/\n/g,"\u2028").replace(//gi,"\u2060");b=c("
").html(f).contents();f="";c.each(b.text().split("\u2028"),function(a,b){0b?"-":"")+(a.numbers.output.thousandsSeparator?(n?g[0].substr(0,n)+a.numbers.output.thousandsSeparator:"")+g[0].substr(n).replace(/(\d{3})(?=\d)/g,"$1"+a.numbers.output.thousandsSeparator):g[0])+(g[1].length?a.numbers.output.decimalMark+g[1]:"")}}!0===a.escape&&(k=escape(k));"function"===typeof a.onCellData&&(k=a.onCellData(h,e,d,k))}return k}function pa(a, +e,d){return e+"-"+d.toLowerCase()}function Q(a,e){var b=/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.exec(a),c=e;b&&(c=[parseInt(b[1]),parseInt(b[2]),parseInt(b[3])]);return c}function ia(a){var b=G(a,"text-align"),d=G(a,"font-weight"),k=G(a,"font-style"),h="";"start"==b&&(b="rtl"==G(a,"direction")?"right":"left");700<=d&&(h="bold");"italic"==k&&(h+=k);""===h&&(h="normal");b={style:{align:b,bcolor:Q(G(a,"background-color"),[255,255,255]),color:Q(G(a,"color"),[0,0,0]),fstyle:h},colspan:parseInt(c(a).attr("colspan"))|| +0,rowspan:parseInt(c(a).attr("rowspan"))||0};null!==a&&(a=a.getBoundingClientRect(),b.rect={width:a.width,height:a.height});return b}function G(a,e){try{return window.getComputedStyle?(e=e.replace(/([a-z])([A-Z])/,pa),window.getComputedStyle(a,null).getPropertyValue(e)):a.currentStyle?a.currentStyle[e]:a.style[e]}catch(d){}return""}function R(a,e,d){e=G(a,e).match(/\d+/);if(null!==e){e=e[0];a=a.parentElement;var b=document.createElement("div");b.style.overflow="hidden";b.style.visibility="hidden"; +a.appendChild(b);b.style.width=100+d;d=100/b.offsetWidth;a.removeChild(b);return e*d}return 0}function W(){if(!(this instanceof W))return new W;this.SheetNames=[];this.Sheets={}}function qa(a){for(var b=new ArrayBuffer(a.length),d=new Uint8Array(b),c=0;c!=a.length;++c)d[c]=a.charCodeAt(c)&255;return b}function ra(a){for(var b={},d={s:{c:1E7,r:1E7},e:{c:0,r:0}},c=0;c!=a.length;++c)for(var h=0;h!=a[c].length;++h){d.s.r>c&&(d.s.r=c);d.s.c>h&&(d.s.c=h);d.e.rd.s.c&&(b["!ref"]=XLSX.utils.encode_range(d));return b}function fa(a){var b=0,c;if(0===a.length)return b;var k=0;for(c=a.length;kl?h+=String.fromCharCode(l):(127l?h+=String.fromCharCode(l>>6|192):(h+=String.fromCharCode(l>>12|224),h+=String.fromCharCode(l>>6&63|128)),h+=String.fromCharCode(l&63|128))}for(a=h;k>2;m=(m&3)<<4|h>>4;var p=(h&15)<<2|c>>6;var f=c&63;isNaN(h)?p=f=64:isNaN(c)&&(f=64);b=b+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(l)+ +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(m)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(p)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(f)}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"},w=this,T=null,u=[],g=[],t=0,B=[],n="",J=[];c.extend(!0,a,q);J=P(w);if("csv"==a.type||"tsv"==a.type||"txt"==a.type){var E="",K=0,t=0,X=function(b,e,d){b.each(function(){n="";A(this, +e,t,d+b.length,function(b,c,e){var d=n,h="";if(null!==b)if(b=y(b,c,e),c=null===b||""===b?"":b.toString(),"tsv"==a.type)b instanceof Date&&b.toLocaleString(),h=S(c,"\t"," ");else if(b instanceof Date)h=a.csvEnclosure+b.toLocaleString()+a.csvEnclosure;else if(h=S(c,a.csvEnclosure,a.csvEnclosure+a.csvEnclosure),0<=h.indexOf(a.csvSeparator)||/[\r\n ]/g.test(h))h=a.csvEnclosure+h+a.csvEnclosure;n=d+(h+("tsv"==a.type?"\t":a.csvSeparator))});n=c.trim(n).substring(0,n.length-1);0"+y(a,c,d)+""});t++});D+="";var ja=1;c(w).find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,c(w).find("tfoot").find(a.tfootSelector)); +c(g).each(function(){var a=1;n="";A(this,"td,th",t,u.length+g.length,function(b,c,k){n+=""+y(b,c,k)+"";a++});0"!=n&&(D+=''+n+"",ja++);t++});D+="";!0===a.consoleLog&&console.log(D);if("string"===a.outputMode)return D;if("base64"===a.outputMode)return F(D);try{z=new Blob([D],{type:"application/xml;charset=utf-8"}),saveAs(z,a.fileName+".xml")}catch(b){C(a.fileName+".xml","data:application/xml;charset=utf-8;base64,", +D)}}else if("excel"===a.type&&"xmlss"===a.excelFileFormat){var M=c(w).filter(function(){return"none"!=c(this).data("tableexport-display")&&(c(this).is(":visible")||"always"==c(this).data("tableexport-display"))});var Z=[];M.each(function(){var b=c(this),e="";t=0;J=P(this);u=b.find("thead").first().find(a.theadSelector);var e=e+"",d=0;u.each(function(){n="";A(this,"th,td",t,u.length,function(a,b,c){null!==a&&(n+=''+y(a,b,c)+"",d++)});0"+n+"");t++});g=[];b.find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});c(g).each(function(){c(this);n="";A(this,"td,th",t,u.length+g.length,function(a,b,c){if(null!==a){var e="String",d="";a=y(a,b,c);!1!==jQuery.isNumeric(a)?e="Number":(b=a,-1"));n+="'+a+""}}); +0"+n+"");t++});e+="
";Z.push(e);!0===a.consoleLog&&console.log(e)});q=(new Date).toISOString();var r=' '+ +q+' 9000 13860 0 0 False False '; +for(q=0;q'+Z[q]+" ";r+="";!0===a.consoleLog&&console.log(r);if("string"===a.outputMode)return r;if("base64"===a.outputMode)return F(r);try{z=new Blob([r],{type:"application/xml;charset=utf-8"}),saveAs(z,a.fileName+".xml")}catch(b){C(a.fileName+".xml","data:application/xml;charset=utf-8;base64,", +D)}}else if("excel"==a.type||"xls"==a.type||"word"==a.type||"doc"==a.type){q="excel"==a.type||"xls"==a.type?"excel":"word";var H="excel"==q?"xls":"doc";r='xmlns:x="urn:schemas-microsoft-com:office:'+q+'"';M=c(w).filter(function(){return"none"!=c(this).data("tableexport-display")&&(c(this).is(":visible")||"always"==c(this).data("tableexport-display"))});var I="";M.each(function(){var b=c(this);t=0;J=P(this);I+="";u=b.find("thead").first().find(a.theadSelector);u.each(function(){n=""; +A(this,"th,td",t,u.length,function(b,d,f){if(null!==b){var e="";n+=""}});0"+n+"");t++});I+= +"";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);n="";A(this,"td,th",t,u.length+g.length,function(d,e,h){if(null!==d){var f="",m=c(d).data("tableexport-msonumberformat");"undefined"==typeof m&&"function"===typeof a.onMsoNumberFormat&&(m=a.onMsoNumberFormat(d,e,h));"undefined"!=typeof m&&""!==m&&(f="style=\"mso-number-format:'"+m+"'");for(var p in a.excelstyles)a.excelstyles.hasOwnProperty(p)&& +(m=c(d).css(a.excelstyles[p]),""===m&&(m=b.css(a.excelstyles[p])),""!==m&&"0px none rgb(0, 0, 0)"!=m&&"rgba(0, 0, 0, 0)"!=m&&(f+=""===f?'style="':";",f+=a.excelstyles[p]+":"+m));n+="")+""}});0"+n+"");t++});a.displayTableName&&(I+="");I+="
"+y(c("

"+ +a.tableName+"

"))+"
";!0===a.consoleLog&&console.log(I)});r=''+('')+"";"excel"===q&&(r+="\x3c!--[if gte mso 9]>",r+="",r+="",r+="",r+="",r+="",r+=a.worksheetName,r+="",r+="",r+="", +r+="",r+="",r+="",r+="",r+="",r+="br {mso-data-placement:same-cell;}";r+="";r+="";r+=I;r+="";r+="";!0===a.consoleLog&&console.log(r);if("string"===a.outputMode)return r;if("base64"===a.outputMode)return F(r);try{z=new Blob([r],{type:"application/vnd.ms-"+a.type}),saveAs(z,a.fileName+"."+H)}catch(b){C(a.fileName+"."+H,"data:application/vnd.ms-"+q+";base64,", +r)}}else if("xlsx"==a.type){var ka=[],aa=[],t=0,g=c(w).find("thead").first().find(a.theadSelector);c(w).find("tbody").each(function(){g.push.apply(g,c(this).find(a.tbodySelector))});a.tfootSelector.length&&g.push.apply(g,c(w).find("tfoot").find(a.tfootSelector));c(g).each(function(){var a=[];A(this,"th,td",t,g.length,function(b,c,f){if("undefined"!==typeof b&&null!==b){var d=parseInt(b.getAttribute("colspan")),e=parseInt(b.getAttribute("rowspan"));b=y(b,c,f);""!==b&&b==+b&&(b=+b);aa.forEach(function(b){if(t>= +b.s.r&&t<=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(e||d)d=d||1,aa.push({s:{r:t,c:a.length},e:{r:t+(e||1)-1,c:a.length+d-1}});a.push(""!==b?b:null);if(d)for(e=0;ena){a>N.a0[0]&&(U="a0",O="l");for(var e in N)N.hasOwnProperty(e)&& +N[e][1]>a&&(U=e,O="l",N[e][0]>a&&(O="p"));na=a}}});a.jspdf.format=""===U?"a4":U;a.jspdf.orientation=""===O?"w":O}f.doc=new jsPDF(a.jspdf.orientation,a.jspdf.unit,a.jspdf.format);!0===f.outputImages&&(f.images={});"undefined"!=typeof f.images&&(c(w).filter(function(){return"none"!=c(this).data("tableexport-display")&&(c(this).is(":visible")||"always"==c(this).data("tableexport-display"))}).each(function(){var b=0;u=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(){A(this,"td,th",u.length+b,u.length+g.length,function(a,b,g){"undefined"!==typeof a&&null!==a&&(b=c(a).children(),"undefined"!=typeof b&&0a.styles.rowHeight&&(a.styles.rowHeight=e)}"undefined"!=typeof d.style&&!0!==d.style.hidden&&(a.styles.halign=d.style.align,"inherit"===k.styles.fillColor&&(a.styles.fillColor=d.style.bcolor),"inherit"===k.styles.textColor&&(a.styles.textColor=d.style.color),"inherit"===k.styles.fontStyle&&(a.styles.fontStyle=d.style.fstyle))}});"function"!==typeof k.createdCell&&(k.createdCell=function(a,b){var c=f.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"===k.styles.fillColor&&(a.styles.fillColor=c.style.bcolor),"inherit"===k.styles.textColor&&(a.styles.textColor=c.style.color),"inherit"===k.styles.fontStyle&&(a.styles.fontStyle=c.style.fstyle))});"function"!==typeof k.drawHeaderCell&&(k.drawHeaderCell=function(a,b){var c=f.columns[b.column.dataKey];return(!0!==c.style.hasOwnProperty("hidden")||!0!==c.style.hidden)&& +0<=c.rowIndex?da(a,b,c):!1});"function"!==typeof k.drawCell&&(k.drawCell=function(a,b){var c=f.rowoptions[b.row.index+":"+b.column.dataKey];if(da(a,b,c))if(f.doc.rect(a.x,a.y,a.width,a.height,a.styles.fillStyle),"undefined"!=typeof c&&"undefined"!=typeof c.kids&&0f.dh||"undefined"==typeof f.dh)f.dh=d;f.dw=a.width/c.rect.width;d=a.textPos.y;ga(a,c.kids,f);a.textPos.y=d;ha(a,c.kids,f)}else ha(a,{},f);return!1});f.headerrows=[];u=c(this).find("thead").find(a.theadSelector); +u.each(function(){b=0;f.headerrows[d]=[];A(this,"th,td",d,u.length,function(a,c,e){var g=ia(a);g.title=y(a,c,e);g.key=b++;g.rowIndex=d;f.headerrows[d].push(g)});d++});if(0 {type: 'pdf', jspdf: {autotable: {tableWidth: 'wrap'}}});"> PDF PDF (jsPDF-AutoTable issue60)) +
  • + PDF PDF (Issue 164: PDF(Make) don't support rowspan and colspan?)
  • Table with rowspan

    @@ -882,47 +886,47 @@

    Issue 53 II: complex table thead rowspan colspan

    - + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - + + + + - - - - + + + + - - - - + + + +
    col3 col4 col5col8col6 col7 col8
    x main1x main2x main3x main4x sub1-1x sub1-2x sub1-3x sub1-4r1 c1r1 c2r1 c3r1 c4r1 c5r1 c6r1 c7r1 c8
    y main1y main2y main3y main4y sub1-1y sub1-2y sub1-3y sub1-4r2 c1r2 c2r2 c3r2 c4r2 c5r2 c6r2 c7r2 c8
    y sub2-1y sub2-2y sub2-3y sub2-4r3 c5r3 c6r3 c7r3 c8
    y sub3-1y sub3-2y sub3-3y sub3-4r4 c5r4 c6r4 c7r4 c8
    y sub4-1y sub4-2y sub4-3y sub4-4r5 c5r5 c6r5 c7r5 c8
    @@ -1226,6 +1230,27 @@

    Issue 142: Omit tfoot from output

    +

    Issue 164: PDF(Make) don't support rowspan and colspan?

    + + + + + + + + + + + + + + + + + + +
    R1-C1R1-C2R1-C3
    R2-C1R2-C2R2-C3
    R3-C1R3-C2R3-C3
    +

    Countries and dependencies by population (font test)