styled-exceljs 0.21.2 → 0.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/xlsx.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /*! xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
2
2
  /* vim: set ts=2: */
3
3
  /*exported XLSX */
4
- /*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false, DataView:false, Deno:false, Set:false, Float32Array:false */
4
+ /*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false, DataView:false, Deno:false, Set:false, Float32Array:false, Int8Array:false */
5
5
  var XLSX = {};
6
6
  function make_xlsx_lib(XLSX){
7
- XLSX.version = '0.21.2';
7
+ XLSX.version = '0.21.3';
8
8
  var current_codepage = 1200, current_ansi = 1252;
9
9
  /*global cptable:true, window */
10
10
  var $cptable;
@@ -158,9 +158,9 @@ function Base64_decode(input) {
158
158
  var o = "";
159
159
  var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
160
160
  if (input.slice(0, 5) == "data:") {
161
- var i = input.slice(0, 1024).indexOf(";base64,");
162
- if (i > -1)
163
- input = input.slice(i + 8);
161
+ var sep = input.slice(0, 1024).indexOf(";base64,");
162
+ if (sep > -1)
163
+ input = input.slice(sep + 8);
164
164
  }
165
165
  input = input.replace(/[^\w\+\/\=]/g, "");
166
166
  for (var i = 0; i < input.length; ) {
@@ -3232,7 +3232,7 @@ function blobify(data) {
3232
3232
  }
3233
3233
  /* write or download file */
3234
3234
  function write_dl(fname, payload, enc) {
3235
- /*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
3235
+ /*global IE_SaveFile, navigator, saveAs, document, chrome */
3236
3236
  if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
3237
3237
  if(typeof Deno !== 'undefined') {
3238
3238
  /* in this spot, it's safe to assume typed arrays and TextEncoder/TextDecoder exist */
@@ -3880,6 +3880,19 @@ function escapexlml(text){
3880
3880
  return s.replace(decregex, function(y) { return rencoding[y]; }).replace(htmlcharegex,function(s) { return "&#x" + (s.charCodeAt(0).toString(16)).toUpperCase() + ";"; });
3881
3881
  }
3882
3882
 
3883
+ /* Extract text from XML fragments in linear time. This is a parser helper,
3884
+ * not an HTML sanitizer: text is escaped separately at HTML output boundaries. */
3885
+ function strip_xml_tags(text) {
3886
+ var str = String(text), out = [], inTag = false;
3887
+ for(var i = 0; i < str.length; ++i) {
3888
+ var cc = str.charCodeAt(i);
3889
+ if(!inTag && cc == 60 /* < */) inTag = true;
3890
+ else if(inTag && cc == 62 /* > */) inTag = false;
3891
+ else if(!inTag) out.push(str.charAt(i));
3892
+ }
3893
+ return out.join("");
3894
+ }
3895
+
3883
3896
  /* TODO: handle codepages */
3884
3897
  var xlml_fixstr = (function() {
3885
3898
  var entregex = /&#(\d+);/g;
@@ -3986,8 +3999,8 @@ var htmldecode = (function() {
3986
3999
  .replace(/[\t\n\r ]+/g, " ")
3987
4000
  // Replace <br> tags with new lines
3988
4001
  .replace(/<\s*[bB][rR]\s*\/?>/g,"\n")
3989
- // Strip HTML elements
3990
- .replace(/<[^<>]*>/g,"");
4002
+ ;
4003
+ o = strip_xml_tags(o);
3991
4004
  for(var i = 0; i < entities.length; ++i) o = o.replace(entities[i][0], entities[i][1]);
3992
4005
  return o;
3993
4006
  };
@@ -4558,9 +4571,25 @@ function format_cell(cell, v, o) {
4558
4571
  return safe_format_cell(cell, v);
4559
4572
  }
4560
4573
 
4574
+ /* Worksheet names are document-controlled. A normal object treats
4575
+ * "__proto__" as a setter, so all workbook sheet maps must use an own-property
4576
+ * preserving dictionary and all lookups must reject inherited properties. */
4577
+ function sheet_map_new() {
4578
+ return Object.create ? Object.create(null) : {};
4579
+ }
4580
+ function sheet_map_set(sheets, name, sheet) {
4581
+ if(name == "__proto__" && Object.defineProperty) Object.defineProperty(sheets, name, {
4582
+ value: sheet, configurable: true, enumerable: true, writable: true
4583
+ });
4584
+ else sheets[name] = sheet;
4585
+ }
4586
+ function sheet_map_get(sheets, name) {
4587
+ return sheets != null && Object.prototype.hasOwnProperty.call(sheets, name) ? sheets[name] : void 0;
4588
+ }
4589
+
4561
4590
  function sheet_to_workbook(sheet, opts) {
4562
4591
  var n = opts && opts.sheet ? opts.sheet : "Sheet1";
4563
- var sheets = {}; sheets[n] = sheet;
4592
+ var sheets = sheet_map_new(); sheet_map_set(sheets, n, sheet);
4564
4593
  return { SheetNames: [n], Sheets: sheets };
4565
4594
  }
4566
4595
 
@@ -6233,8 +6262,8 @@ function parse_TypedPropertyValue(blob, type, _opts) {
6233
6262
  case 0x03 /*VT_I4*/: ret = blob.read_shift(4, 'i'); return ret;
6234
6263
  case 0x0B /*VT_BOOL*/: return blob.read_shift(4) !== 0x0;
6235
6264
  case 0x13 /*VT_UI4*/: ret = blob.read_shift(4); return ret;
6236
- case 0x1E /*VT_LPSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
6237
- case 0x1F /*VT_LPWSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
6265
+ case 0x1E /*VT_LPSTR*/: blob.l += 4; return parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1");
6266
+ case 0x1F /*VT_LPWSTR*/: blob.l += 4; return parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1");
6238
6267
  case 0x40 /*VT_FILETIME*/: return parse_FILETIME(blob);
6239
6268
  case 0x41 /*VT_BLOB*/: return parse_BLOB(blob);
6240
6269
  case 0x47 /*VT_CF*/: return parse_ClipboardData(blob);
@@ -6743,7 +6772,6 @@ function parse_LongRGBA(blob) { var r = blob.read_shift(1), g = blob.read_shift(
6743
6772
  /* 2.5.177 LongRGB */
6744
6773
  function parse_LongRGB(blob, length) { var x = parse_LongRGBA(blob, length); x[3] = 0; return x; }
6745
6774
 
6746
-
6747
6775
  /* [MS-XLS] 2.5.19 */
6748
6776
  function parse_XLSCell(blob, length, opts) {
6749
6777
  var rw = blob.read_shift(2); // 0-indexed
@@ -8205,7 +8233,7 @@ function dbf_to_workbook(buf, opts) {
8205
8233
  o.bookType = "dbf";
8206
8234
  return o;
8207
8235
  } catch(e) { if(opts && opts.WTF) throw e; }
8208
- return ({SheetNames:[],Sheets:{}});
8236
+ return ({SheetNames:[],Sheets:sheet_map_new()});
8209
8237
  }
8210
8238
 
8211
8239
  var _RLEN = { 'B': 8, 'C': 250, 'L': 1, 'D': 8, '?': 0, '': 0 };
@@ -9101,7 +9129,7 @@ function read_wb_TABL(d, opts) {
9101
9129
  try {
9102
9130
  var out = DIF.to_workbook(d, o);
9103
9131
  if(!out || !out.Sheets) throw "DIF bad workbook";
9104
- var ws = out.Sheets[out.SheetNames[0]];
9132
+ var ws = sheet_map_get(out.Sheets, out.SheetNames[0]);
9105
9133
  if(!ws || !ws["!ref"]) throw "DIF empty worksheet";
9106
9134
  o.WTF = OLD_WTF;
9107
9135
  return out;
@@ -9157,7 +9185,7 @@ var WK_ = (function() {
9157
9185
  var o = opts || {};
9158
9186
  if(DENSE != null && o.dense == null) o.dense = DENSE;
9159
9187
  var s = ({}), n = "Sheet1", next_n = "", sidx = 0;
9160
- var sheets = {}, snames = [], realnames = [], sdata = [];
9188
+ var sheets = sheet_map_new(), snames = [], realnames = [], sdata = [];
9161
9189
  if(o.dense) sdata = s["!data"] = [];
9162
9190
 
9163
9191
  var refguess = {s: {r:0, c:0}, e: {r:0, c:0} };
@@ -9202,7 +9230,7 @@ var WK_ = (function() {
9202
9230
  if(o.qpro) {
9203
9231
  if(val[3] > sidx) {
9204
9232
  s["!ref"] = encode_range(refguess);
9205
- sheets[n] = s;
9233
+ sheet_map_set(sheets, n, s);
9206
9234
  snames.push(n);
9207
9235
  s = ({}); if(o.dense) sdata = s["!data"] = [];
9208
9236
  refguess = {s: {r:0, c:0}, e: {r:0, c:0} };
@@ -9253,7 +9281,7 @@ var WK_ = (function() {
9253
9281
  case 0x28: /* FORMULA28 */
9254
9282
  if(val[3] > sidx) {
9255
9283
  s["!ref"] = encode_range(refguess);
9256
- sheets[n] = s;
9284
+ sheet_map_set(sheets, n, s);
9257
9285
  snames.push(n);
9258
9286
  s = ({}); if(o.dense) sdata = s["!data"] = [];
9259
9287
  refguess = {s: {r:0, c:0}, e: {r:0, c:0} };
@@ -9276,17 +9304,17 @@ var WK_ = (function() {
9276
9304
  }}, o);
9277
9305
  } else throw new Error("Unrecognized LOTUS BOF " + d[2]);
9278
9306
  s["!ref"] = encode_range(refguess);
9279
- sheets[next_n || n] = s;
9307
+ sheet_map_set(sheets, next_n || n, s);
9280
9308
  snames.push(next_n || n);
9281
9309
  if(!realnames.length) return { SheetNames: snames, Sheets: sheets };
9282
- var osheets = {}, rnames = [];
9310
+ var osheets = sheet_map_new(), rnames = [];
9283
9311
  /* TODO: verify no collisions */
9284
- for(var i = 0; i < realnames.length; ++i) if(sheets[snames[i]]) {
9312
+ for(var i = 0; i < realnames.length; ++i) if(sheet_map_get(sheets, snames[i])) {
9285
9313
  rnames.push(realnames[i] || snames[i]);
9286
- osheets[realnames[i]] = sheets[realnames[i]] || sheets[snames[i]];
9314
+ sheet_map_set(osheets, realnames[i] || snames[i], sheet_map_get(sheets, realnames[i]) || sheet_map_get(sheets, snames[i]));
9287
9315
  } else {
9288
9316
  rnames.push(realnames[i]);
9289
- osheets[realnames[i]] = ({ "!ref": "A1" });
9317
+ sheet_map_set(osheets, realnames[i], ({ "!ref": "A1" }));
9290
9318
  }
9291
9319
  return { SheetNames: rnames, Sheets: osheets };
9292
9320
  }
@@ -9340,11 +9368,11 @@ var WK_ = (function() {
9340
9368
 
9341
9369
  write_biff_rec(ba, 0x00, write_BOF_WK3(wb));
9342
9370
 
9343
- for(var i = 0, cnt = 0; i < wb.SheetNames.length; ++i) if((wb.Sheets[wb.SheetNames[i]] || {})["!ref"]) write_biff_rec(ba, 0x1b, write_XFORMAT_SHEETNAME(wb.SheetNames[i], cnt++));
9371
+ for(var i = 0, cnt = 0; i < wb.SheetNames.length; ++i) if((sheet_map_get(wb.Sheets, wb.SheetNames[i]) || {})["!ref"]) write_biff_rec(ba, 0x1b, write_XFORMAT_SHEETNAME(wb.SheetNames[i], cnt++));
9344
9372
 
9345
9373
  var wsidx = 0;
9346
9374
  for(i = 0; i < wb.SheetNames.length; ++i) {
9347
- var ws = wb.Sheets[wb.SheetNames[i]];
9375
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[i]);
9348
9376
  if(!ws || !ws["!ref"]) continue;
9349
9377
  var range = safe_decode_range(ws["!ref"]);
9350
9378
  var dense = ws["!data"] != null;
@@ -9389,7 +9417,7 @@ var WK_ = (function() {
9389
9417
  var rows = 0, cols = 0, wscnt = 0;
9390
9418
  for(var i = 0; i < wb.SheetNames.length; ++i) {
9391
9419
  var name = wb.SheetNames[i];
9392
- var ws = wb.Sheets[name];
9420
+ var ws = sheet_map_get(wb.Sheets, name);
9393
9421
  if(!ws || !ws["!ref"]) continue;
9394
9422
  ++wscnt;
9395
9423
  var range = decode_range(ws["!ref"]);
@@ -10117,7 +10145,7 @@ var WK_ = (function() {
10117
10145
  var SST = [], sname = "", formulae = [];
10118
10146
  var range = {s:{r:-1,c:-1}, e:{r:-1,c:-1}};
10119
10147
  var cnt = 0, type = 0, C = 0, R = 0;
10120
- var wb = { SheetNames: [], Sheets: {} };
10148
+ var wb = { SheetNames: [], Sheets: sheet_map_new() };
10121
10149
  var FMTS = [];
10122
10150
  outer: while(d.l < d.length) {
10123
10151
  var RT = d.read_shift(2), length = d.read_shift(2);
@@ -10421,13 +10449,13 @@ var parse_rs = (function() {
10421
10449
 
10422
10450
  /* Parse a list of <r> tags */
10423
10451
  var rs_to_html = (function parse_rs_factory() {
10424
- var nlregex = /(\r\n|\n)/g;
10425
10452
  function parse_rpr2(font, intro, outro) {
10426
10453
  var style = [];
10427
10454
 
10428
10455
  if(font.u) style.push("text-decoration: underline;");
10429
- if(font.uval) style.push("text-underline-style:" + font.uval + ";");
10430
- if(font.sz) style.push("font-size:" + font.sz + "pt;");
10456
+ if(font.uval && /^(?:single|double|single-accounting|double-accounting)$/.test(font.uval)) style.push("text-underline-style:" + font.uval + ";");
10457
+ var sz = +font.sz;
10458
+ if(isFinite(sz) && sz > 0) style.push("font-size:" + Math.min(sz, 409) + "pt;");
10431
10459
  if(font.outline) style.push("text-effect: outline;");
10432
10460
  if(font.shadow) style.push("text-shadow: auto;");
10433
10461
  intro.push('<span style="' + style.join("") + '">');
@@ -10452,7 +10480,7 @@ var rs_to_html = (function parse_rs_factory() {
10452
10480
 
10453
10481
  if(r.s) parse_rpr2(r.s, terms[0], terms[2]);
10454
10482
 
10455
- return terms[0].join("") + terms[1].replace(nlregex,'<br/>') + terms[2].join("");
10483
+ return terms[0].join("") + escapehtml(terms[1]) + terms[2].join("");
10456
10484
  }
10457
10485
 
10458
10486
  return function parse_rs(rs) {
@@ -11186,6 +11214,15 @@ function style_font_family(style) {
11186
11214
  var font = style && style.font || {};
11187
11215
  return font.name || "Calibri";
11188
11216
  }
11217
+ function css_string_escape(value, quote) {
11218
+ var str = String(value), out = [];
11219
+ for(var i = 0; i < str.length; ++i) {
11220
+ var cc = str.charCodeAt(i), ch = str.charAt(i);
11221
+ if(ch == quote || ch == "\\" || cc < 32 || cc == 127 || ch == "<" || ch == ">" || ch == "&") out.push("\\" + cc.toString(16) + " ");
11222
+ else out.push(ch);
11223
+ }
11224
+ return out.join("");
11225
+ }
11189
11226
  function css_font_from_style(style) {
11190
11227
  var font = style && style.font || {};
11191
11228
  var parts = [];
@@ -11193,7 +11230,8 @@ function css_font_from_style(style) {
11193
11230
  if(font.bold) parts.push("bold");
11194
11231
  parts.push(style_font_size_pt(style) + "pt");
11195
11232
  var name = style_font_family(style);
11196
- if(/[,\s'"]/.test(name)) name = '"' + String(name).replace(/"/g, '\\"') + '"';
11233
+ if(/[,\s'"]/.test(name)) name = '"' + css_string_escape(name, '"') + '"';
11234
+ else name = css_string_escape(name, '"');
11197
11235
  parts.push(name);
11198
11236
  return parts.join(" ");
11199
11237
  }
@@ -13174,7 +13212,7 @@ function parse_drawing_anchor(data) {
13174
13212
  function parse_drawing_text(data) {
13175
13213
  var out = [];
13176
13214
  (data.match(/<a:t\b[^>]*>[\s\S]*?<\/a:t>/g)||[]).forEach(function(t) {
13177
- out.push(unescapexml(t.replace(/<[^>]*>/g, "")));
13215
+ out.push(unescapexml(strip_xml_tags(t)));
13178
13216
  });
13179
13217
  return out.join("");
13180
13218
  }
@@ -16554,7 +16592,25 @@ var mergecregex = /<(?:\w+:)?mergeCell ref=["'][A-Z0-9:]+['"]\s*[\/]?>/g;
16554
16592
  var hlinkregex = /<(?:\w+:)?hyperlink [^<>]*>/mg;
16555
16593
  var dimregex = /"(\w*:\w*)"/;
16556
16594
  var colregex = /<(?:\w+:)?col\b[^<>]*[\/]?>/g;
16557
- var afregex = /<(?:\w:)?autoFilter[^>]*([\/]|>([\s\S]*)<\/(?:\w:)?autoFilter)>/g;
16595
+ function match_ws_xml_autofilter(data) {
16596
+ var paired = str_match_xml_ns(data, "autoFilter");
16597
+ if(paired) return paired[0];
16598
+ var start = 0;
16599
+ while((start = data.indexOf("<", start)) != -1) {
16600
+ var end = data.indexOf(">", start + 1);
16601
+ if(end == -1) return null;
16602
+ var tag = data.slice(start + 1, end), p = 0;
16603
+ while(p < tag.length && tag.charCodeAt(p) <= 32) ++p;
16604
+ var nameEnd = p;
16605
+ while(nameEnd < tag.length && tag.charCodeAt(nameEnd) > 32 && tag.charAt(nameEnd) != "/") ++nameEnd;
16606
+ var name = tag.slice(p, nameEnd), colon = name.indexOf(":");
16607
+ if(colon != -1) name = name.slice(colon + 1);
16608
+ var tail = tag.slice(nameEnd).trim();
16609
+ if(name == "autoFilter" && tail.charAt(tail.length - 1) == "/") return data.slice(start, end + 1);
16610
+ start = end + 1;
16611
+ }
16612
+ return null;
16613
+ }
16558
16614
  var marginregex= /<(?:\w+:)?pageMargins[^<>]*\/>/g;
16559
16615
  var sheetprregex = /<(?:\w+:)?sheetPr\b[^<>]*?\/>/;
16560
16616
 
@@ -16603,8 +16659,8 @@ function parse_ws_xml(data, opts, idx, rels, wb, themes, styles) {
16603
16659
  if(mtch) parse_ws_xml_data(mtch[1], s, opts, refguess, themes, styles, wb);
16604
16660
 
16605
16661
  /* 18.3.1.2 autoFilter CT_AutoFilter */
16606
- var afilter = data2.match(afregex);
16607
- if(afilter) s['!autofilter'] = parse_ws_xml_autofilter(afilter[0]);
16662
+ var afilter = match_ws_xml_autofilter(data2);
16663
+ if(afilter) s['!autofilter'] = parse_ws_xml_autofilter(afilter);
16608
16664
 
16609
16665
  /* 18.3.1.55 mergeCells CT_MergeCells */
16610
16666
  var merges = [];
@@ -17129,7 +17185,7 @@ function write_ws_xml(idx, opts, wb, rels) {
17129
17185
  'xmlns:r': XMLNS.r
17130
17186
  })];
17131
17187
  var s = wb.SheetNames[idx], sidx = 0, rdata = "";
17132
- var ws = wb.Sheets[s];
17188
+ var ws = sheet_map_get(wb.Sheets, s);
17133
17189
  if(ws == null) ws = {};
17134
17190
  var ref = ws['!ref'] || 'A1';
17135
17191
  var range = safe_decode_range(ref);
@@ -18242,7 +18298,7 @@ function write_SHEETPROTECT(ba, ws) {
18242
18298
 
18243
18299
  function write_ws_bin(idx, opts, wb, rels) {
18244
18300
  var ba = buf_array();
18245
- var s = wb.SheetNames[idx], ws = wb.Sheets[s] || {};
18301
+ var s = wb.SheetNames[idx], ws = sheet_map_get(wb.Sheets, s) || {};
18246
18302
  var c = s; try { if(wb && wb.Workbook) c = wb.Workbook.Sheets[idx].CodeName || c; } catch(e) {}
18247
18303
  var r = safe_decode_range(ws['!ref'] || "A1");
18248
18304
  if(r.e.c > 0x3FFF || r.e.r > 0xFFFFF) {
@@ -18310,7 +18366,7 @@ function parse_Cache(data) {
18310
18366
  /* 21.2.2.71 formatCode CT_Xstring */
18311
18367
  var nf = unescapexml((str_match_xml(data, "c:formatCode") || ["","General"])[1]);
18312
18368
 
18313
- (str_match_ng(data, "<c:f>", "</c:f>")||[]).forEach(function(F) { f = F.replace(/<[^<>]*>/g,""); });
18369
+ (str_match_ng(data, "<c:f>", "</c:f>")||[]).forEach(function(F) { f = strip_xml_tags(F); });
18314
18370
 
18315
18371
  return [col, nf, f];
18316
18372
  }
@@ -18327,7 +18383,7 @@ function parse_chart_cache(data) {
18327
18383
  return {values:s[0], formatCode:s[1], formula:s[2]};
18328
18384
  }
18329
18385
  var f = (str_match_ng(data, "<c:f>", "</c:f>")||[])[0];
18330
- return {values:[], formula:f ? f.replace(/<[^<>]*>/g,"") : void 0};
18386
+ return {values:[], formula:f ? strip_xml_tags(f) : void 0};
18331
18387
  }
18332
18388
 
18333
18389
  function parse_chart_tx(data) {
@@ -18359,7 +18415,7 @@ function parse_chart_title(data) {
18359
18415
  var title = str_match_xml_ns(data, "title");
18360
18416
  if(!title) return "";
18361
18417
  var out = [];
18362
- (title[0].match(/<a:t\b[^>]*>[\s\S]*?<\/a:t>/g)||[]).forEach(function(t) { out.push(unescapexml(t.replace(/<[^>]*>/g, ""))); });
18418
+ (title[0].match(/<a:t\b[^>]*>[\s\S]*?<\/a:t>/g)||[]).forEach(function(t) { out.push(unescapexml(strip_xml_tags(t))); });
18363
18419
  return out.join("");
18364
18420
  }
18365
18421
 
@@ -18664,9 +18720,13 @@ function check_wb(wb) {
18664
18720
  if(!wb.SheetNames.length) throw new Error("Workbook is empty");
18665
18721
  var Sheets = (wb.Workbook && wb.Workbook.Sheets) || [];
18666
18722
  check_wb_names(wb.SheetNames, Sheets, !!wb.vbaraw);
18667
- for(var i = 0; i < wb.SheetNames.length; ++i) check_ws(wb.Sheets[wb.SheetNames[i]], wb.SheetNames[i], i);
18723
+ for(var i = 0; i < wb.SheetNames.length; ++i) {
18724
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[i]);
18725
+ if(!ws) throw new Error("Missing worksheet |" + wb.SheetNames[i] + "|");
18726
+ check_ws(ws, wb.SheetNames[i], i);
18727
+ }
18668
18728
  wb.SheetNames.forEach(function(n, i) {
18669
- var ws = wb.Sheets[n];
18729
+ var ws = sheet_map_get(wb.Sheets, n);
18670
18730
  if(!ws || !ws["!autofilter"]) return;
18671
18731
  var DN;
18672
18732
  if(!wb.Workbook) wb.Workbook = {};
@@ -19451,7 +19511,7 @@ function parse_xlml_data(xml, ss, data, cell, base, styles, csty, row, arrayf, o
19451
19511
  break;
19452
19512
  case 'String':
19453
19513
  cell.t = 's'; cell.r = xlml_fixstr(unescapexml(xml));
19454
- cell.v = (xml.indexOf("<") > -1 ? unescapexml(ss||xml).replace(/<[^<>]*>/g, "") : cell.r); // todo: BR etc
19514
+ cell.v = (xml.indexOf("<") > -1 ? strip_xml_tags(unescapexml(ss||xml)) : cell.r); // todo: BR etc
19455
19515
  break;
19456
19516
  case 'DateTime':
19457
19517
  if(xml.slice(-1) != "Z") xml += "Z";
@@ -19546,7 +19606,7 @@ function parse_xlml_xml(d, _opts) {
19546
19606
  var Rn;
19547
19607
  var state = [], tmp;
19548
19608
  if(DENSE != null && opts.dense == null) opts.dense = DENSE;
19549
- var sheets = {}, sheetnames = [], cursheet = ({}), sheetname = ""; if(opts.dense) cursheet["!data"] = [];
19609
+ var sheets = sheet_map_new(), sheetnames = [], cursheet = ({}), sheetname = ""; if(opts.dense) cursheet["!data"] = [];
19550
19610
  var cell = ({}), row = {};// eslint-disable-line no-unused-vars
19551
19611
  var dtag = xlml_parsexmltag('<Data ss:Type="String">'), didx = 0;
19552
19612
  var c = 0, r = 0;
@@ -19652,7 +19712,7 @@ for(var cma = c; cma <= cc; ++cma) {
19652
19712
  if(merges.length) cursheet["!merges"] = merges;
19653
19713
  if(cstys.length > 0) cursheet["!cols"] = cstys;
19654
19714
  if(rowinfo.length > 0) cursheet["!rows"] = rowinfo;
19655
- sheets[sheetname] = cursheet;
19715
+ sheet_map_set(sheets, sheetname, cursheet);
19656
19716
  } else {
19657
19717
  refguess = {s: {r:2000000, c:2000000}, e: {r:0, c:0} };
19658
19718
  r = c = 0;
@@ -20553,7 +20613,7 @@ function write_ws_xlml_table(ws, opts, idx, wb) {
20553
20613
  function write_ws_xlml(idx, opts, wb) {
20554
20614
  var o = [];
20555
20615
  var s = wb.SheetNames[idx];
20556
- var ws = wb.Sheets[s];
20616
+ var ws = sheet_map_get(wb.Sheets, s);
20557
20617
 
20558
20618
  var t = ws ? write_ws_xlml_names(ws, opts, idx, wb) : "";
20559
20619
  if(t.length > 0) o.push("<Names>" + t + "</Names>");
@@ -20785,7 +20845,7 @@ var parse_BIFFSurface = make_BIFFChartType("surfaceChart");
20785
20845
  // 2.3.2
20786
20846
  function parse_workbook(blob, options) {
20787
20847
  var wb = ({opts:{}});
20788
- var Sheets = {};
20848
+ var Sheets = sheet_map_new();
20789
20849
  if(DENSE != null && options.dense == null) options.dense = DENSE;
20790
20850
  var out = ({}); if(options.dense) out["!data"] = [];
20791
20851
  var Directory = {};
@@ -21226,7 +21286,7 @@ wb.opts.Date1904 = Workbook.WBProps.date1904 = val; break;
21226
21286
  finalize_sheet_visuals(out);
21227
21287
  Workbook.Sheets.push(wsprops);
21228
21288
  }
21229
- if(cur_sheet === "") Preamble = out; else Sheets[cur_sheet] = out;
21289
+ if(cur_sheet === "") Preamble = out; else sheet_map_set(Sheets, cur_sheet, out);
21230
21290
  out = ({}); if(options.dense) out["!data"] = [];
21231
21291
  } break;
21232
21292
  case 0x0009: case 0x0209: case 0x0409: case 0x0809 /* BOF */: {
@@ -21525,10 +21585,13 @@ if(!cur_sheet) Workbook.WBProps.CodeName = val || "ThisWorkbook";
21525
21585
  if(!wb.SheetNames.length && Preamble["!ref"]) {
21526
21586
  wb.SheetNames.push("Sheet1");
21527
21587
  /*jshint -W069 */
21528
- if(wb.Sheets) wb.Sheets["Sheet1"] = Preamble;
21588
+ if(wb.Sheets) sheet_map_set(wb.Sheets, "Sheet1", Preamble);
21529
21589
  /*jshint +W069 */
21530
21590
  } else wb.Preamble=Preamble;
21531
- if(wb.Sheets) FilterDatabases.forEach(function(r,i) { wb.Sheets[wb.SheetNames[i]]['!autofilter'] = r; });
21591
+ if(wb.Sheets) FilterDatabases.forEach(function(r,i) {
21592
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[i]);
21593
+ if(ws) ws['!autofilter'] = r;
21594
+ });
21532
21595
  wb.Strings = sst;
21533
21596
  wb.SSF = dup(table_fmt);
21534
21597
  if(opts.enc) wb.Encryption = opts.enc;
@@ -23153,7 +23216,7 @@ function write_biff2_buf(wb, opts) {
23153
23216
  o.cellXfs = [{numFmtId: 0}];
23154
23217
  o._BIFF2FmtTable = ["General"]; o._Fonts = [];
23155
23218
  var body = buf_array();
23156
- write_ws_biff2(body, wb.Sheets[wb.SheetNames[idx]], idx, o, wb);
23219
+ write_ws_biff2(body, sheet_map_get(wb.Sheets, wb.SheetNames[idx]), idx, o, wb);
23157
23220
 
23158
23221
  o._BIFF2FmtTable.forEach(function(f) {
23159
23222
  if(o.biff <= 3) write_biff_rec(ba, 0x001E, write_BIFF2Format(f));
@@ -23563,7 +23626,7 @@ function write_ws_biff8_cell(ba, cell, R, C, opts, date1904) {
23563
23626
  /* [MS-XLS] 2.1.7.20.5 */
23564
23627
  function write_ws_biff8(idx, opts, wb) {
23565
23628
  var ba = buf_array();
23566
- var s = wb.SheetNames[idx], ws = wb.Sheets[s] || {};
23629
+ var s = wb.SheetNames[idx], ws = sheet_map_get(wb.Sheets, s) || {};
23567
23630
  var _WB = ((wb||{}).Workbook||{});
23568
23631
  var _sheet = ((_WB.Sheets||[])[idx]||{});
23569
23632
  var dense = ws["!data"] != null;
@@ -23762,7 +23825,7 @@ function write_biff8_buf(wb, opts) {
23762
23825
 
23763
23826
  function write_biff_buf(wb, opts) {
23764
23827
  for(var i = 0; i <= wb.SheetNames.length; ++i) {
23765
- var ws = wb.Sheets[wb.SheetNames[i]];
23828
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[i]);
23766
23829
  if(!ws || !ws["!ref"]) continue;
23767
23830
  var range = decode_range(ws["!ref"]);
23768
23831
  if(range.e.c > 255) { // note: 255 is IV
@@ -23844,15 +23907,66 @@ function html_to_sheet(str, _opts) {
23844
23907
  return ws;
23845
23908
  }
23846
23909
 
23847
- function cssesc(x) { return escapexml(String(x).replace(/"/g, "'")); }
23848
23910
  function css_color(color) {
23849
23911
  if(!color) return "";
23850
- if(color.rgb) return "#" + String(color.rgb).slice(-6);
23912
+ if(color.rgb && /^[0-9A-Fa-f]{6}(?:[0-9A-Fa-f]{2})?$/.test(String(color.rgb))) return "#" + String(color.rgb).slice(-6);
23851
23913
  return "";
23852
23914
  }
23853
23915
  function css_font_family(name) {
23854
23916
  if(!name) return "";
23855
- return "'" + cssesc(name).replace(/'/g, "\\'") + "'";
23917
+ return "'" + css_string_escape(name, "'") + "'";
23918
+ }
23919
+
23920
+ function html_attr_escape(value) {
23921
+ return String(value).replace(/[&<>"']/g, function(ch) {
23922
+ return ch == "&" ? "&amp;" : ch == "<" ? "&lt;" : ch == ">" ? "&gt;" : ch == '"' ? "&quot;" : "&#39;";
23923
+ });
23924
+ }
23925
+ function html_writextag(tag, content, attrs) {
23926
+ var out = ["<", tag];
23927
+ if(attrs) keys(attrs).forEach(function(key) { out.push(" ", key, '="', html_attr_escape(attrs[key]), '"'); });
23928
+ if(content == null) { out.push("/>"); return out.join(""); }
23929
+ out.push(">", content, "</", tag, ">");
23930
+ return out.join("");
23931
+ }
23932
+ function safe_html_href(value) {
23933
+ var href = String(value == null ? "" : value).trim();
23934
+ if(!href || href.slice(0, 2) == "//") return null;
23935
+ var colon = href.indexOf(":"), prefix = colon == -1 ? "" : href.slice(0, colon), compact = "";
23936
+ for(var i = 0; i < prefix.length; ++i) if(prefix.charCodeAt(i) > 32 && prefix.charCodeAt(i) != 127) compact += prefix.charAt(i);
23937
+ if(colon != -1 && !/^(?:https?|mailto|tel)$/i.test(compact)) return null;
23938
+ return href;
23939
+ }
23940
+ function safe_html_image_src(value) {
23941
+ var src = String(value == null ? "" : value);
23942
+ return /^data:image\/[A-Za-z0-9.+-]+;base64,[A-Za-z0-9+/=\r\n]+$/.test(src) ? src : null;
23943
+ }
23944
+ function sanitize_cell_html(value) {
23945
+ var html = String(value == null ? "" : value), out = [], pos = 0;
23946
+ while(pos < html.length) {
23947
+ var start = html.indexOf("<", pos);
23948
+ if(start == -1) { out.push(html.slice(pos)); break; }
23949
+ out.push(html.slice(pos, start));
23950
+ var end = html.indexOf(">", start + 1);
23951
+ if(end == -1) { out.push("&lt;", html.slice(start + 1)); break; }
23952
+ var raw = html.slice(start + 1, end).trim(), lower = raw.toLowerCase();
23953
+ if(/^(?:\/?(?:b|i|s|sup|sub)|br\s*\/?)$/.test(lower)) out.push("<", lower == "br" ? "br/" : lower, ">");
23954
+ else if(lower == "/span") out.push("</span>");
23955
+ else if(lower.slice(0, 12) == 'span style="' && raw.charAt(raw.length - 1) == '"') {
23956
+ var declarations = raw.slice(12, -1).split(";"), safe = [];
23957
+ declarations.forEach(function(decl) {
23958
+ var colon = decl.indexOf(":"), key = colon == -1 ? "" : decl.slice(0, colon).trim().toLowerCase(), val = colon == -1 ? "" : decl.slice(colon + 1).trim().toLowerCase();
23959
+ if(key == "text-decoration" && val == "underline") safe.push("text-decoration:underline");
23960
+ else if(key == "text-underline-style" && /^(?:single|double|single-accounting|double-accounting)$/.test(val)) safe.push("text-underline-style:" + val);
23961
+ else if(key == "font-size" && /^\d+(?:\.\d+)?pt$/.test(val)) safe.push("font-size:" + val);
23962
+ else if(key == "text-effect" && val == "outline") safe.push("text-effect:outline");
23963
+ else if(key == "text-shadow" && val == "auto") safe.push("text-shadow:auto");
23964
+ });
23965
+ out.push('<span style="', safe.join(";"), safe.length ? ";" : "", '">');
23966
+ } else out.push(html_attr_escape(html.slice(start, end + 1)));
23967
+ pos = end + 1;
23968
+ }
23969
+ return out.join("");
23856
23970
  }
23857
23971
  function html_border_style(style) {
23858
23972
  switch(style) {
@@ -23881,7 +23995,8 @@ function html_cell_style(cell, opts) {
23881
23995
  var s = cell.s, css = [];
23882
23996
  var font = s.font || {};
23883
23997
  if(font.name) css.push("font-family:" + css_font_family(font.name));
23884
- if(font.sz) css.push("font-size:" + font.sz + "pt");
23998
+ var fontSize = +font.sz;
23999
+ if(isFinite(fontSize) && fontSize > 0) css.push("font-size:" + Math.min(fontSize, 409) + "pt");
23885
24000
  if(font.bold) css.push("font-weight:bold");
23886
24001
  if(font.italic) css.push("font-style:italic");
23887
24002
  var deco = [];
@@ -23894,8 +24009,9 @@ function html_cell_style(cell, opts) {
23894
24009
  if(fill.patternType != "none" && fill.patternType != "gray125") fillColor = css_color(fill.fgColor) || css_color(fill.bgColor);
23895
24010
  if(fillColor) css.push("background-color:" + fillColor);
23896
24011
  var alignment = s.alignment || {};
23897
- if(alignment.horizontal) css.push("text-align:" + alignment.horizontal);
23898
- if(alignment.vertical) css.push("vertical-align:" + alignment.vertical);
24012
+ if(/^(?:left|right|center|justify|fill|distributed)$/.test(alignment.horizontal || "")) css.push("text-align:" + alignment.horizontal);
24013
+ var vertical = alignment.vertical == "center" ? "middle" : alignment.vertical;
24014
+ if(/^(?:top|middle|bottom|baseline)$/.test(vertical || "")) css.push("vertical-align:" + vertical);
23899
24015
  if(alignment.textRotation != null && alignment.textRotation !== 0) {
23900
24016
  var deg = alignment.textRotation == 255 ? 90 : alignment.textRotation > 90 ? 90 - alignment.textRotation : alignment.textRotation;
23901
24017
  css.push("transform:rotate(" + deg + "deg)");
@@ -23974,7 +24090,7 @@ function make_html_row(ws, r, R, o) {
23974
24090
  }
23975
24091
  }
23976
24092
  /* TODO: html entities */
23977
- var w = (cell && cell.v != null) && (cell.h || escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
24093
+ var w = (cell && cell.v != null) && (cell.h ? sanitize_cell_html(cell.h) : escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
23978
24094
  sp = ({});
23979
24095
  if(RS > 1) sp.rowspan = RS;
23980
24096
  if(CS > 1) sp.colspan = CS;
@@ -23982,17 +24098,18 @@ function make_html_row(ws, r, R, o) {
23982
24098
  else if(cell) {
23983
24099
  sp["data-t"] = cell && cell.t || 'z';
23984
24100
  // note: data-v is unaffected by the timezone interpretation
23985
- if(cell.v != null) sp["data-v"] = escapehtml(cell.v instanceof Date ? cell.v.toISOString() : cell.v);
24101
+ if(cell.v != null) sp["data-v"] = cell.v instanceof Date ? cell.v.toISOString() : cell.v;
23986
24102
  if(cell.z != null) sp["data-z"] = cell.z;
23987
- if(cell.f != null) sp["data-f"] = escapehtml(cell.f);
23988
- if(cell.l && (cell.l.Target || "#").charAt(0) != "#" && (!o.sanitizeLinks || (cell.l.Target || "").slice(0, 11).toLowerCase() != 'javascript:')) w = '<a href="' + escapehtml(cell.l.Target) +'">' + w + '</a>';
24103
+ if(cell.f != null) sp["data-f"] = cell.f;
24104
+ var href = cell.l && safe_html_href(cell.l.Target);
24105
+ if(href) w = '<a href="' + html_attr_escape(href) +'">' + w + '</a>';
23989
24106
  }
23990
24107
  var cstyle = html_cell_style(stylecell, o);
23991
24108
  var lstyle = html_cell_layout_style(stylecell, o, C, CS, cols);
23992
24109
  if(lstyle) cstyle = cstyle ? cstyle + ";" + lstyle : lstyle;
23993
24110
  if(cstyle) sp.style = cstyle;
23994
24111
  sp.id = (o.id || "sjs") + "-" + coord;
23995
- oo.push(writextag('td', w, sp));
24112
+ oo.push(html_writextag('td', w, sp));
23996
24113
  }
23997
24114
  var rsp = ({}), rstyle = [];
23998
24115
  if(row) {
@@ -24000,7 +24117,7 @@ function make_html_row(ws, r, R, o) {
24000
24117
  if(o.browserPixels) rstyle.push("height:" + html_row_height(row) + "px");
24001
24118
  }
24002
24119
  if(rstyle.length) rsp.style = rstyle.join(";");
24003
- return writextag('tr', oo.join(""), rsp);
24120
+ return html_writextag('tr', oo.join(""), rsp);
24004
24121
  }
24005
24122
 
24006
24123
  var HTML_BEGIN = '<html><head><meta charset="utf-8"/><title>SheetJS Table Export</title></head><body>';
@@ -24136,8 +24253,10 @@ function render_html_drawings(ws, opts) {
24136
24253
  var out = [], drawings = ws["!drawings"] || {}, charts = ws["!charts"] || [];
24137
24254
  if(opts && opts.drawings && drawings.images) drawings.images.forEach(function(img) {
24138
24255
  if(!img || !img.dataURI) return;
24256
+ var src = safe_html_image_src(img.dataURI);
24257
+ if(!src) return;
24139
24258
  var pos = html_anchor_pos(ws, img.anchor, opts);
24140
- out.push('<img class="sjs-drawing-image" src="' + img.dataURI + '" style="' + html_abs_style(pos) + '"/>');
24259
+ out.push('<img class="sjs-drawing-image" src="' + html_attr_escape(src) + '" style="' + html_abs_style(pos) + '"/>');
24141
24260
  });
24142
24261
  if(opts && opts.charts) charts.forEach(function(chart) {
24143
24262
  var pos = html_anchor_pos(ws, chart.anchor, opts);
@@ -24152,7 +24271,7 @@ function make_html_preamble(ws, R, o) {
24152
24271
  if(o && o.id) tattr.id = o.id;
24153
24272
  if(o && (o.browserPixels || o.autoFit)) tstyle.push("border-collapse:collapse;table-layout:fixed");
24154
24273
  if(tstyle.length) tattr.style = tstyle.join(";");
24155
- var table = writextag("table", "", tattr).replace(/<\/table>$/, "");
24274
+ var table = html_writextag("table", "", tattr).replace(/<\/table>$/, "");
24156
24275
  var cols = o && o._htmlCols || ws["!cols"];
24157
24276
  if(o && (o.browserPixels || o.autoFit) && cols) {
24158
24277
  out.push("<colgroup>");
@@ -24160,7 +24279,7 @@ function make_html_preamble(ws, R, o) {
24160
24279
  var col = cols[C], style = [];
24161
24280
  style.push("width:" + html_col_width(col) + "px");
24162
24281
  if(col && col.hidden) style.push("display:none");
24163
- out.push(writextag("col", null, {style:style.join(";")}));
24282
+ out.push(html_writextag("col", null, {style:style.join(";")}));
24164
24283
  }
24165
24284
  out.push("</colgroup>");
24166
24285
  }
@@ -24327,7 +24446,7 @@ function parse_text_p(text) {
24327
24446
  .replace(/<text:s text:c="(\d+)"\/>/g, function($$,$1) { return Array(parseInt($1,10)+1).join(" "); })
24328
24447
  .replace(/<text:tab[^<>]*\/>/g,"\t")
24329
24448
  .replace(/<text:line-break\/>/g,"\n");
24330
- var v = unescapexml(fixed.replace(/<[^<>]*>/g,""));
24449
+ var v = unescapexml(strip_xml_tags(fixed));
24331
24450
 
24332
24451
  return [v];
24333
24452
  }
@@ -24564,7 +24683,7 @@ function parse_content_xml(d, _opts, _nfm) {
24564
24683
  var nfidx, NF = "", pidx = 0;
24565
24684
  var sheetag;
24566
24685
  var rowtag;
24567
- var Sheets = {}, SheetNames = [];
24686
+ var Sheets = sheet_map_new(), SheetNames = [];
24568
24687
  var ws = ({}); if(opts.dense) ws["!data"] = [];
24569
24688
  var Rn, q;
24570
24689
  var ctag = ({value:""}), ctag2 = ({});
@@ -24601,7 +24720,7 @@ function parse_content_xml(d, _opts, _nfm) {
24601
24720
  sheetag.name = sheetag['名称'] || sheetag.name;
24602
24721
  if(typeof JSON !== 'undefined') JSON.stringify(sheetag);
24603
24722
  SheetNames.push(sheetag.name);
24604
- Sheets[sheetag.name] = ws;
24723
+ sheet_map_set(Sheets, sheetag.name, ws);
24605
24724
  WB.Sheets.push({
24606
24725
  /* TODO: CodeName */
24607
24726
  Hidden: (tstyles[sheetag["style-name"]] && tstyles[sheetag["style-name"]]["display"] ? (parsexmlbool(tstyles[sheetag["style-name"]]["display"]) ? 0 : 1) : 0)
@@ -24957,7 +25076,9 @@ function parse_content_xml(d, _opts, _nfm) {
24957
25076
  if(Rn[1]==='/') break;
24958
25077
  try {
24959
25078
  _Ref = ods_to_csf_3D(parsexmltag(Rn[0])['target-range-address']);
24960
- Sheets[_Ref[0]]['!autofilter'] = { ref:_Ref[1] };
25079
+ if(Object.prototype.hasOwnProperty.call(Sheets, _Ref[0]) && Sheets[_Ref[0]]) {
25080
+ Sheets[_Ref[0]]['!autofilter'] = { ref:_Ref[1] };
25081
+ }
24961
25082
  } catch(e) {/* empty */}
24962
25083
  break;
24963
25084
 
@@ -25467,7 +25588,7 @@ var write_content_ods = /* @__PURE__ */(function() {
25467
25588
 
25468
25589
  /* column styles */
25469
25590
  var cidx = 0;
25470
- wb.SheetNames.map(function(n) { return wb.Sheets[n]; }).forEach(function(ws) {
25591
+ wb.SheetNames.map(function(n) { return sheet_map_get(wb.Sheets, n); }).forEach(function(ws) {
25471
25592
  if(!ws) return;
25472
25593
  if(ws["!cols"]) {
25473
25594
  for(var C = 0; C < ws["!cols"].length; ++C) if(ws["!cols"][C]) {
@@ -25486,7 +25607,7 @@ var write_content_ods = /* @__PURE__ */(function() {
25486
25607
 
25487
25608
  /* row styles */
25488
25609
  var ridx = 0;
25489
- wb.SheetNames.map(function(n) { return wb.Sheets[n]; }).forEach(function(ws) {
25610
+ wb.SheetNames.map(function(n) { return sheet_map_get(wb.Sheets, n); }).forEach(function(ws) {
25490
25611
  if(!ws) return;
25491
25612
  if(ws["!rows"]) {
25492
25613
  for(var R = 0; R < ws["!rows"].length; ++R) if(ws["!rows"][R]) {
@@ -25519,7 +25640,7 @@ var write_content_ods = /* @__PURE__ */(function() {
25519
25640
  /* number formats, table cells, text */
25520
25641
  var nfs = {};
25521
25642
  var nfi = 69;
25522
- wb.SheetNames.map(function(n) { return wb.Sheets[n]; }).forEach(function(ws) {
25643
+ wb.SheetNames.map(function(n) { return sheet_map_get(wb.Sheets, n); }).forEach(function(ws) {
25523
25644
  if(!ws) return;
25524
25645
  var dense = (ws["!data"] != null);
25525
25646
  if(!ws["!ref"]) return;
@@ -25602,7 +25723,7 @@ var write_content_ods = /* @__PURE__ */(function() {
25602
25723
  o.push(' <office:body>\n');
25603
25724
  o.push(' <office:spreadsheet>\n');
25604
25725
  if(((wb.Workbook||{}).WBProps||{}).date1904) o.push(' <table:calculation-settings table:case-sensitive="false" table:search-criteria-must-apply-to-whole-cell="true" table:use-wildcards="true" table:use-regular-expressions="false" table:automatic-find-labels="false">\n <table:null-date table:date-value="1904-01-01"/>\n </table:calculation-settings>\n');
25605
- for(var i = 0; i != wb.SheetNames.length; ++i) o.push(write_ws(wb.Sheets[wb.SheetNames[i]], wb, i, opts, nfs, ((wb.Workbook||{}).WBProps||{}).date1904));
25726
+ for(var i = 0; i != wb.SheetNames.length; ++i) o.push(write_ws(sheet_map_get(wb.Sheets, wb.SheetNames[i]), wb, i, opts, nfs, ((wb.Workbook||{}).WBProps||{}).date1904));
25606
25727
  if((wb.Workbook||{}).Names) o.push(write_names_ods(wb.Workbook.Names, wb.SheetNames, -1));
25607
25728
  o.push(' </office:spreadsheet>\n');
25608
25729
  o.push(' </office:body>\n');
@@ -25654,7 +25775,6 @@ function write_ods(wb, opts) {
25654
25775
 
25655
25776
  return zip;
25656
25777
  }
25657
-
25658
25778
  /*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
25659
25779
  var subarray = function() {
25660
25780
  try {
@@ -27172,7 +27292,7 @@ function write_numbers_iwa(wb, opts) {
27172
27292
  docroot = numbers_iwa_find(cfb, deps, 1);
27173
27293
  sheetrefs = mappa(parse_shallow(docroot.messages[0].data)[1], parse_TSP_Reference);
27174
27294
  }
27175
- write_numbers_ws(cfb, deps, wb.Sheets[name], name, idx, sheetrefs[idx]);
27295
+ write_numbers_ws(cfb, deps, sheet_map_get(wb.Sheets, name), name, idx, sheetrefs[idx]);
27176
27296
  });
27177
27297
  return cfb;
27178
27298
  }
@@ -28090,7 +28210,7 @@ function safe_parse_sheet(zip, path, relsPath, sheet, idx, sheetRels, sheets, st
28090
28210
  case 'dialog': _ws = parse_ds(data, path, idx, opts, sheetRels[sheet], wb, themes, styles); break;
28091
28211
  default: throw new Error("Unrecognized sheet type " + stype);
28092
28212
  }
28093
- sheets[sheet] = _ws;
28213
+ sheet_map_set(sheets, sheet, _ws);
28094
28214
 
28095
28215
  /* scan rels for comments and threaded comments */
28096
28216
  var comments = [], tcomments = [];
@@ -28213,7 +28333,7 @@ function parse_zip(zip, opts) {
28213
28333
  if(opts.bookSheets && typeof sheets !== 'undefined') out.SheetNames = sheets;
28214
28334
  if(opts.bookSheets ? out.SheetNames : opts.bookProps) return out;
28215
28335
  }
28216
- sheets = {};
28336
+ sheets = sheet_map_new();
28217
28337
 
28218
28338
  var deps = {};
28219
28339
  if(opts.bookDeps && dir.calcchain) deps=parse_cc(getzipdata(zip, strip_front_slash(dir.calcchain)),dir.calcchain,opts);
@@ -28413,7 +28533,7 @@ f = "docProps/app.xml";
28413
28533
 
28414
28534
  for(rId=1;rId <= wb.SheetNames.length; ++rId) {
28415
28535
  var wsrels = {'!id':{}};
28416
- var ws = wb.Sheets[wb.SheetNames[rId-1]];
28536
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[rId-1]);
28417
28537
  var _type = (ws || {})["!type"] || "sheet";
28418
28538
  switch(_type) {
28419
28539
  case "chart":
@@ -28568,7 +28688,7 @@ f = "docProps/app.xml";
28568
28688
 
28569
28689
  for(rId=1;rId <= wb.SheetNames.length; ++rId) {
28570
28690
  var wsrels = {'!id':{}};
28571
- var ws = wb.Sheets[wb.SheetNames[rId-1]];
28691
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[rId-1]);
28572
28692
  var _type = (ws || {})["!type"] || "sheet";
28573
28693
  switch(_type) {
28574
28694
  case "chart":
@@ -28664,7 +28784,6 @@ f = "docProps/app.xml";
28664
28784
  delete opts.revssf; delete opts.ssf;
28665
28785
  return zip;
28666
28786
  }
28667
-
28668
28787
  function firstbyte(f,o) {
28669
28788
  var x = "";
28670
28789
  switch((o||{}).type || "base64") {
@@ -28933,18 +29052,18 @@ function writeSync(wb, opts) {
28933
29052
  case 'xml':
28934
29053
  case 'xlml': return write_string_type(write_xlml(wb, o), o);
28935
29054
  case 'slk':
28936
- case 'sylk': return write_string_type(SYLK.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb), o);
29055
+ case 'sylk': return write_string_type(SYLK.from_sheet(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o, wb), o);
28937
29056
  case 'htm':
28938
- case 'html': return write_string_type(sheet_to_html(wb.Sheets[wb.SheetNames[idx]], o), o);
28939
- case 'txt': return write_stxt_type(sheet_to_txt(wb.Sheets[wb.SheetNames[idx]], o), o);
28940
- case 'csv': return write_string_type(sheet_to_csv(wb.Sheets[wb.SheetNames[idx]], o), o, "\ufeff");
28941
- case 'dif': return write_string_type(DIF.from_sheet(wb.Sheets[wb.SheetNames[idx]], o), o);
28942
- case 'dbf': return write_binary_type(DBF.from_sheet(wb.Sheets[wb.SheetNames[idx]], o), o);
28943
- case 'prn': return write_string_type(PRN.from_sheet(wb.Sheets[wb.SheetNames[idx]], o), o);
28944
- case 'rtf': return write_string_type(sheet_to_rtf(wb.Sheets[wb.SheetNames[idx]], o), o);
28945
- case 'eth': return write_string_type(ETH.from_sheet(wb.Sheets[wb.SheetNames[idx]], o), o);
29057
+ case 'html': return write_string_type(sheet_to_html(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29058
+ case 'txt': return write_stxt_type(sheet_to_txt(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29059
+ case 'csv': return write_string_type(sheet_to_csv(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o, "\ufeff");
29060
+ case 'dif': return write_string_type(DIF.from_sheet(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29061
+ case 'dbf': return write_binary_type(DBF.from_sheet(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29062
+ case 'prn': return write_string_type(PRN.from_sheet(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29063
+ case 'rtf': return write_string_type(sheet_to_rtf(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29064
+ case 'eth': return write_string_type(ETH.from_sheet(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
28946
29065
  case 'fods': return write_string_type(write_ods(wb, o), o);
28947
- case 'wk1': return write_binary_type(WK_.sheet_to_wk1(wb.Sheets[wb.SheetNames[idx]], o), o);
29066
+ case 'wk1': return write_binary_type(WK_.sheet_to_wk1(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
28948
29067
  case 'wk3': return write_binary_type(WK_.book_to_wk3(wb, o), o);
28949
29068
  case 'biff2': if(!o.biff) o.biff = 2; /* falls through */
28950
29069
  case 'biff3': if(!o.biff) o.biff = 3; /* falls through */
@@ -29204,6 +29323,7 @@ function sheet_add_json(_ws, js, opts) {
29204
29323
  var _origin = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin;
29205
29324
  _R = _origin.r; _C = _origin.c;
29206
29325
  }
29326
+ if(!isFinite(_R) || _R !== Math.floor(_R) || _R < -1 || !isFinite(_C) || _C !== Math.floor(_C) || _C < 0) throw new Error("Invalid origin");
29207
29327
  }
29208
29328
  var range = ({s: {c:0, r:0}, e: {c:_C, r:_R + js.length - 1 + offset}});
29209
29329
  if(ws['!ref']) {
@@ -29295,7 +29415,7 @@ function wb_sheet_idx(wb, sh) {
29295
29415
 
29296
29416
  /* simple blank or single-sheet workbook object */
29297
29417
  function book_new(ws, wsname) {
29298
- var wb = { SheetNames: [], Sheets: {} };
29418
+ var wb = { SheetNames: [], Sheets: sheet_map_new() };
29299
29419
  if(ws) book_append_sheet(wb, ws, wsname || "Sheet1");
29300
29420
  return wb;
29301
29421
  }
@@ -29315,7 +29435,7 @@ function book_append_sheet(wb, ws, name, roll) {
29315
29435
  if(wb.SheetNames.indexOf(name) >= 0) throw new Error("Worksheet with name |" + name + "| already exists!");
29316
29436
 
29317
29437
  wb.SheetNames.push(name);
29318
- wb.Sheets[name] = ws;
29438
+ sheet_map_set(wb.Sheets, name, ws);
29319
29439
  return name;
29320
29440
  }
29321
29441
 
@@ -29382,7 +29502,6 @@ function sheet_set_array_formula(ws, range, formula, dynamic) {
29382
29502
  ws["!ref"] = encode_range(wsr);
29383
29503
  return ws;
29384
29504
  }
29385
-
29386
29505
  var utils = {
29387
29506
  encode_col: encode_col,
29388
29507
  encode_row: encode_row,
@@ -29539,7 +29658,7 @@ function write_json_stream(sheet, opts) {
29539
29658
  if ((rowinfo[R]||{}).hidden) {
29540
29659
  ++R;
29541
29660
  continue;
29542
- };
29661
+ }
29543
29662
  var row = make_json_row(sheet, r, R, cols, header, hdr, o);
29544
29663
  ++R;
29545
29664
  if((row.isempty === false) || (header === 1 ? o.blankrows !== false : !!o.blankrows)) {
@@ -29568,7 +29687,7 @@ function write_xlml_stream(wb, o) {
29568
29687
 
29569
29688
  /* do one pass to determine styles since they must be added before tables */
29570
29689
  wb.SheetNames.forEach(function(n) {
29571
- var ws = wb.Sheets[n];
29690
+ var ws = sheet_map_get(wb.Sheets, n);
29572
29691
  if(!ws || !ws["!ref"]) return;
29573
29692
  var range = decode_range(ws["!ref"]);
29574
29693
  var dense = ws["!data"] != null;
@@ -29588,7 +29707,7 @@ function write_xlml_stream(wb, o) {
29588
29707
  });
29589
29708
  var sty = write_sty_xlml(wb, opts);
29590
29709
 
29591
- var stage = 0, wsidx = 0, ws = wb.Sheets[wb.SheetNames[wsidx]], range = safe_decode_range(ws), R = -1, T = false;
29710
+ var stage = 0, wsidx = 0, ws = sheet_map_get(wb.Sheets, wb.SheetNames[wsidx]), range = safe_decode_range(ws), R = -1, T = false;
29592
29711
 
29593
29712
  var marr = [], mi = 0, dense = false, darr = [], addr = {r:0,c:0};
29594
29713
 
@@ -29628,7 +29747,7 @@ function write_xlml_stream(wb, o) {
29628
29747
 
29629
29748
  stream.push("<Worksheet" + wxt_helper({ "ss:Name": escapexml(wb.SheetNames[wsidx])}) + ">");
29630
29749
 
29631
- ws = wb.Sheets[wb.SheetNames[wsidx]];
29750
+ ws = sheet_map_get(wb.Sheets, wb.SheetNames[wsidx]);
29632
29751
  if(!ws) { stream.push("</Worksheet>"); return void ++wsidx; }
29633
29752
 
29634
29753
  var names = write_ws_xlml_names(ws, opts, wsidx, wb);