diff --git a/README.md b/README.md index 8293a6d..4050482 100644 --- a/README.md +++ b/README.md @@ -112,8 +112,9 @@ $("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 cells from the exported file - emptyCSS: ".tableexport-empty" // (selector, selector[]), selector(s) to replace cells with an empty string in 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 + trimWhitespace: false // (Boolean), remove all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of cell text }); ``` > **Note:** to use the xlsx filetype, you must include the third-party scripts listed in the Dependencies section. diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index 87f1eac..b064725 100644 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -100,7 +100,7 @@ } return new Array(total).concat($(val).text()); } - return $(val).text(); + return formatValue($(val).text()); }).get()]; }).get(), dataObject = TableExport.prototype.escapeHtml( @@ -151,7 +151,7 @@ } return new Array(total).concat($(val).text()); } - return $(val).text(); + return formatValue($(val).text()); }).get()]; }).get(), dataObject = TableExport.prototype.escapeHtml( @@ -179,7 +179,7 @@ if ($(val).is(emptyCSS)) { return " " } - return $(val).text(); + return formatValue($(val).text()); }).get().join(colD); }).get().join(rdel), dataObject = TableExport.prototype.escapeHtml( @@ -207,7 +207,7 @@ if ($(val).is(emptyCSS)) { return " " } - return '"' + $(val).text().replace(/"/g, '""') + '"'; + return '"' + formatValue($(val).text().replace(/"/g, '""')) + '"'; }).get().join(colD); }).get().join(rdel), dataObject = TableExport.prototype.escapeHtml( @@ -235,7 +235,7 @@ if ($(val).is(emptyCSS)) { return " " } - return $(val).text(); + return formatValue($(val).text()); }).get().join(colD); }).get().join(rdel), dataObject = TableExport.prototype.escapeHtml( @@ -259,6 +259,18 @@ } ); + function trimWhitespace(string) { + if (self.settings.trimWhitespace) { + return $.trim(string); + } + return string; + } + + function formatValue(string) { + string = trimWhitespace(string); + return string; + } + function checkCaption(exportButton) { var $caption = $el.find('caption:not(.head)'); $caption.length ? $caption.append(exportButton) : $el.prepend('