From 6c2c4d8958d08d501281ec12fe592f1e82749bdc Mon Sep 17 00:00:00 2001 From: hluikart <35969933+hluikart@users.noreply.github.com> Date: Mon, 29 Apr 2019 10:08:13 -0400 Subject: [PATCH 1/6] Update tableToXlsx.js Added validation check for both numbers and dates. --- lib/tableToXlsx.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/tableToXlsx.js b/lib/tableToXlsx.js index 61184bd..6ae3606 100644 --- a/lib/tableToXlsx.js +++ b/lib/tableToXlsx.js @@ -97,16 +97,17 @@ async function tableToXlsx (options, tables, id) { usedCells[`${cell.rowNumber()},${cell.columnNumber()}`] = true if (cellInfo.type === 'number') { - cell.value(parseFloat(cellInfo.valueText)) + cellInfo.valueText && !isNaN(cellInfo.valueText) ? cell.value(parseFloat(cellInfo.valueText)) : ''; } else if (cellInfo.type === 'bool' || cellInfo.type === 'boolean') { cell.value(cellInfo.valueText === 'true' || cellInfo.valueText === '1') } else if (cellInfo.type === 'date') { // dates in excel are just numbers with some format applied to make // the number appear as date // https://github.com/dtjohnson/xlsx-populate#dates - cell.value(moment(cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd') + cellInfo.valueText && moment(cellInfo.valueText).isValid() ? cell.value(moment(cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd') :''; + } else if (cellInfo.type === 'datetime') { - cell.value(moment(cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd h:mm:ss') + cellInfo.valueText && moment(cellInfo.valueText).isValid() ? cell.value(moment(cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd h:mm:ss') : ''; } else if (cellInfo.type === 'formula') { cell.formula(cellInfo.valueText) } else { From a92fbb94d18045fa434d6a3e97fd0fb92d681bcb Mon Sep 17 00:00:00 2001 From: hluikart <35969933+hluikart@users.noreply.github.com> Date: Mon, 29 Apr 2019 10:17:20 -0400 Subject: [PATCH 2/6] Update tableToXlsx.js --- lib/tableToXlsx.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tableToXlsx.js b/lib/tableToXlsx.js index 6ae3606..4c85b2c 100644 --- a/lib/tableToXlsx.js +++ b/lib/tableToXlsx.js @@ -97,17 +97,17 @@ async function tableToXlsx (options, tables, id) { usedCells[`${cell.rowNumber()},${cell.columnNumber()}`] = true if (cellInfo.type === 'number') { - cellInfo.valueText && !isNaN(cellInfo.valueText) ? cell.value(parseFloat(cellInfo.valueText)) : ''; + cellInfo.valueText && !isNaN(cellInfo.valueText) ? cell.value(parseFloat(cellInfo.valueText)) : '' } else if (cellInfo.type === 'bool' || cellInfo.type === 'boolean') { cell.value(cellInfo.valueText === 'true' || cellInfo.valueText === '1') } else if (cellInfo.type === 'date') { // dates in excel are just numbers with some format applied to make // the number appear as date // https://github.com/dtjohnson/xlsx-populate#dates - cellInfo.valueText && moment(cellInfo.valueText).isValid() ? cell.value(moment(cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd') :''; + cellInfo.valueText && moment(cellInfo.valueText).isValid() ? cell.value(moment(cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd') :'' } else if (cellInfo.type === 'datetime') { - cellInfo.valueText && moment(cellInfo.valueText).isValid() ? cell.value(moment(cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd h:mm:ss') : ''; + cellInfo.valueText && moment(cellInfo.valueText).isValid() ? cell.value(moment(cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd h:mm:ss') : '' } else if (cellInfo.type === 'formula') { cell.formula(cellInfo.valueText) } else { From d9fc045395fc015c1295979c5b058e3178195ad4 Mon Sep 17 00:00:00 2001 From: hluikart <35969933+hluikart@users.noreply.github.com> Date: Mon, 29 Apr 2019 10:27:40 -0400 Subject: [PATCH 3/6] Update tableToXlsx.js --- lib/tableToXlsx.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/tableToXlsx.js b/lib/tableToXlsx.js index 4c85b2c..40f3cec 100644 --- a/lib/tableToXlsx.js +++ b/lib/tableToXlsx.js @@ -97,17 +97,16 @@ async function tableToXlsx (options, tables, id) { usedCells[`${cell.rowNumber()},${cell.columnNumber()}`] = true if (cellInfo.type === 'number') { - cellInfo.valueText && !isNaN(cellInfo.valueText) ? cell.value(parseFloat(cellInfo.valueText)) : '' + cell.value((cellInfo.valueText && !isNaN(cellInfo.valueText) ? parseFloat(cellInfo.valueText) : '')) } else if (cellInfo.type === 'bool' || cellInfo.type === 'boolean') { cell.value(cellInfo.valueText === 'true' || cellInfo.valueText === '1') } else if (cellInfo.type === 'date') { // dates in excel are just numbers with some format applied to make // the number appear as date // https://github.com/dtjohnson/xlsx-populate#dates - cellInfo.valueText && moment(cellInfo.valueText).isValid() ? cell.value(moment(cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd') :'' - + cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment(cellInfo.valueText).toDate().style('numberFormat', 'yyyy-mm-dd') :'') } else if (cellInfo.type === 'datetime') { - cellInfo.valueText && moment(cellInfo.valueText).isValid() ? cell.value(moment(cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd h:mm:ss') : '' + cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment(cellInfo.valueText).toDate().style('numberFormat', 'yyyy-mm-dd h:mm:ss') : '') } else if (cellInfo.type === 'formula') { cell.formula(cellInfo.valueText) } else { From 26b84926d3797bfe5cd9e5047ee0eb8f1a59c66c Mon Sep 17 00:00:00 2001 From: hluikart <35969933+hluikart@users.noreply.github.com> Date: Mon, 29 Apr 2019 10:34:37 -0400 Subject: [PATCH 4/6] Update tableToXlsx.js --- lib/tableToXlsx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tableToXlsx.js b/lib/tableToXlsx.js index 40f3cec..2728d23 100644 --- a/lib/tableToXlsx.js +++ b/lib/tableToXlsx.js @@ -104,9 +104,9 @@ async function tableToXlsx (options, tables, id) { // dates in excel are just numbers with some format applied to make // the number appear as date // https://github.com/dtjohnson/xlsx-populate#dates - cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment(cellInfo.valueText).toDate().style('numberFormat', 'yyyy-mm-dd') :'') + cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment((cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd') :'') } else if (cellInfo.type === 'datetime') { - cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment(cellInfo.valueText).toDate().style('numberFormat', 'yyyy-mm-dd h:mm:ss') : '') + cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment((cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd h:mm:ss') : '') } else if (cellInfo.type === 'formula') { cell.formula(cellInfo.valueText) } else { From 9e386e820130c355226c0913273b95aa1b878c91 Mon Sep 17 00:00:00 2001 From: hluikart <35969933+hluikart@users.noreply.github.com> Date: Mon, 29 Apr 2019 10:51:42 -0400 Subject: [PATCH 5/6] Update tableToXlsx.js --- lib/tableToXlsx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tableToXlsx.js b/lib/tableToXlsx.js index 2728d23..602ac80 100644 --- a/lib/tableToXlsx.js +++ b/lib/tableToXlsx.js @@ -104,9 +104,9 @@ async function tableToXlsx (options, tables, id) { // dates in excel are just numbers with some format applied to make // the number appear as date // https://github.com/dtjohnson/xlsx-populate#dates - cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment((cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd') :'') + cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment(cellInfo.valueText).toDate() : '').style('numberFormat', 'yyyy-mm-dd') } else if (cellInfo.type === 'datetime') { - cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment((cellInfo.valueText).toDate()).style('numberFormat', 'yyyy-mm-dd h:mm:ss') : '') + cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment(cellInfo.valueText).toDate(): '').style('numberFormat', 'yyyy-mm-dd h:mm:ss') } else if (cellInfo.type === 'formula') { cell.formula(cellInfo.valueText) } else { From 6a8f3c2b5578232e28afb65d87e80b09b31cd6de Mon Sep 17 00:00:00 2001 From: hluikart <35969933+hluikart@users.noreply.github.com> Date: Mon, 29 Apr 2019 11:04:06 -0400 Subject: [PATCH 6/6] Update tableToXlsx.js --- lib/tableToXlsx.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tableToXlsx.js b/lib/tableToXlsx.js index 602ac80..a797eac 100644 --- a/lib/tableToXlsx.js +++ b/lib/tableToXlsx.js @@ -106,7 +106,7 @@ async function tableToXlsx (options, tables, id) { // https://github.com/dtjohnson/xlsx-populate#dates cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment(cellInfo.valueText).toDate() : '').style('numberFormat', 'yyyy-mm-dd') } else if (cellInfo.type === 'datetime') { - cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment(cellInfo.valueText).toDate(): '').style('numberFormat', 'yyyy-mm-dd h:mm:ss') + cell.value(cellInfo.valueText && moment(cellInfo.valueText).isValid() ? moment(cellInfo.valueText).toDate() : '').style('numberFormat', 'yyyy-mm-dd h:mm:ss') } else if (cellInfo.type === 'formula') { cell.formula(cellInfo.valueText) } else {