diff --git a/tableExport.js b/tableExport.js
index a55cd0d..5f491a0 100644
--- a/tableExport.js
+++ b/tableExport.js
@@ -1,9 +1,9 @@
/**
* @preserve tableExport.jquery.plugin
*
- * Version 1.10.14
+ * Version 1.10.15
*
- * Copyright (c) 2015-2019 hhurz, https://github.com/hhurz/tableExport.jquery.plugin
+ * Copyright (c) 2015-2020 hhurz, https://github.com/hhurz/tableExport.jquery.plugin
*
* Based on https://github.com/kayalshri/tableExport.jquery.plugin
*
@@ -148,14 +148,14 @@
'credit-card': [153, 243]
};
var FONT_ROW_RATIO = 1.15;
- var el = this;
- var DownloadEvt = null;
- var $hrows = [];
- var $rows = [];
- var rowIndex = 0;
- var trData = '';
- var colNames = [];
- var ranges = [];
+ var el = this;
+ var DownloadEvt = null;
+ var $hrows = [];
+ var $rows = [];
+ var rowIndex = 0;
+ var trData = '';
+ var colNames = [];
+ var ranges = [];
var blob;
var $hiddenTableElements = [];
var checkCellVisibilty = false;
@@ -186,7 +186,7 @@
defaults.mso.pageOrientation = (defaults.mso.pageOrientation.substr(0, 1) === 'l') ? 'landscape' : 'portrait';
defaults.date.html = defaults.date.html || '';
- if ( defaults.date.html.length ) {
+ if (defaults.date.html.length) {
var patt = [];
patt['dd'] = '(3[01]|[12][0-9]|0?[1-9])';
patt['mm'] = '(1[012]|0?[1-9])';
@@ -205,49 +205,48 @@
// e.g. '^\\s*(3[01]|[12][0-9]|0?[1-9])(.)(1[012]|0?[1-9])\\2((?:1[6-9]|2[0-2])\\d{2})\\s*$'
defaults.date.pattern = new RegExp(defaults.date.regex, 'g');
- var f = formatItems.indexOf("dd")+1;
+ var f = formatItems.indexOf('dd') + 1;
defaults.date.match_d = f + (f > 1 ? 1 : 0);
- f = formatItems.indexOf("mm")+1;
+ f = formatItems.indexOf('mm') + 1;
defaults.date.match_m = f + (f > 1 ? 1 : 0);
- f = (formatItems.indexOf("yyyy") >= 0 ? formatItems.indexOf("yyyy") : formatItems.indexOf("yy"))+1;
+ f = (formatItems.indexOf('yyyy') >= 0 ? formatItems.indexOf('yyyy') : formatItems.indexOf('yy')) + 1;
defaults.date.match_y = f + (f > 1 ? 1 : 0);
}
colNames = GetColumnNames(el);
- if ( defaults.type === 'csv' || defaults.type === 'tsv' || defaults.type === 'txt' ) {
+ if (defaults.type === 'csv' || defaults.type === 'tsv' || defaults.type === 'txt') {
- var csvData = "";
+ var csvData = '';
var rowlength = 0;
- ranges = [];
- rowIndex = 0;
+ ranges = [];
+ rowIndex = 0;
var csvString = function (cell, rowIndex, colIndex) {
var result = '';
- if ( cell !== null ) {
+ if (cell !== null) {
var dataString = parseString(cell, rowIndex, colIndex);
var csvValue = (dataString === null || dataString === '') ? '' : dataString.toString();
- if ( defaults.type === 'tsv' ) {
- if ( dataString instanceof Date )
+ if (defaults.type === 'tsv') {
+ if (dataString instanceof Date)
dataString.toLocaleString();
// According to http://www.iana.org/assignments/media-types/text/tab-separated-values
// are fields that contain tabs not allowable in tsv encoding
result = replaceAll(csvValue, '\t', ' ');
- }
- else {
+ } else {
// Takes a string and encapsulates it (by default in double-quotes) if it
// contains the csv field separator, spaces, or linebreaks.
- if ( dataString instanceof Date )
+ if (dataString instanceof Date)
result = defaults.csvEnclosure + dataString.toLocaleString() + defaults.csvEnclosure;
else {
result = preventInjection(csvValue);
result = replaceAll(result, defaults.csvEnclosure, defaults.csvEnclosure + defaults.csvEnclosure);
- if ( result.indexOf(defaults.csvSeparator) >= 0 || /[\r\n ]/g.test(result) )
+ if (result.indexOf(defaults.csvSeparator) >= 0 || /[\r\n ]/g.test(result))
result = defaults.csvEnclosure + result + defaults.csvEnclosure;
}
}
@@ -259,16 +258,16 @@
var CollectCsvData = function ($rows, rowselector, length) {
$rows.each(function () {
- trData = "";
+ trData = '';
ForEachVisibleCell(this, rowselector, rowIndex, length + $rows.length,
- function (cell, row, col) {
- trData += csvString(cell, row, col) + (defaults.type === 'tsv' ? '\t' : defaults.csvSeparator);
- });
+ function (cell, row, col) {
+ trData += csvString(cell, row, col) + (defaults.type === 'tsv' ? '\t' : defaults.csvSeparator);
+ });
trData = $.trim(trData).substring(0, trData.length - 1);
- if ( trData.length > 0 ) {
+ if (trData.length > 0) {
- if ( csvData.length > 0 )
- csvData += "\n";
+ if (csvData.length > 0)
+ csvData += '\n';
csvData += trData;
}
@@ -279,152 +278,152 @@
};
rowlength += CollectCsvData($(el).find('thead').first().find(defaults.theadSelector), 'th,td', rowlength);
- findTableElements($(el),'tbody').each(function () {
+ findTableElements($(el), 'tbody').each(function () {
rowlength += CollectCsvData(findTableElements($(this), defaults.tbodySelector), 'td,th', rowlength);
});
- if ( defaults.tfootSelector.length )
+ if (defaults.tfootSelector.length)
CollectCsvData($(el).find('tfoot').first().find(defaults.tfootSelector), 'td,th', rowlength);
- csvData += "\n";
+ csvData += '\n';
//output
- if ( defaults.outputMode === 'string' )
+ if (defaults.outputMode === 'string')
return csvData;
- if ( defaults.outputMode === 'base64' )
+ if (defaults.outputMode === 'base64')
return base64encode(csvData);
- if ( defaults.outputMode === 'window' ) {
+ if (defaults.outputMode === 'window') {
downloadFile(false, 'data:text/' + (defaults.type === 'csv' ? 'csv' : 'plain') + ';charset=utf-8,', csvData);
return;
}
- saveToFile ( csvData,
- defaults.fileName + '.' + defaults.type,
- "text/" + (defaults.type === 'csv' ? 'csv' : 'plain'),
- "utf-8",
- "",
- (defaults.type === 'csv' && defaults.csvUseBOM) );
+ saveToFile(csvData,
+ defaults.fileName + '.' + defaults.type,
+ 'text/' + (defaults.type === 'csv' ? 'csv' : 'plain'),
+ 'utf-8',
+ '',
+ (defaults.type === 'csv' && defaults.csvUseBOM));
- } else if ( defaults.type === 'sql' ) {
+ } else if (defaults.type === 'sql') {
// Header
rowIndex = 0;
- ranges = [];
- var tdData = "INSERT INTO " + defaults.sql.tableEnclosure + defaults.tableName + defaults.sql.tableEnclosure + " (";
- $hrows = collectHeadRows ($(el));
+ ranges = [];
+ var tdData = 'INSERT INTO ' + defaults.sql.tableEnclosure + defaults.tableName + defaults.sql.tableEnclosure + ' (';
+ $hrows = collectHeadRows($(el));
$($hrows).each(function () {
ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
- function (cell, row, col) {
- 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 + ",";
- });
+ function (cell, row, col) {
+ 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);
});
- tdData += ") VALUES ";
+ tdData += ') VALUES ';
// Data
- $rows = collectRows ($(el));
+ $rows = collectRows($(el));
$($rows).each(function () {
- trData = "";
+ trData = '';
ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length,
- function (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;
+ function (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;
tdData = $.trim(tdData).substring(0, tdData.length - 1);
- tdData += "),";
+ tdData += '),';
}
rowIndex++;
});
tdData = $.trim(tdData).substring(0, tdData.length - 1);
- tdData += ";";
+ tdData += ';';
// Output
- if ( defaults.outputMode === 'string' )
+ if (defaults.outputMode === 'string')
return tdData;
- if ( defaults.outputMode === 'base64' )
+ if (defaults.outputMode === 'base64')
return base64encode(tdData);
- saveToFile ( tdData, defaults.fileName + '.sql', "application/sql", "utf-8", "", false );
+ saveToFile(tdData, defaults.fileName + '.sql', 'application/sql', 'utf-8', '', false);
- } else if ( defaults.type === 'json' ) {
+ } else if (defaults.type === 'json') {
var jsonHeaderArray = [];
ranges = [];
- $hrows = collectHeadRows ($(el));
+ $hrows = collectHeadRows($(el));
$($hrows).each(function () {
var jsonArrayTd = [];
ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
- function (cell, row, col) {
- jsonArrayTd.push(parseString(cell, row, col));
- });
+ function (cell, row, col) {
+ jsonArrayTd.push(parseString(cell, row, col));
+ });
jsonHeaderArray.push(jsonArrayTd);
});
// Data
var jsonArray = [];
- $rows = collectRows ($(el));
+ $rows = collectRows($(el));
$($rows).each(function () {
var jsonObjectTd = {};
var colIndex = 0;
ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length,
- function (cell, row, col) {
- if ( jsonHeaderArray.length ) {
- jsonObjectTd[jsonHeaderArray[jsonHeaderArray.length - 1][colIndex]] = parseString(cell, row, col);
- } else {
- jsonObjectTd[colIndex] = parseString(cell, row, col);
- }
- colIndex++;
- });
- if ( $.isEmptyObject(jsonObjectTd) === false )
+ function (cell, row, col) {
+ if (jsonHeaderArray.length) {
+ jsonObjectTd[jsonHeaderArray[jsonHeaderArray.length - 1][colIndex]] = parseString(cell, row, col);
+ } else {
+ jsonObjectTd[colIndex] = parseString(cell, row, col);
+ }
+ colIndex++;
+ });
+ if ($.isEmptyObject(jsonObjectTd) === false)
jsonArray.push(jsonObjectTd);
rowIndex++;
});
- var sdata = "";
+ var sdata = '';
- if ( defaults.jsonScope === 'head' )
+ if (defaults.jsonScope === 'head')
sdata = JSON.stringify(jsonHeaderArray);
- else if ( defaults.jsonScope === 'data' )
+ else if (defaults.jsonScope === 'data')
sdata = JSON.stringify(jsonArray);
else // all
sdata = JSON.stringify({header: jsonHeaderArray, data: jsonArray});
- if ( defaults.outputMode === 'string' )
+ if (defaults.outputMode === 'string')
return sdata;
- if ( defaults.outputMode === 'base64' )
+ if (defaults.outputMode === 'base64')
return base64encode(sdata);
- saveToFile ( sdata, defaults.fileName + '.json', "application/json", "utf-8", "base64", false );
+ saveToFile(sdata, defaults.fileName + '.json', 'application/json', 'utf-8', 'base64', false);
- } else if ( defaults.type === 'xml' ) {
+ } else if (defaults.type === 'xml') {
rowIndex = 0;
- ranges = [];
- var xml = '';
+ ranges = [];
+ var xml = '';
xml += '
0 ) - trData += ' colspan="' + tdcolspan + '"'; - - var tdrowspan = getRowspan (cell); - if ( tdrowspan > 0 ) - trData += ' rowspan="' + tdrowspan + '"'; - - trData += '>' + parseString(cell, row, col) + ' | '; - } - }); - if ( trData.length > 0 ) + function (cell, row, col) { + if (cell !== null) { + var thstyle = ''; + + trData += '0) + trData += ' colspan="' + tdcolspan + '"'; + + var tdrowspan = getRowspan(cell); + if (tdrowspan > 0) + trData += ' rowspan="' + tdrowspan + '"'; + + trData += '>' + parseString(cell, row, col) + ' | '; + } + }); + if (trData.length > 0) docData += '
---|
0 )
- trData += ' colspan="' + tdcolspan + '"';
-
- var tdrowspan = getRowspan (cell);
- if ( tdrowspan > 0 )
- trData += ' rowspan="' + tdrowspan + '"';
-
- if ( typeof tdvalue === 'string' && tdvalue !== '' ) {
- tdvalue = preventInjection(tdvalue);
- tdvalue = tdvalue.replace(/\n/g, ' '); - } - - trData += '>' + tdvalue + ' | ';
- }
- });
- if ( trData.length > 0 )
+ function (cell, row, col) {
+ if (cell !== null) {
+ var tdvalue = parseString(cell, row, col);
+ var tdstyle = '';
+ var tdcss = $(cell).attr('data-tableexport-msonumberformat');
+
+ if (typeof tdcss === 'undefined' && typeof defaults.mso.onMsoNumberFormat === 'function')
+ tdcss = defaults.mso.onMsoNumberFormat(cell, row, col);
+
+ if (typeof tdcss !== 'undefined' && tdcss !== '')
+ tdstyle = 'style="mso-number-format:\'' + tdcss + '\'';
+
+ if (defaults.mso.styles.length) {
+ var cellstyles = document.defaultView.getComputedStyle(cell, null);
+ var rowstyles = document.defaultView.getComputedStyle($row[0], null);
+
+ for (var cssStyle in defaults.mso.styles) {
+ tdcss = cellstyles[defaults.mso.styles[cssStyle]];
+ if (tdcss === '')
+ tdcss = rowstyles[defaults.mso.styles[cssStyle]];
+
+ if (tdcss !== '' && tdcss !== '0px none rgb(0, 0, 0)' && tdcss !== 'rgba(0, 0, 0, 0)') {
+ tdstyle += (tdstyle === '') ? 'style="' : ';';
+ tdstyle += defaults.mso.styles[cssStyle] + ':' + tdcss;
+ }
+ }
+ }
+
+ trData += ' 0)
+ trData += ' colspan="' + tdcolspan + '"';
+
+ var tdrowspan = getRowspan(cell);
+ if (tdrowspan > 0)
+ trData += ' rowspan="' + tdrowspan + '"';
+
+ if (typeof tdvalue === 'string' && tdvalue !== '') {
+ tdvalue = preventInjection(tdvalue);
+ tdvalue = tdvalue.replace(/\n/g, ' '); + } + + trData += '>' + tdvalue + ' | ';
+ }
+ });
+ if (trData.length > 0)
docData += '
' + parseString($(' ' + defaults.tableName + ' ')) + ' |