adding an option to not parse numbers #2014

Merged
ab320012 merged 1 commits from master into master 2020-07-10 03:40:27 +00:00
6 changed files with 16 additions and 10 deletions

@ -33,7 +33,7 @@ function make_json_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Ar
else if(raw && v === null) row[hdr[C]] = null;
else continue;
} else {
row[hdr[C]] = raw ? v : format_cell(val,v,o);
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
}
if(v != null) isempty = false;
}
@ -98,7 +98,7 @@ function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Arr
if(val == null) txt = "";
else if(val.v != null) {
isempty = false;
txt = ''+format_cell(val, null, o);
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(txt == "ID") txt = '"ID"';
} else if(val.f != null && !val.F) {

6
types/index.d.ts vendored

@ -626,6 +626,9 @@ export interface Sheet2CSVOpts extends DateNFOption {
/** Force quotes around fields */
forceQuotes?: boolean;
/** if true, return raw numbers; if false, return formatted numbers */
rawNumbers?: boolean;
}
export interface OriginOption {
@ -662,6 +665,9 @@ export interface Sheet2JSONOpts extends DateNFOption {
/** if true, return raw data; if false, return formatted text */
raw?: boolean;
/** if true, return raw numbers; if false, return formatted numbers */
rawNumbers?: boolean;
}
export interface AOA2SheetOpts extends CommonOptions, DateNFOption {

@ -21147,7 +21147,7 @@ function make_json_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Ar
else if(raw && v === null) row[hdr[C]] = null;
else continue;
} else {
row[hdr[C]] = raw ? v : format_cell(val,v,o);
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
}
if(v != null) isempty = false;
}
@ -21212,7 +21212,7 @@ function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Arr
if(val == null) txt = "";
else if(val.v != null) {
isempty = false;
txt = ''+format_cell(val, null, o);
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(txt == "ID") txt = '"ID"';
} else if(val.f != null && !val.F) {

4
xlsx.js generated

@ -21016,7 +21016,7 @@ function make_json_row(sheet, r, R, cols, header, hdr, dense, o) {
else if(raw && v === null) row[hdr[C]] = null;
else continue;
} else {
row[hdr[C]] = raw ? v : format_cell(val,v,o);
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
}
if(v != null) isempty = false;
}
@ -21081,7 +21081,7 @@ function make_csv_row(sheet, r, R, cols, fs, rs, FS, o) {
if(val == null) txt = "";
else if(val.v != null) {
isempty = false;
txt = ''+format_cell(val, null, o);
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(txt == "ID") txt = '"ID"';
} else if(val.f != null && !val.F) {

@ -8330,7 +8330,7 @@ function make_json_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Ar
else if(raw && v === null) row[hdr[C]] = null;
else continue;
} else {
row[hdr[C]] = raw ? v : format_cell(val,v,o);
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
}
if(v != null) isempty = false;
}
@ -8395,7 +8395,7 @@ function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Arr
if(val == null) txt = "";
else if(val.v != null) {
isempty = false;
txt = ''+format_cell(val, null, o);
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(txt == "ID") txt = '"ID"';
} else if(val.f != null && !val.F) {

@ -8226,7 +8226,7 @@ function make_json_row(sheet, r, R, cols, header, hdr, dense, o) {
else if(raw && v === null) row[hdr[C]] = null;
else continue;
} else {
row[hdr[C]] = raw ? v : format_cell(val,v,o);
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
}
if(v != null) isempty = false;
}
@ -8291,7 +8291,7 @@ function make_csv_row(sheet, r, R, cols, fs, rs, FS, o) {
if(val == null) txt = "";
else if(val.v != null) {
isempty = false;
txt = ''+format_cell(val, null, o);
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(txt == "ID") txt = '"ID"';
} else if(val.f != null && !val.F) {