From f2b5fcc40eeb177f856f71eb9c114d277faf3fd9 Mon Sep 17 00:00:00 2001 From: abhiramTS Date: Wed, 18 Jan 2023 14:55:55 +0530 Subject: [PATCH] Check for strings that may be interpreted as numbers (fixes #2609) --- bits/90_utils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bits/90_utils.js b/bits/90_utils.js index c7df54316..8db4bc234 100644 --- a/bits/90_utils.js +++ b/bits/90_utils.js @@ -110,10 +110,13 @@ function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Arr isempty = false; txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o)); for(var i = 0, cc = 0; i !== txt.length; ++i) if((cc = txt.charCodeAt(i)) === fs || cc === rs || cc === 34 || o.forceQuotes) {txt = "\"" + txt.replace(qreg, '""') + "\""; break; } + if (parseInt(txt) == txt) txt = "\"" + txt + "\""; if(txt == "ID") txt = '"ID"'; } else if(val.f != null && !val.F) { isempty = false; - txt = '=' + val.f; if(txt.indexOf(",") >= 0) txt = '"' + txt.replace(qreg, '""') + '"'; + txt = '=' + val.f; + if (parseInt(val.f) == val.f) txt = "\"" + val.f + "\""; + if(txt.indexOf(",") >= 0) txt = '"' + txt.replace(qreg, '""') + '"'; } else txt = ""; /* NOTE: Excel CSV does not support array formulae */ row.push(txt);