forked from sheetjs/sheetjs
feat(raw-numbers): optional raw numbers
This commit is contained in:
parent
9add78a290
commit
6127e19c02
@ -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
6
types/index.d.ts
vendored
@ -629,6 +629,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 {
|
||||
@ -665,6 +668,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 {
|
||||
|
@ -21286,7 +21286,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;
|
||||
}
|
||||
@ -21351,7 +21351,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
4
xlsx.js
generated
@ -21155,7 +21155,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;
|
||||
}
|
||||
@ -21220,7 +21220,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) {
|
||||
|
@ -9376,7 +9376,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;
|
||||
}
|
||||
@ -9441,7 +9441,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) {
|
||||
|
@ -9271,7 +9271,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;
|
||||
}
|
||||
@ -9336,7 +9336,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) {
|
||||
|
Loading…
Reference in New Issue
Block a user