Skip to content

Commit

Permalink
Fixed Issue #300: Cell data of original table was modified since rele…
Browse files Browse the repository at this point in the history
…ase 1.10.18
  • Loading branch information
hhurz committed May 16, 2020
1 parent f2b7477 commit c896abb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions tableExport.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @preserve tableExport.jquery.plugin
*
* Version 1.10.18
* Version 1.10.19
*
* Copyright (c) 2015-2020 hhurz, https://github.com/hhurz/tableExport.jquery.plugin
*
Expand Down Expand Up @@ -1243,7 +1243,8 @@
teOptions.doc.rect(cell.x, cell.y, cell.width, cell.height, cell.styles.fillStyle);

if (typeof tecell !== 'undefined' &&
typeof tecell.elements !== 'undefined' && tecell.elements.length) {
(typeof tecell.hasUserDefText === 'undefined' || tecell.hasUserDefText !== true) &&
typeof tecell.elements !== 'undefined' && tecell.elements.length) {

var hScale = cell.height / tecell.rect.height;
if (hScale > teOptions.hScaleFactor)
Expand Down Expand Up @@ -1339,6 +1340,10 @@
obj = getCellStyles(cell);
obj.isCanvas = cell.hasAttribute('data-tableexport-canvas');
obj.elements = obj.isCanvas ? $(cell) : $(cell).children();

if(typeof $(cell).data('teUserDefText') !== 'undefined')
obj.hasUserDefText = true;

teOptions.teCells [rowCount + ':' + colKey++] = obj;
} else {
obj = $.extend(true, {}, teOptions.teCells [rowCount + ':' + (colKey - 1)]);
Expand Down Expand Up @@ -1910,18 +1915,20 @@
var $cell = $(cell);
var htmlData;

$cell.removeData('teUserDefText');

if ($cell[0].hasAttribute('data-tableexport-canvas')) {
htmlData = '';
} else if ($cell[0].hasAttribute('data-tableexport-value')) {
htmlData = $cell.attr('data-tableexport-value');
htmlData = htmlData ? htmlData + '' : '';
$cell.html(htmlData);
$cell.data('teUserDefText', 1);
} else {
htmlData = $cell.html();

if (typeof defaults.onCellHtmlData === 'function') {
htmlData = defaults.onCellHtmlData($cell, rowIndex, colIndex, htmlData);
$cell.html(htmlData);
$cell.data('teUserDefText', 1);
}
else if (htmlData !== '') {
var html = $.parseHTML(htmlData);
Expand Down Expand Up @@ -2032,7 +2039,7 @@

if (typeof defaults.onCellData === 'function') {
result = defaults.onCellData($cell, rowIndex, colIndex, result, cellType);
$cell.html(result);
$cell.data('teUserDefText', 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ <h1>
<br>
<li><a href="#" onClick="doExport('#countries', {type: 'xlsx', htmlHyperlink: 'content'});"> <img src='icons/xls.png' alt="XLSX" style="width:24px"> XLSX</a></li>
<li><a href="#" onClick="doExport('#rowspans', {type: 'excel', mso: {fileFormat: 'xlsx'}});"> <img src='icons/xls.png' alt="XLSX" style="width:24px"> XLSX data types</a></li>
<li><a href="#" onClick="doExport('#issue45', {type: 'xlsx',numbers: {html: {decimalMark: ',', thousandsSeparator: '.'}, output: {decimalMark: '.', thousandsSeparator: ''}}});"> <img src='icons/xls.png' alt="XLSX" style="width:24px"> XLSX (tableexport-cellformat)</a></li>
<li><a href="#" onClick="doExport('#issue45', {type: 'xlsx', onCellHtmlData: DoOnCellHtmlData, numbers: {html: {decimalMark: ',', thousandsSeparator: '.'}, output: {decimalMark: '.', thousandsSeparator: ''}}});"> <img src='icons/xls.png' alt="XLSX" style="width:24px"> XLSX (tableexport-cellformat)</a></li>
<li><a href="#" onClick="doExport('#issue81', {type: 'xlsx', onCellData: DoOnXlsxCellData});"> <img src='icons/xls.png' alt="XLSX" style="width:24px"> XLSX (Issue 193: Number format)</a></li>
<li><a href="#" onClick="doExport('#mixspans', {type: 'xlsx'});"> <img src='icons/xls.png' alt="XLSX" style="width:24px"> XLSX (colspan + rowspan)</a></li>
<li><a href="#" onClick="doExport('#issue93', {type: 'xlsx', ignoreColumn: [4,7],ignoreRow: [4,8]});"> <img src='icons/xls.png' alt="XLS" style="width:24px"> XLSX (Issue 93: colspan & rowspan)</a></li>
Expand Down

0 comments on commit c896abb

Please sign in to comment.