Skip to content

Commit 6127e19

Browse files
ab320012Srijon Saha
authored andcommitted
feat(raw-numbers): optional raw numbers
1 parent 9add78a commit 6127e19

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

bits/90_utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function make_json_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Ar
3333
else if(raw && v === null) row[hdr[C]] = null;
3434
else continue;
3535
} else {
36-
row[hdr[C]] = raw ? v : format_cell(val,v,o);
36+
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
3737
}
3838
if(v != null) isempty = false;
3939
}
@@ -98,7 +98,7 @@ function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Arr
9898
if(val == null) txt = "";
9999
else if(val.v != null) {
100100
isempty = false;
101-
txt = ''+format_cell(val, null, o);
101+
txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
102102
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; }
103103
if(txt == "ID") txt = '"ID"';
104104
} else if(val.f != null && !val.F) {

types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ export interface Sheet2CSVOpts extends DateNFOption {
629629

630630
/** Force quotes around fields */
631631
forceQuotes?: boolean;
632+
633+
/** if true, return raw numbers; if false, return formatted numbers */
634+
rawNumbers?: boolean;
632635
}
633636

634637
export interface OriginOption {
@@ -665,6 +668,9 @@ export interface Sheet2JSONOpts extends DateNFOption {
665668

666669
/** if true, return raw data; if false, return formatted text */
667670
raw?: boolean;
671+
672+
/** if true, return raw numbers; if false, return formatted numbers */
673+
rawNumbers?: boolean;
668674
}
669675

670676
export interface AOA2SheetOpts extends CommonOptions, DateNFOption {

xlsx.flow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21286,7 +21286,7 @@ function make_json_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Ar
2128621286
else if(raw && v === null) row[hdr[C]] = null;
2128721287
else continue;
2128821288
} else {
21289-
row[hdr[C]] = raw ? v : format_cell(val,v,o);
21289+
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
2129021290
}
2129121291
if(v != null) isempty = false;
2129221292
}
@@ -21351,7 +21351,7 @@ function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Arr
2135121351
if(val == null) txt = "";
2135221352
else if(val.v != null) {
2135321353
isempty = false;
21354-
txt = ''+format_cell(val, null, o);
21354+
txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
2135521355
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; }
2135621356
if(txt == "ID") txt = '"ID"';
2135721357
} else if(val.f != null && !val.F) {

xlsx.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xlsx.mini.flow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9376,7 +9376,7 @@ function make_json_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Ar
93769376
else if(raw && v === null) row[hdr[C]] = null;
93779377
else continue;
93789378
} else {
9379-
row[hdr[C]] = raw ? v : format_cell(val,v,o);
9379+
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
93809380
}
93819381
if(v != null) isempty = false;
93829382
}
@@ -9441,7 +9441,7 @@ function make_csv_row(sheet/*:Worksheet*/, r/*:Range*/, R/*:number*/, cols/*:Arr
94419441
if(val == null) txt = "";
94429442
else if(val.v != null) {
94439443
isempty = false;
9444-
txt = ''+format_cell(val, null, o);
9444+
txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
94459445
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; }
94469446
if(txt == "ID") txt = '"ID"';
94479447
} else if(val.f != null && !val.F) {

xlsx.mini.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9271,7 +9271,7 @@ function make_json_row(sheet, r, R, cols, header, hdr, dense, o) {
92719271
else if(raw && v === null) row[hdr[C]] = null;
92729272
else continue;
92739273
} else {
9274-
row[hdr[C]] = raw ? v : format_cell(val,v,o);
9274+
row[hdr[C]] = raw || (o.rawNumbers && val.t == "n") ? v : format_cell(val,v,o);
92759275
}
92769276
if(v != null) isempty = false;
92779277
}
@@ -9336,7 +9336,7 @@ function make_csv_row(sheet, r, R, cols, fs, rs, FS, o) {
93369336
if(val == null) txt = "";
93379337
else if(val.v != null) {
93389338
isempty = false;
9339-
txt = ''+format_cell(val, null, o);
9339+
txt = ''+(o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
93409340
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; }
93419341
if(txt == "ID") txt = '"ID"';
93429342
} else if(val.f != null && !val.F) {

0 commit comments

Comments
 (0)