diff --git a/tableExport.js b/tableExport.js index c3ef575..a55cd0d 100644 --- a/tableExport.js +++ b/tableExport.js @@ -1,7 +1,7 @@ /** * @preserve tableExport.jquery.plugin * - * Version 1.10.13 + * Version 1.10.14 * * Copyright (c) 2015-2019 hhurz, https://github.com/hhurz/tableExport.jquery.plugin * @@ -316,7 +316,10 @@ $($hrows).each(function () { ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length, function (cell, row, col) { - tdData += defaults.sql.columnEnclosure + parseString(cell, row, col) + defaults.sql.columnEnclosure + ","; + var colName = parseString(cell, row, col) || ''; + if ( colName.indexOf(defaults.sql.columnEnclosure) > -1 ) + colName = replaceAll(colName.toString(), defaults.sql.columnEnclosure, defaults.sql.columnEnclosure + defaults.sql.columnEnclosure); + tdData += defaults.sql.columnEnclosure + colName + defaults.sql.columnEnclosure + ","; }); rowIndex++; tdData = $.trim(tdData).substring(0, tdData.length - 1); @@ -329,7 +332,10 @@ trData = ""; ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length, function (cell, row, col) { - trData += "'" + parseString(cell, row, col) + "',"; + var dataString = parseString(cell, row, col) || ''; + if ( dataString.indexOf("'") > -1 ) + dataString = replaceAll(dataString.toString(), "'", "''"); + trData += "'" + dataString + "',"; }); if ( trData.length > 3 ) { tdData += "(" + trData; diff --git a/tableExport.min.js b/tableExport.min.js index dc6266a..307f046 100644 --- a/tableExport.min.js +++ b/tableExport.min.js @@ -1,7 +1,7 @@ /* tableExport.jquery.plugin - Version 1.10.13 + Version 1.10.14 Copyright (c) 2015-2019 hhurz, https://github.com/hhurz/tableExport.jquery.plugin @@ -16,25 +16,25 @@ $jscomp.polyfill("Array.prototype.find",function(c){return c?c:function(c,y){ret function S(b){var a=[];c(b).find("thead").first().find("th").each(function(b,d){void 0!==c(d).attr("data-field")?a[b]=c(d).attr("data-field"):a[b]=b.toString()});return a}function I(b){var a="undefined"!==typeof b[0].rowIndex,e=!1===a&&"undefined"!==typeof b[0].cellIndex,q=e||a?Ka(b):b.is(":visible"),f=b.attr("data-tableexport-display");e&&"none"!==f&&"always"!==f&&(b=c(b[0].parentNode),a="undefined"!==typeof b[0].rowIndex,f=b.attr("data-tableexport-display"));a&&"none"!==f&&"always"!==f&&(f=b.closest("table").attr("data-tableexport-display")); return"none"!==f&&(!0===q||"always"===f)}function Ka(b){var a=[];V&&(a=J.filter(function(){var a=!1;this.nodeType===b[0].nodeType&&("undefined"!==typeof this.rowIndex&&this.rowIndex===b[0].rowIndex?a=!0:"undefined"!==typeof this.cellIndex&&this.cellIndex===b[0].cellIndex&&"undefined"!==typeof this.parentNode.rowIndex&&"undefined"!==typeof b[0].parentNode.rowIndex&&this.parentNode.rowIndex===b[0].parentNode.rowIndex&&(a=!0));return a}));return!1===V||0===a.length}function ta(b,d,e){var q=!1;I(b)?0< a.ignoreColumn.length&&(-1!==c.inArray(e,a.ignoreColumn)||-1!==c.inArray(e-d,a.ignoreColumn)||T.length>e&&"undefined"!==typeof T[e]&&-1!==c.inArray(T[e],a.ignoreColumn))&&(q=!0):q=!0;return q}function E(b,d,e,q,f){if("function"===typeof f){var m=!1;"function"===typeof a.onIgnoreRow&&(m=a.onIgnoreRow(c(b),e));if(!1===m&&(0===a.ignoreRow.length||-1===c.inArray(e,a.ignoreRow)&&-1===c.inArray(e-q,a.ignoreRow))&&I(c(b))){var t=C(c(b),d),k=0;t.each(function(b){var a=c(this),d,m=O(this),q=U(this);c.each(G, -function(){if(e>=this.s.r&&e<=this.e.r&&k>=this.s.c&&k<=this.e.c)for(d=0;d<=this.e.c-this.s.c;++d)f(null,e,k++)});if(!1===ta(a,t.length,b)){if(q||m)m=m||1,G.push({s:{r:e,c:k},e:{r:e+(q||1)-1,c:k+m-1}});f(this,e,k++)}if(m)for(d=0;d=this.s.r&&e<=this.e.r&&k>=this.s.c&&k<=this.e.c)for(ca=0;ca<=this.e.c-this.s.c;++ca)f(null,e,k++)})}}}function ua(b,a,e,c){if("undefined"!==typeof c.images&&(e=c.images[e],"undefined"!==typeof e)){a=a.getBoundingClientRect(); +function(){if(e>=this.s.r&&e<=this.e.r&&k>=this.s.c&&k<=this.e.c)for(d=0;d<=this.e.c-this.s.c;++d)f(null,e,k++)});if(!1===ta(a,t.length,b)){if(q||m)m=m||1,G.push({s:{r:e,c:k},e:{r:e+(q||1)-1,c:k+m-1}});f(this,e,k++)}if(m)for(d=0;d=this.s.r&&e<=this.e.r&&k>=this.s.c&&k<=this.e.c)for(da=0;da<=this.e.c-this.s.c;++da)f(null,e,k++)})}}}function ua(b,a,e,c){if("undefined"!==typeof c.images&&(e=c.images[e],"undefined"!==typeof e)){a=a.getBoundingClientRect(); var d=b.width/b.height,m=a.width/a.height,q=b.width,k=b.height,z=19.049976/25.4,g=0;m<=d?(k=Math.min(b.height,a.height),q=a.width*k/a.height):m>d&&(q=Math.min(b.width,a.width),k=a.height*q/a.width);q*=z;k*=z;kb.textPos.x&&q+g>b.textPos.x+b.width&&(0<=".,!%*;:=-".indexOf(z.charAt(0))&&(h=z.charAt(0),g=e.doc.getStringUnitWidth(h)*e.doc.internal.getFontSize(),q+g<=b.textPos.x+b.width&&(e.doc.autoTableText(h,q,f,m),z=z.substring(1,z.length)),g=e.doc.getStringUnitWidth(z)*e.doc.internal.getFontSize()),q=b.textPos.x,f+=e.doc.internal.getFontSize());if("visible"!==b.styles.overflow)for(;z.length&&q+g>b.textPos.x+b.width;)z=z.substring(0,z.length-1),g=e.doc.getStringUnitWidth(z)*e.doc.internal.getFontSize(); -e.doc.autoTableText(z,q,f,m);q+=g}if(t||k)c(d).is("b")?t=!1:c(d).is("i")&&(k=!1),e.doc.setFontType(t||k?t?"bold":"italic":"normal");d=d.nextSibling}b.textPos.x=q;b.textPos.y=f}else e.doc.autoTableText(b.text,b.textPos.x,b.textPos.y,m)}}function fa(b,a,e){return null==b?"":b.toString().replace(new RegExp(null==a?"":a.toString().replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),e)}function ka(b){return null==b?"":b.toString().replace(/^\s+/,"")}function la(b){return null==b?"":b.toString().replace(/\s+$/, -"")}function Ba(b){a.date.pattern.lastIndex=0;var d=a.date.pattern.exec(b);if(null==d)return!1;b=+d[a.date.match_y];if(0>b||8099b||8099]*)>)/gi,"\u2060"),p=c("
").html(l).contents();b=!1;l="";c.each(p.text().split("\u2028"),function(b,d){0b?1:0)).split(".");1===p.length&&(p[1]="");var n=3b?"-":"")+ (a.numbers.output.thousandsSeparator?(n?p[0].substr(0,n)+a.numbers.output.thousandsSeparator:"")+p[0].substr(n).replace(/(\d{3})(?=\d)/g,"$1"+a.numbers.output.thousandsSeparator):p[0])+(p[1].length?a.numbers.output.decimalMark+p[1]:"")}}else f=k;!0===a.escape&&(f=escape(f));"function"===typeof a.onCellData&&(f=a.onCellData(t,d,e,f,m))}void 0!==q&&(q.type=m);return f}function Ca(b){return 0"+F(a,c,e)+""});p++});Q+="";var ra=1;r=B(c(A));c(r).each(function(){var a=1;n="";E(this,"td,th",p,u.length+r.length,function(b,c,g){n+=""+F(b,c,g)+"";a++});0"!==n&&(Q+=''+n+"",ra++);p++}); -Q+="";if("string"===a.outputMode)return Q;if("base64"===a.outputMode)return K(Q);M(Q,a.fileName+".xml","application/xml","utf-8","base64",!1)}else if("excel"===a.type&&"xmlss"===a.mso.fileFormat){var sa=[],D=[];c(A).filter(function(){return I(c(this))}).each(function(){function b(a,b,d){var f=[];c(a).each(function(){var b=0,e=0;n="";E(this,"td,th",p,d+a.length,function(a,d,m){if(null!==a){var k="";d=F(a,d,m);m="String";if(!1!==jQuery.isNumeric(d))m="Number";else{var g=Ma(d);!1!== -g&&(d=g,m="Number",k+=' ss:StyleID="pct1"')}"Number"!==m&&(d=d.replace(/\n/g,"
"));g=O(a);a=U(a);c.each(f,function(){if(p>=this.s.r&&p<=this.e.r&&e>=this.s.c&&e<=this.e.c)for(var a=0;a<=this.e.c-this.s.c;++a)e++,b++});if(a||g)a=a||1,g=g||1,f.push({s:{r:p,c:e},e:{r:p+a-1,c:e+g-1}});1'+c("
").text(d).html()+"\r"; -e++}});0\r'+n+"\r");p++});return a.length}var d=c(this),e="";"string"===typeof a.mso.worksheetName&&a.mso.worksheetName.length?e=a.mso.worksheetName+" "+(D.length+1):"undefined"!==typeof a.mso.worksheetName[D.length]&&(e=a.mso.worksheetName[D.length]);e.length||(e=d.find("caption").text()||"");e.length||(e="Table "+(D.length+1));e=c.trim(e.replace(/[\\\/[\]*:?'"]/g,"").substring(0,31));D.push(c("
").text(e).html());!1===a.exportHiddenCells&&(J= -d.find("tr, th, td").filter(":hidden"),V=0\r";e=b(y(d),"th,td",0);b(B(d),"td,th",e);H+="\r";sa.push(H)});h={};v={};for(var l,R,X=0,ca=D.length;X\r\r\r\r '+ -(new Date).toISOString()+'\r\r\r \r\r\r 9000\r 13860\r 0\r 0\r False\r False\r\r\r \r \r \r\r'; +h+(1"+F(a,c,e)+""});p++});Q+="";var ra= +1;r=B(c(A));c(r).each(function(){var a=1;n="";E(this,"td,th",p,u.length+r.length,function(b,c,g){n+=""+F(b,c,g)+"";a++});0"!==n&&(Q+=''+n+"",ra++);p++});Q+="";if("string"===a.outputMode)return Q;if("base64"===a.outputMode)return K(Q);M(Q,a.fileName+".xml","application/xml","utf-8","base64",!1)}else if("excel"===a.type&&"xmlss"===a.mso.fileFormat){var sa=[],D=[];c(A).filter(function(){return I(c(this))}).each(function(){function b(a, +b,d){var f=[];c(a).each(function(){var b=0,e=0;n="";E(this,"td,th",p,d+a.length,function(a,d,m){if(null!==a){var k="";d=F(a,d,m);m="String";if(!1!==jQuery.isNumeric(d))m="Number";else{var g=Ma(d);!1!==g&&(d=g,m="Number",k+=' ss:StyleID="pct1"')}"Number"!==m&&(d=d.replace(/\n/g,"
"));g=O(a);a=U(a);c.each(f,function(){if(p>=this.s.r&&p<=this.e.r&&e>=this.s.c&&e<=this.e.c)for(var a=0;a<=this.e.c-this.s.c;++a)e++,b++});if(a||g)a=a||1,g=g||1,f.push({s:{r:p,c:e},e:{r:p+a-1,c:e+g-1}});1'+c("
").text(d).html()+"\r";e++}});0\r'+n+"\r");p++});return a.length}var d=c(this),e="";"string"===typeof a.mso.worksheetName&&a.mso.worksheetName.length?e=a.mso.worksheetName+" "+(D.length+1):"undefined"!==typeof a.mso.worksheetName[D.length]&&(e=a.mso.worksheetName[D.length]);e.length|| +(e=d.find("caption").text()||"");e.length||(e="Table "+(D.length+1));e=c.trim(e.replace(/[\\\/[\]*:?'"]/g,"").substring(0,31));D.push(c("
").text(e).html());!1===a.exportHiddenCells&&(J=d.find("tr, th, td").filter(":hidden"),V=0\r";e=b(y(d),"th,td",0);b(B(d),"td,th",e);H+="\r";sa.push(H)});h={};v={};for(var l,R,Y=0,da=D.length;Y\r\r\r\r '+(new Date).toISOString()+'\r\r\r \r\r\r 9000\r 13860\r 0\r 0\r False\r False\r\r\r \r \r \r\r'; for(v=0;v\r'+sa[v],h=a.mso.rtl?h+'\r\r\r':h+'\r',h+="\r";h+="\r";if("string"===a.outputMode)return h;if("base64"===a.outputMode)return K(h);M(h,a.fileName+".xml","application/xml","utf-8","base64",!1)}else if("excel"=== -a.type&&"xlsx"===a.mso.fileFormat){var Z=[],Ga=XLSX.utils.book_new();c(A).filter(function(){return I(c(this))}).each(function(){for(var b=c(this),d={},e=this.getElementsByTagName("tr"),g={s:{r:0,c:0},e:{r:0,c:0}},f=[],m,t=[],k=0,h=0,l,n,u,v,r,y=XLSX.SSF.get_table();kh;++k)if(l=e[k],n=!1,"function"===typeof a.onIgnoreRow&&(n=a.onIgnoreRow(c(l),k)),!1===n&&-1===c.inArray(p,a.ignoreRow)&&-1===c.inArray(p-ra,a.ignoreRow)&&I(c(l))){var A=l.children,C=0;for(l=0;lh;++k)if(l=e[k],n=!1,"function"===typeof a.onIgnoreRow&&(n=a.onIgnoreRow(c(l),k)),!1===n&&-1===c.inArray(p,a.ignoreRow)&&-1===c.inArray(p-ra,a.ignoreRow)&&I(c(l))){var A=l.children,C=0;for(l=0;lx||36x||48===x)D="n";else if("date"===E.type||13x||44x||56===x)D="d"}else D="s";if(null!=m)if(0===m.length)w.t=D||"z";else if(0!==m.trim().length&&"s"!==D)if("function"===E.type)w={f:m};else if("TRUE"===m)w={t:"b",v:!0};else if("FALSE"===m)w={t:"b",v:!1};else if(""===D&&c(r).find("a").length)m="href"!==a.htmlHyperlink? m:"",w={f:'=HYPERLINK("'+c(r).find("a").attr("href")+(m.length?'","'+m:"")+'")'};else if("n"===D||!isNaN(Ea(m,a.numbers.output)))r=Ea(m,a.numbers.output),0===x&&"function"!==typeof a.mso.xslx.formatId.numbers&&(x=a.mso.xslx.formatId.numbers),isNaN(r)&&isNaN(m)||(w={t:"n",v:isNaN(r)?m:r,z:"string"===typeof x?x:x in y?y[x]:"0.00"});else if("d"===D||!1!==Ba(m))r=Ba(m),0===x&&"function"!==typeof a.mso.xslx.formatId.date&&(x=a.mso.xslx.formatId.date),w={t:"d",v:!1!==r?r:m,z:"string"===typeof x?x:x in y? -y[x]:"m/d/yy"};d[na({c:n,r:h})]=w;g.e.c";u=y(b);c(u).each(function(){var b=c(this);n="";E(this,"th,td",p,u.length,function(c,d,f){if(null!==c){var e="";n+="";u=y(b);c(u).each(function(){var b=c(this);n="";E(this,"th,td",p,u.length,function(c,d,f){if(null!==c){var e="";n+=""}});0"+n+"");p++});H+="";r=B(b);c(r).each(function(){var b=c(this);n="";E(this,"td,th",p,u.length+r.length,function(d,g,f){if(null!==d){var e=F(d,g,f), h="",k=c(d).attr("data-tableexport-msonumberformat");"undefined"===typeof k&&"function"===typeof a.mso.onMsoNumberFormat&&(k=a.mso.onMsoNumberFormat(d,g,f));"undefined"!==typeof k&&""!==k&&(h="style=\"mso-number-format:'"+k+"'");if(a.mso.styles.length){g=document.defaultView.getComputedStyle(d,null);f=document.defaultView.getComputedStyle(b[0],null);for(var l in a.mso.styles)k=g[a.mso.styles[l]],""===k&&(k=f[a.mso.styles[l]]),""!==k&&"0px none rgb(0, 0, 0)"!==k&&"rgba(0, 0, 0, 0)"!==k&&(h+=""===h? 'style="':";",h+=a.mso.styles[l]+":"+k)}n+=""));n+=">"+e+""}});0"+n+"");p++});a.displayTableName&&(H+=""+F(c("

"+a.tableName+"

"))+"");H+=""});l=''+ -('');l+="";"excel"===h&&(l+="\x3c!--[if gte mso 9]>",l+="",l+="",l+="",l+="",l+="",l+=aa,l+="",l+="",l+="",a.mso.rtl&&(l+=""),l+="",l+="",l+="",l+="",l+="",l+=""; +('');l+="";"excel"===h&&(l+="\x3c!--[if gte mso 9]>",l+="",l+="",l+="",l+="",l+="",l+=ba,l+="",l+="",l+="",a.mso.rtl&&(l+=""),l+="",l+="",l+="",l+="",l+="",l+=""; l+="@page { size:"+a.mso.pageOrientation+"; mso-page-orientation:"+a.mso.pageOrientation+"; }";l+="@page Section1 {size:"+N[a.mso.pageFormat][0]+"pt "+N[a.mso.pageFormat][1]+"pt";l+="; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}";l+="div.Section1 {page:Section1;}";l+="@page Section2 {size:"+N[a.mso.pageFormat][1]+"pt "+N[a.mso.pageFormat][0]+"pt";l+=";mso-page-orientation:"+a.mso.pageOrientation+";margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}"; l+="div.Section2 {page:Section2;}";l+="br {mso-data-placement:same-cell;}";l+="";l+="";l+="";l+='
';l+=H;l+="
";l+="";l+="";if("string"===a.outputMode)return l;if("base64"===a.outputMode)return K(l);M(l,a.fileName+"."+v,"application/vnd.ms-"+h,"","base64",!1)}else if("png"===a.type)html2canvas(c(A)[0]).then(function(b){b=b.toDataURL();for(var c=atob(b.substring(22)),e=new ArrayBuffer(c.length), g=new Uint8Array(e),f=0;fJa){a>N.a0[0]&&(ia="a0",ba="l");for(var d in N)N.hasOwnProperty(d)&&N[d][1]>a&&(ia=d,ba="l",N[d][0]>a&&(ba="p"));Ja=a}}});a.jspdf.format=""===ia?"a4":ia;a.jspdf.orientation=""===ba?"w":ba}if(null==g.doc&&(g.doc=new jsPDF(a.jspdf.orientation,a.jspdf.unit,a.jspdf.format),g.wScaleFactor=1,g.hScaleFactor=1,"function"===typeof a.jspdf.onDocCreated))a.jspdf.onDocCreated(g.doc);!0===g.outputImages&&(g.images={});"undefined"!==typeof g.images&&(c(A).filter(function(){return I(c(this))}).each(function(){var b= +a.fileName+".pdf","application/pdf","","",!1)})}else if(!1===a.jspdf.autotable){h={dim:{w:fa(c(A).first().get(0),"width","mm"),h:fa(c(A).first().get(0),"height","mm")},pagesplit:!1};var Ia=new jsPDF(a.jspdf.orientation,a.jspdf.unit,a.jspdf.format);Ia.addHTML(c(A).first(),a.jspdf.margins.left,a.jspdf.margins.top,h,function(){va(Ia,!1)})}else{var g=a.jspdf.autotable.tableExport;if("string"===typeof a.jspdf.format&&"bestfit"===a.jspdf.format.toLowerCase()){var ia="",ca="",Ja=0;c(A).each(function(){if(I(c(this))){var a= +fa(c(this).get(0),"width","pt");if(a>Ja){a>N.a0[0]&&(ia="a0",ca="l");for(var d in N)N.hasOwnProperty(d)&&N[d][1]>a&&(ia=d,ca="l",N[d][0]>a&&(ca="p"));Ja=a}}});a.jspdf.format=""===ia?"a4":ia;a.jspdf.orientation=""===ca?"w":ca}if(null==g.doc&&(g.doc=new jsPDF(a.jspdf.orientation,a.jspdf.unit,a.jspdf.format),g.wScaleFactor=1,g.hScaleFactor=1,"function"===typeof a.jspdf.onDocCreated))a.jspdf.onDocCreated(g.doc);!0===g.outputImages&&(g.images={});"undefined"!==typeof g.images&&(c(A).filter(function(){return I(c(this))}).each(function(){var b= 0;G=[];!1===a.exportHiddenCells&&(J=c(this).find("tr, th, td").filter(":hidden"),V=0 B Line 1 - Line 2 - Line 3 + TeableExport's Line 2 + Line 3 contains ' and "