Skip to content

Commit 654d6f9

Browse files
committed
stringify all 's' cell values (fixes #2795)
1 parent 4ae4f0f commit 654d6f9

File tree

12 files changed

+2607
-568
lines changed

12 files changed

+2607
-568
lines changed

bits/40_harb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ function sheet_to_dbf(ws/*:Worksheet*/, opts/*:WriteOpts*/) {
311311
var cp = +dbf_reverse_map[/*::String(*/current_codepage/*::)*/] || 0x03;
312312
h.write_shift(4, 0x00000000 | (cp<<8));
313313
if(dbf_codepage_map[cp] != +o.codepage) {
314-
console.error("DBF Unsupported codepage " + current_codepage + ", using 1252");
314+
if(o.codepage) console.error("DBF Unsupported codepage " + current_codepage + ", using 1252");
315315
current_codepage = 1252;
316316
}
317317

@@ -578,7 +578,7 @@ var SYLK = /*#__PURE__*/(function() {
578578
case 'b': o += cell.v ? "TRUE" : "FALSE"; break;
579579
case 'e': o += cell.w || cell.v; break;
580580
case 'd': o += '"' + (cell.w || cell.v) + '"'; break;
581-
case 's': o += '"' + cell.v.replace(/"/g,"").replace(/;/g, ";;") + '"'; break;
581+
case 's': o += '"' + (cell.v == null ? "" : String(cell.v)).replace(/"/g,"").replace(/;/g, ";;") + '"'; break;
582582
}
583583
return o;
584584
}

bits/42_sstxml.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ function write_sst_xml(sst/*:SST*/, opts)/*:string*/ {
229229
else {
230230
sitag += "<t";
231231
if(!s.t) s.t = "";
232+
if(typeof s.t !== "string") s.t = String(s.t);
232233
if(s.t.match(straywsregex)) sitag += ' xml:space="preserve"';
233234
sitag += ">" + escapexml(s.t) + "</t>";
234235
}

bits/68_wsbin.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,10 @@ function parse_BrtCellSt(data) {
258258
return [cell, value, 'str'];
259259
}
260260
function write_BrtCellSt(cell, ncell, o) {
261+
var data = cell.v == null ? "" : String(cell.v);
261262
if(o == null) o = new_buf(12 + 4 * cell.v.length);
262263
write_XLSBCell(ncell, o);
263-
write_XLWideString(cell.v, o);
264+
write_XLWideString(data, o);
264265
return o.length > o.l ? o.slice(0, o.l) : o;
265266
}
266267
function parse_BrtShortSt(data) {
@@ -269,9 +270,10 @@ function parse_BrtShortSt(data) {
269270
return [cell, value, 'str'];
270271
}
271272
function write_BrtShortSt(cell, ncell, o) {
272-
if(o == null) o = new_buf(8 + 4 * cell.v.length);
273+
var data = cell.v == null ? "" : String(cell.v);
274+
if(o == null) o = new_buf(8 + 4 * data.length);
273275
write_XLSBShortCell(ncell, o);
274-
write_XLWideString(cell.v, o);
276+
write_XLWideString(data, o);
275277
return o.length > o.l ? o.slice(0, o.l) : o;
276278
}
277279

@@ -824,7 +826,7 @@ function write_ws_bin_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:num
824826
switch(cell.t) {
825827
case 's': case 'str':
826828
if(opts.bookSST) {
827-
vv = get_sst_id(opts.Strings, (cell.v/*:any*/), opts.revStrings);
829+
vv = get_sst_id(opts.Strings, (cell.v == null ? "" : String(cell.v)/*:any*/), opts.revStrings);
828830
o.t = "s"; o.v = vv;
829831
if(last_seen) write_record(ba, 0x0012 /* BrtShortIsst */, write_BrtShortIsst(cell, o));
830832
else write_record(ba, 0x0007 /* BrtCellIsst */, write_BrtCellIsst(cell, o));

bits/78_writebiff.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function write_ws_biff2_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:n
6868
case 'b': case 'e': write_biff_rec(ba, 0x0005, write_BIFF2BERR(R, C, cell.v, cell.t)); return;
6969
/* TODO: codepage, sst */
7070
case 's': case 'str':
71-
write_biff_rec(ba, 0x0004, write_BIFF2LABEL(R, C, (cell.v||"").slice(0,255)));
71+
write_biff_rec(ba, 0x0004, write_BIFF2LABEL(R, C, cell.v == null ? "" : String(cell.v).slice(0,255)));
7272
return;
7373
}
7474
write_biff_rec(ba, 0x0001, write_BIFF2Cell(null, R, C));
@@ -192,9 +192,9 @@ function write_ws_biff8_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:n
192192
/* TODO: codepage, sst */
193193
case 's': case 'str':
194194
if(opts.bookSST) {
195-
var isst = get_sst_id(opts.Strings, cell.v, opts.revStrings);
195+
var isst = get_sst_id(opts.Strings, cell.v == null ? "" : String(cell.v), opts.revStrings);
196196
write_biff_rec(ba, 0x00fd /* LabelSst */, write_LabelSst(R, C, isst, os, opts));
197-
} else write_biff_rec(ba, 0x0204 /* Label */, write_Label(R, C, (cell.v||"").slice(0,255), os, opts));
197+
} else write_biff_rec(ba, 0x0204 /* Label */, write_Label(R, C, (cell.v == null ? "" : String(cell.v)).slice(0,255), os, opts));
198198
break;
199199
default:
200200
write_biff_rec(ba, 0x0201 /* Blank */, write_XLSCell(R, C, os));

0 commit comments

Comments
 (0)