diff --git a/README.md b/README.md index d43af66..765a21d 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,8 @@ $("table").tableExport({ position: "bottom", // (top, bottom), position of the caption element relative to table ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file - ignoreCSS: ".tableexport-ignore" // (selector, selector[]), selector(s) to exclude from the exported file + ignoreCSS: ".tableexport-ignore" // (selector, selector[]), selector(s) to exclude cells from the exported file + emptyCSS: ".tableexport-empty" // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file }); ``` > **Note:** to use the xlsx filetype, you must include the third-party scripts listed in the Dependencies section. diff --git a/bower.json b/bower.json index 25a1e23..9ccc7a1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "tableexport.js", - "version": "3.2.11", + "version": "3.2.12", "authors": [ "clarketm " ], diff --git a/dist/css/tableexport.css b/dist/css/tableexport.css index 24a624c..fb9e188 100644 --- a/dist/css/tableexport.css +++ b/dist/css/tableexport.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.2.11 (https://www.travismclarke.com) + * TableExport.js v3.2.12 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ diff --git a/dist/css/tableexport.min.css b/dist/css/tableexport.min.css index e9c37aa..b5d42a6 100644 --- a/dist/css/tableexport.min.css +++ b/dist/css/tableexport.min.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.2.11 (https://www.travismclarke.com) + * TableExport.js v3.2.12 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */.top{caption-side:top}.bottom{caption-side:bottom}.button-default,.button-default:active,.button-default:focus,.button-default:hover{text-decoration:none}.button-default{font:700 12px sans-serif;color:#222;cursor:pointer;padding:5px;margin:5px}.button-default.csv:before,.button-default.txt:before,.button-default.xls:before,.button-default.xlsx:before{content:none}.csv:before,.txt:before,.xls:before,.xlsx:before{content:""}.csv,.txt,.xls,.xlsx{margin:4px 0}.csv:before,.txt:before,.xls:before,.xlsx:before{margin-right:10px;padding:11px 15px 12px;box-shadow:1px 1px 2px rgba(0,0,0,.2)}.xlsx:before{background:url(../img/xlsx.svg) center no-repeat #006400}.xls:before{background:url(../img/xls.svg) center no-repeat green}.csv:before{background:url(../img/csv.svg) center no-repeat #00f}.txt:before{background:url(../img/txt.svg) center no-repeat purple} \ No newline at end of file diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index 7cb9ade..fdc9fe4 100644 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.2.11 (https://www.travismclarke.com) + * TableExport.js v3.2.12 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ @@ -41,6 +41,7 @@ ignoreRows = self.settings.ignoreRows instanceof Array ? self.settings.ignoreRows : [self.settings.ignoreRows], ignoreCols = self.settings.ignoreCols instanceof Array ? self.settings.ignoreCols : [self.settings.ignoreCols], ignoreCSS = self.settings.ignoreCSS instanceof Array ? self.settings.ignoreCSS.join(", ") : self.settings.ignoreCSS, + emptyCSS = self.settings.emptyCSS instanceof Array ? self.settings.emptyCSS.join(", ") : self.settings.emptyCSS, bootstrapClass, bootstrapTheme, bootstrapSpacing; if (self.settings.bootstrap) { @@ -74,6 +75,9 @@ if (!!~ignoreCols.indexOf(ic) || $(val).is(ignoreCSS)) { return; } + if ($(val).is(emptyCSS)) { + return " " + } if (val.hasAttribute('colspan')) { rcMap[ir] = rcMap[ir] || {}; rcMap[ir][ic+1] = val.getAttribute('colspan') - 1 @@ -112,6 +116,9 @@ if (!!~ignoreCols.indexOf(ic) || $(val).is(ignoreCSS)) { return; } + if ($(val).is(emptyCSS)) { + return " " + } if (val.hasAttribute('colspan')) { rcMap[ir] = rcMap[ir] || {}; rcMap[ir][ic+1] = val.getAttribute('colspan') - 1 @@ -150,6 +157,9 @@ if (!!~ignoreCols.indexOf(i) || $(val).is(ignoreCSS)) { return; } + if ($(val).is(emptyCSS)) { + return " " + } return $(val).text(); }).get().join(colD); }).get().join(rdel), @@ -175,6 +185,9 @@ if (!!~ignoreCols.indexOf(i) || $(val).is(ignoreCSS)) { return; } + if ($(val).is(emptyCSS)) { + return " " + } return $(val).text(); }).get().join(colD); }).get().join(rdel), @@ -200,6 +213,9 @@ if (!!~ignoreCols.indexOf(i) || $(val).is(ignoreCSS)) { return; } + if ($(val).is(emptyCSS)) { + return " " + } return $(val).text(); }).get().join(colD); }).get().join(rdel), @@ -264,7 +280,8 @@ position: "bottom", // (top, bottom), position of the caption element relative to table, (default: "bottom") ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file (default: null) ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file (default: null) - ignoreCSS: ".tableexport-ignore" // (selector, selector[]), selector(s) to exclude from the exported file (default: ".tableexport-ignore") + ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file (default: ".tableexport-ignore") + emptyCSS: ".tableexport-empty" // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty") }, /** * Character set (character encoding) of the HTML. diff --git a/dist/js/tableexport.min.js b/dist/js/tableexport.min.js index b2536e6..c694ac0 100644 --- a/dist/js/tableexport.min.js +++ b/dist/js/tableexport.min.js @@ -1,6 +1,6 @@ /*! - * TableExport.js v3.2.11 (https://www.travismclarke.com) + * TableExport.js v3.2.12 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ -!function(t,e){"function"==typeof define&&define.amd?define(["exports","jquery","file-saver","xlsx"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?e(exports,require("jquery"),require("file-saver"),require("xlsx")):e(t,t.jQuery,t.saveAs,t.XLSX)}(this,function(t,e,n,o){"use strict";var i=function(t,n,r){var s=this;s.settings=r?n:e.extend({},i.prototype.defaults,n),s.selectors=t;var a,p,f,l=i.prototype.rowDel,u=s.settings.ignoreRows instanceof Array?s.settings.ignoreRows:[s.settings.ignoreRows],c=s.settings.ignoreCols instanceof Array?s.settings.ignoreCols:[s.settings.ignoreCols],x=s.settings.ignoreCSS instanceof Array?s.settings.ignoreCSS.join(", "):s.settings.ignoreCSS;return s.settings.bootstrap?(a=i.prototype.bootstrap[0]+" ",p=i.prototype.bootstrap[1]+" ",f=i.prototype.bootstrap[2]+" "):(a=i.prototype.defaultButton+" ",p=f=""),s.selectors.each(function(){function t(t){var e=d.find("caption:not(.head)");e.length?e.append(t):d.prepend(''+t+"")}function n(e,n,o){var i="";t(i)}var d=e(this);r&&d.find("caption:not(.head)").remove();var y=d.find("tbody").find("tr"),y=s.settings.headings?y.add(d.find("thead>tr")):y,y=s.settings.footers?y.add(d.find("tfoot>tr")):y,m=s.settings.headings?d.find("thead>tr").length:0,g="id"===s.settings.fileName?d.attr("id")?d.attr("id"):i.prototype.defaultFileName:s.settings.fileName,h={xlsx:function(t,o){var r={},s=y.map(function(t,n){if(!~u.indexOf(t-m)&&!e(n).is(x)){var o=e(n).find("th, td");return[o.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x)){if(o.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][n+1]=o.getAttribute("colspan")-1),o.hasAttribute("rowspan"))for(var i=1;i":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return i.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},i=0;i!=t.length;++i)for(var r=0;r!=t[i].length;++r){n.s.r>i&&(n.s.r=i),n.s.c>r&&(n.s.c=r),n.e.r'+t+"")}function n(e,n,o){var i="";t(i)}var y=e(this);r&&y.find("caption:not(.head)").remove();var m=y.find("tbody").find("tr"),m=s.settings.headings?m.add(y.find("thead>tr")):m,m=s.settings.footers?m.add(y.find("tfoot>tr")):m,g=s.settings.headings?y.find("thead>tr").length:0,b="id"===s.settings.fileName?y.attr("id")?y.attr("id"):i.prototype.defaultFileName:s.settings.fileName,h={xlsx:function(t,o){var r={},s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return[o.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x)){if(e(o).is(d))return" ";if(o.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][n+1]=o.getAttribute("colspan")-1),o.hasAttribute("rowspan"))for(var i=1;i":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return i.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},i=0;i!=t.length;++i)for(var r=0;r!=t[i].length;++r){n.s.r>i&&(n.s.r=i),n.s.c>r&&(n.s.c=r),n.e.r" ], diff --git a/src/stable/css/tableexport.css b/src/stable/css/tableexport.css index 24a624c..fb9e188 100644 --- a/src/stable/css/tableexport.css +++ b/src/stable/css/tableexport.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.2.11 (https://www.travismclarke.com) + * TableExport.js v3.2.12 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ diff --git a/src/stable/css/tableexport.min.css b/src/stable/css/tableexport.min.css index e9c37aa..b5d42a6 100644 --- a/src/stable/css/tableexport.min.css +++ b/src/stable/css/tableexport.min.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.2.11 (https://www.travismclarke.com) + * TableExport.js v3.2.12 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */.top{caption-side:top}.bottom{caption-side:bottom}.button-default,.button-default:active,.button-default:focus,.button-default:hover{text-decoration:none}.button-default{font:700 12px sans-serif;color:#222;cursor:pointer;padding:5px;margin:5px}.button-default.csv:before,.button-default.txt:before,.button-default.xls:before,.button-default.xlsx:before{content:none}.csv:before,.txt:before,.xls:before,.xlsx:before{content:""}.csv,.txt,.xls,.xlsx{margin:4px 0}.csv:before,.txt:before,.xls:before,.xlsx:before{margin-right:10px;padding:11px 15px 12px;box-shadow:1px 1px 2px rgba(0,0,0,.2)}.xlsx:before{background:url(../img/xlsx.svg) center no-repeat #006400}.xls:before{background:url(../img/xls.svg) center no-repeat green}.csv:before{background:url(../img/csv.svg) center no-repeat #00f}.txt:before{background:url(../img/txt.svg) center no-repeat purple} \ No newline at end of file diff --git a/src/stable/js/tableexport.js b/src/stable/js/tableexport.js index 7cb9ade..fdc9fe4 100644 --- a/src/stable/js/tableexport.js +++ b/src/stable/js/tableexport.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.2.11 (https://www.travismclarke.com) + * TableExport.js v3.2.12 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ @@ -41,6 +41,7 @@ ignoreRows = self.settings.ignoreRows instanceof Array ? self.settings.ignoreRows : [self.settings.ignoreRows], ignoreCols = self.settings.ignoreCols instanceof Array ? self.settings.ignoreCols : [self.settings.ignoreCols], ignoreCSS = self.settings.ignoreCSS instanceof Array ? self.settings.ignoreCSS.join(", ") : self.settings.ignoreCSS, + emptyCSS = self.settings.emptyCSS instanceof Array ? self.settings.emptyCSS.join(", ") : self.settings.emptyCSS, bootstrapClass, bootstrapTheme, bootstrapSpacing; if (self.settings.bootstrap) { @@ -74,6 +75,9 @@ if (!!~ignoreCols.indexOf(ic) || $(val).is(ignoreCSS)) { return; } + if ($(val).is(emptyCSS)) { + return " " + } if (val.hasAttribute('colspan')) { rcMap[ir] = rcMap[ir] || {}; rcMap[ir][ic+1] = val.getAttribute('colspan') - 1 @@ -112,6 +116,9 @@ if (!!~ignoreCols.indexOf(ic) || $(val).is(ignoreCSS)) { return; } + if ($(val).is(emptyCSS)) { + return " " + } if (val.hasAttribute('colspan')) { rcMap[ir] = rcMap[ir] || {}; rcMap[ir][ic+1] = val.getAttribute('colspan') - 1 @@ -150,6 +157,9 @@ if (!!~ignoreCols.indexOf(i) || $(val).is(ignoreCSS)) { return; } + if ($(val).is(emptyCSS)) { + return " " + } return $(val).text(); }).get().join(colD); }).get().join(rdel), @@ -175,6 +185,9 @@ if (!!~ignoreCols.indexOf(i) || $(val).is(ignoreCSS)) { return; } + if ($(val).is(emptyCSS)) { + return " " + } return $(val).text(); }).get().join(colD); }).get().join(rdel), @@ -200,6 +213,9 @@ if (!!~ignoreCols.indexOf(i) || $(val).is(ignoreCSS)) { return; } + if ($(val).is(emptyCSS)) { + return " " + } return $(val).text(); }).get().join(colD); }).get().join(rdel), @@ -264,7 +280,8 @@ position: "bottom", // (top, bottom), position of the caption element relative to table, (default: "bottom") ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file (default: null) ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file (default: null) - ignoreCSS: ".tableexport-ignore" // (selector, selector[]), selector(s) to exclude from the exported file (default: ".tableexport-ignore") + ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file (default: ".tableexport-ignore") + emptyCSS: ".tableexport-empty" // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty") }, /** * Character set (character encoding) of the HTML. diff --git a/src/stable/js/tableexport.min.js b/src/stable/js/tableexport.min.js index b2536e6..c694ac0 100644 --- a/src/stable/js/tableexport.min.js +++ b/src/stable/js/tableexport.min.js @@ -1,6 +1,6 @@ /*! - * TableExport.js v3.2.11 (https://www.travismclarke.com) + * TableExport.js v3.2.12 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ -!function(t,e){"function"==typeof define&&define.amd?define(["exports","jquery","file-saver","xlsx"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?e(exports,require("jquery"),require("file-saver"),require("xlsx")):e(t,t.jQuery,t.saveAs,t.XLSX)}(this,function(t,e,n,o){"use strict";var i=function(t,n,r){var s=this;s.settings=r?n:e.extend({},i.prototype.defaults,n),s.selectors=t;var a,p,f,l=i.prototype.rowDel,u=s.settings.ignoreRows instanceof Array?s.settings.ignoreRows:[s.settings.ignoreRows],c=s.settings.ignoreCols instanceof Array?s.settings.ignoreCols:[s.settings.ignoreCols],x=s.settings.ignoreCSS instanceof Array?s.settings.ignoreCSS.join(", "):s.settings.ignoreCSS;return s.settings.bootstrap?(a=i.prototype.bootstrap[0]+" ",p=i.prototype.bootstrap[1]+" ",f=i.prototype.bootstrap[2]+" "):(a=i.prototype.defaultButton+" ",p=f=""),s.selectors.each(function(){function t(t){var e=d.find("caption:not(.head)");e.length?e.append(t):d.prepend(''+t+"")}function n(e,n,o){var i="";t(i)}var d=e(this);r&&d.find("caption:not(.head)").remove();var y=d.find("tbody").find("tr"),y=s.settings.headings?y.add(d.find("thead>tr")):y,y=s.settings.footers?y.add(d.find("tfoot>tr")):y,m=s.settings.headings?d.find("thead>tr").length:0,g="id"===s.settings.fileName?d.attr("id")?d.attr("id"):i.prototype.defaultFileName:s.settings.fileName,h={xlsx:function(t,o){var r={},s=y.map(function(t,n){if(!~u.indexOf(t-m)&&!e(n).is(x)){var o=e(n).find("th, td");return[o.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x)){if(o.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][n+1]=o.getAttribute("colspan")-1),o.hasAttribute("rowspan"))for(var i=1;i":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return i.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},i=0;i!=t.length;++i)for(var r=0;r!=t[i].length;++r){n.s.r>i&&(n.s.r=i),n.s.c>r&&(n.s.c=r),n.e.r'+t+"")}function n(e,n,o){var i="";t(i)}var y=e(this);r&&y.find("caption:not(.head)").remove();var m=y.find("tbody").find("tr"),m=s.settings.headings?m.add(y.find("thead>tr")):m,m=s.settings.footers?m.add(y.find("tfoot>tr")):m,g=s.settings.headings?y.find("thead>tr").length:0,b="id"===s.settings.fileName?y.attr("id")?y.attr("id"):i.prototype.defaultFileName:s.settings.fileName,h={xlsx:function(t,o){var r={},s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return[o.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x)){if(e(o).is(d))return" ";if(o.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][n+1]=o.getAttribute("colspan")-1),o.hasAttribute("rowspan"))for(var i=1;i":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return i.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},i=0;i!=t.length;++i)for(var r=0;r!=t[i].length;++r){n.s.r>i&&(n.s.r=i),n.s.c>r&&(n.s.c=r),n.e.r