version bump 0.18.0

- Removed global variables `XLS` and `ODS` from standalone browser build
- Removed `dist/jszip.js` from the package
- XLSX SST parse, fixes #2503
This commit is contained in:
SheetJS 2022-02-01 00:58:45 -05:00
parent cb8046c447
commit 5f0f2c91c5
41 changed files with 5331 additions and 436 deletions

View File

@ -122,6 +122,7 @@ Community Translations of this README:
+ [Lotus 1-2-3 (WKS/WK1/WK2/WK3/WK4/123)](#lotus-1-2-3-wkswk1wk2wk3wk4123)
+ [Quattro Pro (WQ1/WQ2/WB1/WB2/WB3/QPW)](#quattro-pro-wq1wq2wb1wb2wb3qpw)
+ [Works for DOS / Windows Spreadsheet (WKS/XLR)](#works-for-dos--windows-spreadsheet-wksxlr)
+ [Numbers 3.0+ / iWork 2013+ Spreadsheet (NUMBERS)](#numbers-30--iwork-2013-spreadsheet-numbers)
+ [OpenDocument Spreadsheet (ODS/FODS)](#opendocument-spreadsheet-odsfods)
+ [Uniform Office Spreadsheet (UOS1/2)](#uniform-office-spreadsheet-uos12)
* [Other Single-Worksheet Formats](#other-single-worksheet-formats)
@ -1840,7 +1841,7 @@ file but Excel will know how to handle it. This library applies similar logic:
| `0xD0` | CFB Container | BIFF 5/8 or protected XLSX/XLSB or WQ3/QPW or XLR |
| `0x09` | BIFF Stream | BIFF 2/3/4/5 |
| `0x3C` | XML/HTML | SpreadsheetML / Flat ODS / UOS1 / HTML / plain text |
| `0x50` | ZIP Archive | XLSB or XLSX/M or ODS or UOS2 or plain text |
| `0x50` | ZIP Archive | XLSB or XLSX/M or ODS or UOS2 or NUMBERS or text |
| `0x49` | Plain Text | SYLK or plain text |
| `0x54` | Plain Text | DIF or plain text |
| `0xEF` | UTF8 Encoded | SpreadsheetML / Flat ODS / UOS1 / HTML / plain text |
@ -2484,6 +2485,7 @@ Despite the library name `xlsx`, it supports numerous spreadsheet file formats:
| Lotus Formatted Text (PRN) | ✔ | ✔ |
| UTF-16 Unicode Text (TXT) | ✔ | ✔ |
| **Other Workbook/Worksheet Formats** |:-----:|:-----:|
| Numbers 3.0+ / iWork 2013+ Spreadsheet (NUMBERS) | ✔ | |
| OpenDocument Spreadsheet (ODS) | ✔ | ✔ |
| Flat XML ODF Spreadsheet (FODS) | ✔ | ✔ |
| Uniform Office Format Spreadsheet (标文通 UOS1/UOS2) | ✔ | |
@ -2669,6 +2671,21 @@ XLR also includes a `WksSSWorkBook` stream similar to Lotus FM3/FMT files.
</details>
#### Numbers 3.0+ / iWork 2013+ Spreadsheet (NUMBERS)
<details>
<summary>(click to show)</summary>
iWork 2013 (Numbers 3.0 / Pages 5.0 / Keynote 6.0) switched from a proprietary
XML-based format to the current file format based on the iWork Archive (IWA).
This format has been used up through the current release (Numbers 11.2).
The parser focuses on extracting raw data from tables. Numbers technically
supports multiple tables in a logical worksheet, including custom titles. This
parser will generate one worksheet per Numbers table.
</details>
#### OpenDocument Spreadsheet (ODS/FODS)
<details>

View File

@ -1 +1 @@
XLSX.version = '0.17.5';
XLSX.version = '0.18.0';

View File

@ -8,7 +8,7 @@ if(typeof module !== "undefined" && typeof require !== 'undefined') {
}
}
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
var VALID_ANSI = [ 874, 932, 936, 949, 950, 10000 ];
for(var i = 0; i <= 8; ++i) VALID_ANSI.push(1250 + i);
/* ECMA-376 Part I 18.4.1 charset to codepage mapping */
var CS2CP = ({

View File

@ -81,15 +81,19 @@ function parse_rpr(rpr) {
case '<color':
if(y.rgb) font.color = y.rgb.slice(2,8);
break;
case '<color>': case '<color/>': case '</color>': break;
/* 18.8.18 family ST_FontFamily */
case '<family': font.family = y.val; break;
case '<family>': case '<family/>': case '</family>': break;
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty TODO */
case '<vertAlign': font.valign = y.val; break;
case '<vertAlign>': case '<vertAlign/>': case '</vertAlign>': break;
/* 18.8.35 scheme CT_FontScheme TODO */
case '<scheme': break;
case '<scheme>': case '<scheme/>': case '</scheme>': break;
/* 18.2.10 extLst CT_ExtensionList ? */
case '<extLst': case '<extLst>': case '</extLst>': break;

View File

@ -387,7 +387,7 @@ function write_biff_buf(wb/*:Workbook*/, opts/*:WriteOpts*/) {
if(!ws || !ws["!ref"]) continue;
var range = decode_range(ws["!ref"]);
if(range.e.c > 255) { // note: 255 is IV
console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
}

View File

@ -1,25 +0,0 @@
function write_sheet_index(wb/*:Workbook*/, sheet/*:?string*/)/*:number*/ {
if(!sheet) return 0;
var idx = wb.SheetNames.indexOf(sheet);
if(idx == -1) throw new Error("Sheet not found: " + sheet);
return idx;
}
function write_obj_str(factory/*:WriteObjStrFactory*/) {
return function write_str(wb/*:Workbook*/, o/*:WriteOpts*/)/*:string*/ {
var idx = write_sheet_index(wb, o.sheet);
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});

View File

@ -40,7 +40,7 @@ var NUMBERS = (function() {
return new DataView(array.buffer, array.byteOffset, array.byteLength);
};
var u8str = function(u8) {
return new TextDecoder().decode(u8);
return typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
};
var u8concat = function(u8a) {
var len = u8a.reduce(function(acc, x) {
@ -280,12 +280,17 @@ var NUMBERS = (function() {
}
// src/prebnccell.ts
function parseit(buf, version) {
function parseit(buf, sst, rsst, version) {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 16270) * 4;
var sidx = -1, ieee = NaN, dt = NaN;
var data_offset = 12 + popcnt(flags & 3470) * 4;
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if (flags & 512) {
ridx = dv.getUint32(data_offset, true);
data_offset += 4;
}
data_offset += popcnt(flags & 12288) * 4;
if (flags & 16) {
sidx = dv.getUint32(data_offset, true);
data_offset += 4;
@ -295,7 +300,7 @@ var NUMBERS = (function() {
data_offset += 8;
}
if (flags & 64) {
dt = dv.getFloat64(data_offset, true);
dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1e3);
data_offset += 8;
}
var ret;
@ -306,12 +311,10 @@ var NUMBERS = (function() {
ret = { t: "n", v: ieee };
break;
case 3:
ret = { t: "s", v: sidx };
ret = { t: "s", v: sst[sidx] };
break;
case 5:
var dd = new Date(2001, 0, 1);
dd.setTime(dd.getTime() + dt * 1e3);
ret = { t: "d", v: dd };
ret = { t: "d", v: dt };
break;
case 6:
ret = { t: "b", v: ieee > 0 };
@ -319,17 +322,32 @@ var NUMBERS = (function() {
case 7:
ret = { t: "n", v: ieee };
break;
case 8:
ret = { t: "e", v: 0 };
break;
case 9:
{
if (ridx > -1)
ret = { t: "s", v: rsst[ridx] };
else if (sidx > -1)
ret = { t: "s", v: sst[sidx] };
else if (!isNaN(ieee))
ret = { t: "n", v: ieee };
else
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
break;
default:
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
return ret;
}
function parse(buf) {
function parse(buf, sst, rsst) {
var version = buf[0];
switch (version) {
case 3:
case 4:
return parseit(buf, version);
return parseit(buf, sst, rsst, version);
default:
throw new Error("Unsupported pre-BNC version ".concat(version));
}
@ -352,11 +370,18 @@ var NUMBERS = (function() {
return { Sheets: {}, SheetNames: [] };
};
var book_append_sheet = function(wb, ws, name) {
if (!name) {
for (var i = 1; i < 9999; ++i)
if (!name)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf(name = "Sheet ".concat(i)) == -1)
break;
}
}
else if (wb.SheetNames.indexOf(name) > -1)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf("".concat(name, "_").concat(i)) == -1) {
name = "".concat(name, "_").concat(i);
break;
}
}
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
};
@ -406,12 +431,31 @@ var NUMBERS = (function() {
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries || []).forEach(function(entry) {
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data) >>> 0;
data[key] = u8str(le[3][0].data);
switch (type) {
case 1:
data[key] = u8str(le[3][0].data);
break;
case 8:
{
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if (mtype != 2001)
throw new Error("2000 unexpected reference to ".concat(mtype));
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(function(x) {
return u8str(x.data);
}).join("");
}
break;
}
});
return data;
}
@ -444,6 +488,7 @@ var NUMBERS = (function() {
}, []);
}
function parse_TST_TableModelArchive(M, root, ws) {
var _a;
var pb = parse_shallow(root.data);
var range = { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } };
range.e.r = (varint_to_i32(pb[6][0].data) >>> 0) - 1;
@ -456,6 +501,7 @@ var NUMBERS = (function() {
{
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst = ((_a = store[17]) == null ? void 0 : _a[0]) ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
var tile = parse_shallow(store[3][0].data);
var tiles = [];
@ -471,12 +517,9 @@ var NUMBERS = (function() {
tile2.ref.forEach(function(row, R) {
row.forEach(function(buf, C) {
var addr = encode_cell({ r: R, c: C });
var res = parse(buf);
if (res) {
var res = parse(buf, sst, rsst);
if (res)
ws[addr] = res;
if (res.t == "s" && typeof res.v == "number")
res.v = sst[res.v];
}
});
});
});
@ -496,18 +539,16 @@ var NUMBERS = (function() {
function parse_sheetroot(M, root) {
var _a;
var pb = parse_shallow(root.data);
var out = [{ "!ref": "A1" }, ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : ""];
var out = {
name: ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : "",
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
var seen = false;
shapeoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 6e3) {
if (seen)
return;
out[0] = parse_TST_TableInfoArchive(M, m);
seen = true;
}
if (mtype == 6e3)
out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
@ -521,7 +562,9 @@ var NUMBERS = (function() {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 2) {
var root2 = parse_sheetroot(M, m);
book_append_sheet(out, root2[0], root2[1]);
root2.sheets.forEach(function(sheet) {
book_append_sheet(out, sheet, root2.name);
});
}
});
});

View File

@ -1,3 +1,26 @@
function write_obj_str(factory/*:WriteObjStrFactory*/) {
return function write_str(wb/*:Workbook*/, o/*:WriteOpts*/)/*:string*/ {
var idx = 0;
if(o.sheet) {
if(typeof o.sheet == "number") idx = o.sheet;
else idx = wb.SheetNames.indexOf(o.sheet);
if(!wb.SheetNames[idx]) throw new Error("Sheet not found: " + o.sheet + " : " + (typeof o.sheet));
}
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
function write_cfb_ctr(cfb/*:CFBContainer*/, o/*:WriteOpts*/)/*:any*/ {
switch(o.type) {
case "base64": case "binary": break;

34
dist/xlsx.core.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.core.min.map generated vendored

File diff suppressed because one or more lines are too long

652
dist/xlsx.extendscript.js generated vendored
View File

@ -9161,7 +9161,7 @@ module.exports = ZStream;
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.17.5';
XLSX.version = '0.18.0';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -9171,7 +9171,7 @@ if(typeof module !== "undefined" && typeof require !== 'undefined') {
}
}
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
var VALID_ANSI = [ 874, 932, 936, 949, 950, 10000 ];
for(var i = 0; i <= 8; ++i) VALID_ANSI.push(1250 + i);
/* ECMA-376 Part I 18.4.1 charset to codepage mapping */
var CS2CP = ({
@ -12099,6 +12099,12 @@ function getzipstr(zip, file, safe) {
try { return getzipstr(zip, file); } catch(e) { return null; }
}
function getzipbin(zip, file, safe) {
if(!safe) return getdatabin(getzipfile(zip, file));
if(!file) return null;
try { return getzipbin(zip, file); } catch(e) { return null; }
}
function zipentries(zip) {
var k = zip.FullPaths || keys(zip.files), o = [];
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i]);
@ -18015,15 +18021,19 @@ function parse_rpr(rpr) {
case '<color':
if(y.rgb) font.color = y.rgb.slice(2,8);
break;
case '<color>': case '<color/>': case '</color>': break;
/* 18.8.18 family ST_FontFamily */
case '<family': font.family = y.val; break;
case '<family>': case '<family/>': case '</family>': break;
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty TODO */
case '<vertAlign': font.valign = y.val; break;
case '<vertAlign>': case '<vertAlign/>': case '</vertAlign>': break;
/* 18.8.35 scheme CT_FontScheme TODO */
case '<scheme': break;
case '<scheme>': case '<scheme/>': case '</scheme>': break;
/* 18.2.10 extLst CT_ExtensionList ? */
case '<extLst': case '<extLst>': case '</extLst>': break;
@ -27666,14 +27676,14 @@ var PSCLSID = {
};
function parse_xls_props(cfb, props, o) {
/* [MS-OSHARED] 2.3.3.2.2 Document Summary Information Property Set */
var DSI = CFB.find(cfb, '!DocumentSummaryInformation');
var DSI = CFB.find(cfb, '/!DocumentSummaryInformation');
if(DSI && DSI.size > 0) try {
var DocSummary = parse_PropertySetStream(DSI, DocSummaryPIDDSI, PSCLSID.DSI);
for(var d in DocSummary) props[d] = DocSummary[d];
} catch(e) {if(o.WTF) throw e;/* empty */}
/* [MS-OSHARED] 2.3.3.2.1 Summary Information Property Set*/
var SI = CFB.find(cfb, '!SummaryInformation');
var SI = CFB.find(cfb, '/!SummaryInformation');
if(SI && SI.size > 0) try {
var Summary = parse_PropertySetStream(SI, SummaryPIDSI, PSCLSID.SI);
for(var s in Summary) if(props[s] == null) props[s] = Summary[s];
@ -29474,7 +29484,7 @@ function write_biff_buf(wb, opts) {
if(!ws || !ws["!ref"]) continue;
var range = decode_range(ws["!ref"]);
if(range.e.c > 255) { // note: 255 is IV
console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
}
@ -30588,31 +30598,583 @@ function write_ods(wb, opts) {
return zip;
}
function write_sheet_index(wb, sheet) {
if(!sheet) return 0;
var idx = wb.SheetNames.indexOf(sheet);
if(idx == -1) throw new Error("Sheet not found: " + sheet);
return idx;
}
var NUMBERS = (function() {
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = function(target) {
return __defProp(target, "__esModule", { value: true });
};
var __export = function(target, all) {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = function(target, module, copyDefault, desc) {
if (module && typeof module === "object" || typeof module === "function")
for (var keys = __getOwnPropNames(module), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
__defProp(target, key, { get: function(k) {
return module[k];
}.bind(null, key), enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}
return target;
};
var __toCommonJS = /* @__PURE__ */ function(cache) {
return function(module, temp) {
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
};
}(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
function write_obj_str(factory) {
return function write_str(wb, o) {
var idx = write_sheet_index(wb, o.sheet);
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
// 83_numbers.ts
var numbers_exports = {};
__export(numbers_exports, {
parse_numbers: function() {
return numbers_default;
}
});
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
// src/util.ts
var u8_to_dataview = function(array) {
return new DataView(array.buffer, array.byteOffset, array.byteLength);
};
var u8str = function(u8) {
return typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
};
var u8concat = function(u8a) {
var len = u8a.reduce(function(acc, x) {
return acc + x.length;
}, 0);
var out = new Uint8Array(len);
var off = 0;
u8a.forEach(function(u8) {
out.set(u8, off);
off += u8.length;
});
return out;
};
var popcnt = function(x) {
x -= x >> 1 & 1431655765;
x = (x & 858993459) + (x >> 2 & 858993459);
return (x + (x >> 4) & 252645135) * 16843009 >>> 24;
};
// src/proto.ts
function parse_varint49(buf, ptr) {
var l = ptr ? ptr[0] : 0;
var usz = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
usz |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 28);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 35);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 42);
++l;
if (buf[l++] < 128)
break varint;
}
if (ptr)
ptr[0] = l;
return usz;
}
function varint_to_i32(buf) {
var l = 0, i32 = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
i32 |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 28;
}
return i32;
}
function parse_shallow(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var off = ptr[0];
var num = parse_varint49(buf, ptr);
var type = num & 7;
num = Math.floor(num / 8);
var len = 0;
var res;
if (num == 0)
break;
switch (type) {
case 0:
{
var l = ptr[0];
while (buf[ptr[0]++] >= 128)
;
res = buf.slice(l, ptr[0]);
}
break;
case 5:
len = 4;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 1:
len = 8;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 2:
len = parse_varint49(buf, ptr);
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 3:
case 4:
default:
throw new Error("PB Type ".concat(type, " for Field ").concat(num, " at offset ").concat(off));
}
var v = { offset: off, data: res, type: type };
if (out[num] == null)
out[num] = [v];
else
out[num].push(v);
}
return out;
}
function mappa(data, cb) {
if (!data)
return [];
return data.map(function(d) {
var _a;
try {
return cb(d.data);
} catch (e) {
var m = (_a = e.message) == null ? void 0 : _a.match(/at offset (\d+)/);
if (m)
e.message = e.message.replace(/at offset (\d+)/, "at offset " + (+m[1] + d.offset));
throw e;
}
});
}
// src/frame.ts
function deframe(buf) {
var out = [];
var l = 0;
while (l < buf.length) {
var t = buf[l++];
var len = buf[l] | buf[l + 1] << 8 | buf[l + 2] << 16;
l += 3;
out.push(parse_snappy_chunk(t, buf.slice(l, l + len)));
l += len;
}
if (l !== buf.length)
throw new Error("data is not a valid framed stream!");
return u8concat(out);
}
function parse_snappy_chunk(type, buf) {
if (type != 0)
throw new Error("Unexpected Snappy chunk type ".concat(type));
var ptr = [0];
var usz = parse_varint49(buf, ptr);
var chunks = [];
while (ptr[0] < buf.length) {
var tag = buf[ptr[0]] & 3;
if (tag == 0) {
var len = buf[ptr[0]++] >> 2;
if (len < 60)
++len;
else {
var c = len - 59;
len = buf[ptr[0]];
if (c > 1)
len |= buf[ptr[0] + 1] << 8;
if (c > 2)
len |= buf[ptr[0] + 2] << 16;
if (c > 3)
len |= buf[ptr[0] + 3] << 24;
len >>>= 0;
len++;
ptr[0] += c;
}
chunks.push(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
continue;
} else {
var offset = 0, length = 0;
if (tag == 1) {
length = (buf[ptr[0]] >> 2 & 7) + 4;
offset = (buf[ptr[0]++] & 224) << 3;
offset |= buf[ptr[0]++];
} else {
length = (buf[ptr[0]++] >> 2) + 1;
if (tag == 2) {
offset = buf[ptr[0]] | buf[ptr[0] + 1] << 8;
ptr[0] += 2;
} else {
offset = (buf[ptr[0]] | buf[ptr[0] + 1] << 8 | buf[ptr[0] + 2] << 16 | buf[ptr[0] + 3] << 24) >>> 0;
ptr[0] += 4;
}
}
chunks = [u8concat(chunks)];
if (offset == 0)
throw new Error("Invalid offset 0");
if (offset > chunks[0].length)
throw new Error("Invalid offset beyond length");
if (length >= offset) {
chunks.push(chunks[0].slice(-offset));
length -= offset;
while (length >= chunks[chunks.length - 1].length) {
chunks.push(chunks[chunks.length - 1]);
length -= chunks[chunks.length - 1].length;
}
}
chunks.push(chunks[0].slice(-offset, -offset + length));
}
}
var o = u8concat(chunks);
if (o.length != usz)
throw new Error("Unexpected length: ".concat(o.length, " != ").concat(usz));
return o;
}
// src/iwa.ts
function parse_iwa(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var len = parse_varint49(buf, ptr);
var ai = parse_shallow(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
var res = {
id: varint_to_i32(ai[1][0].data),
messages: []
};
ai[2].forEach(function(b) {
var mi = parse_shallow(b.data);
var fl = varint_to_i32(mi[3][0].data);
res.messages.push({
meta: mi,
data: buf.slice(ptr[0], ptr[0] + fl)
});
ptr[0] += fl;
});
out.push(res);
}
return out;
}
// src/prebnccell.ts
function parseit(buf, sst, rsst, version) {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 3470) * 4;
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if (flags & 512) {
ridx = dv.getUint32(data_offset, true);
data_offset += 4;
}
data_offset += popcnt(flags & 12288) * 4;
if (flags & 16) {
sidx = dv.getUint32(data_offset, true);
data_offset += 4;
}
if (flags & 32) {
ieee = dv.getFloat64(data_offset, true);
data_offset += 8;
}
if (flags & 64) {
dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1e3);
data_offset += 8;
}
var ret;
switch (ctype) {
case 0:
break;
case 2:
ret = { t: "n", v: ieee };
break;
case 3:
ret = { t: "s", v: sst[sidx] };
break;
case 5:
ret = { t: "d", v: dt };
break;
case 6:
ret = { t: "b", v: ieee > 0 };
break;
case 7:
ret = { t: "n", v: ieee };
break;
case 8:
ret = { t: "e", v: 0 };
break;
case 9:
{
if (ridx > -1)
ret = { t: "s", v: rsst[ridx] };
else if (sidx > -1)
ret = { t: "s", v: sst[sidx] };
else if (!isNaN(ieee))
ret = { t: "n", v: ieee };
else
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
break;
default:
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
return ret;
}
function parse(buf, sst, rsst) {
var version = buf[0];
switch (version) {
case 3:
case 4:
return parseit(buf, sst, rsst, version);
default:
throw new Error("Unsupported pre-BNC version ".concat(version));
}
}
// src/numbers.ts
var encode_col = function(C) {
var s = "";
for (++C; C; C = Math.floor((C - 1) / 26))
s = String.fromCharCode((C - 1) % 26 + 65) + s;
return s;
};
var encode_cell = function(c) {
return "".concat(encode_col(c.c)).concat(c.r + 1);
};
var encode_range = function(r) {
return encode_cell(r.s) + ":" + encode_cell(r.e);
};
var book_new = function() {
return { Sheets: {}, SheetNames: [] };
};
var book_append_sheet = function(wb, ws, name) {
if (!name)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf(name = "Sheet ".concat(i)) == -1)
break;
}
else if (wb.SheetNames.indexOf(name) > -1)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf("".concat(name, "_").concat(i)) == -1) {
name = "".concat(name, "_").concat(i);
break;
}
}
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
};
function parse_numbers(cfb) {
var out = [];
cfb.FileIndex.forEach(function(s) {
if (!s.name.match(/\.iwa$/))
return;
var o;
try {
o = deframe(s.content);
} catch (e) {
return console.log("?? " + s.content.length + " " + (e.message || e));
}
var packets;
try {
packets = parse_iwa(o);
} catch (e) {
return console.log("## " + (e.message || e));
}
packets.forEach(function(packet) {
out[+packet.id] = packet.messages;
});
});
if (!out.length)
throw new Error("File has no messages");
var docroot;
out.forEach(function(iwams) {
iwams.forEach(function(iwam) {
var mtype = varint_to_i32(iwam.meta[1][0].data) >>> 0;
if (mtype == 1) {
if (!docroot)
docroot = iwam;
else
throw new Error("Document has multiple roots");
}
});
});
if (!docroot)
throw new Error("Cannot find Document root");
return parse_docroot(out, docroot);
}
var numbers_default = parse_numbers;
function parse_Reference(buf) {
var pb = parse_shallow(buf);
return parse_varint49(pb[1][0].data);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries || []).forEach(function(entry) {
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data) >>> 0;
switch (type) {
case 1:
data[key] = u8str(le[3][0].data);
break;
case 8:
{
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if (mtype != 2001)
throw new Error("2000 unexpected reference to ".concat(mtype));
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(function(x) {
return u8str(x.data);
}).join("");
}
break;
}
});
return data;
}
function parse_TST_TileRowInfo(u8) {
var pb = parse_shallow(u8);
var R = varint_to_i32(pb[1][0].data) >>> 0;
var storage = pb[3][0].data;
var offsets = u8_to_dataview(pb[4][0].data);
var cells = [];
for (var C = 0; C < offsets.byteLength / 2; ++C) {
var off = offsets.getUint16(C * 2, true);
if (off > storage.length)
continue;
cells[C] = storage.subarray(off, offsets.getUint16(C * 2 + 2, true));
}
return { R: R, cells: cells };
}
function parse_TST_Tile(M, root) {
var pb = parse_shallow(root.data);
var ri = mappa(pb[5], parse_TST_TileRowInfo);
return ri.reduce(function(acc, x) {
if (!acc[x.R])
acc[x.R] = [];
x.cells.forEach(function(cell, C) {
if (acc[x.R][C])
throw new Error("Duplicate cell r=".concat(x.R, " c=").concat(C));
acc[x.R][C] = cell;
});
return acc;
}, []);
}
function parse_TST_TableModelArchive(M, root, ws) {
var _a;
var pb = parse_shallow(root.data);
var range = { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } };
range.e.r = (varint_to_i32(pb[6][0].data) >>> 0) - 1;
if (range.e.r < 0)
throw new Error("Invalid row varint ".concat(pb[6][0].data));
range.e.c = (varint_to_i32(pb[7][0].data) >>> 0) - 1;
if (range.e.c < 0)
throw new Error("Invalid col varint ".concat(pb[7][0].data));
ws["!ref"] = encode_range(range);
{
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst = ((_a = store[17]) == null ? void 0 : _a[0]) ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
var tile = parse_shallow(store[3][0].data);
var tiles = [];
tile[1].forEach(function(t) {
var tl = parse_shallow(t.data);
var ref = M[parse_Reference(tl[2][0].data)][0];
var mtype = varint_to_i32(ref.meta[1][0].data);
if (mtype != 6002)
throw new Error("6001 unexpected reference to ".concat(mtype));
tiles.push({ id: varint_to_i32(tl[1][0].data), ref: parse_TST_Tile(M, ref) });
});
tiles.forEach(function(tile2) {
tile2.ref.forEach(function(row, R) {
row.forEach(function(buf, C) {
var addr = encode_cell({ r: R, c: C });
var res = parse(buf, sst, rsst);
if (res)
ws[addr] = res;
});
});
});
}
}
}
function parse_TST_TableInfoArchive(M, root) {
var pb = parse_shallow(root.data);
var out = { "!ref": "A1" };
var tableref = M[parse_Reference(pb[2][0].data)];
var mtype = varint_to_i32(tableref[0].meta[1][0].data);
if (mtype != 6001)
throw new Error("6000 unexpected reference to ".concat(mtype));
parse_TST_TableModelArchive(M, tableref[0], out);
return out;
}
function parse_sheetroot(M, root) {
var _a;
var pb = parse_shallow(root.data);
var out = {
name: ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : "",
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
shapeoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 6e3)
out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
}
function parse_docroot(M, root) {
var out = book_new();
var pb = parse_shallow(root.data);
var sheetoffs = mappa(pb[1], parse_Reference);
sheetoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 2) {
var root2 = parse_sheetroot(M, m);
root2.sheets.forEach(function(sheet) {
book_append_sheet(out, sheet, root2.name);
});
}
});
});
if (out.SheetNames.length == 0)
throw new Error("Empty NUMBERS file");
return out;
}
return __toCommonJS(numbers_exports);
})();
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
function fix_opts_func(defaults) {
return function fix_opts(opts) {
for(var i = 0; i != defaults.length; ++i) {
@ -30719,7 +31281,16 @@ function parse_zip(zip, opts) {
/* UOC */
if(safegetzipfile(zip, 'objectdata.xml')) return parse_ods(zip, opts);
/* Numbers */
if(safegetzipfile(zip, 'Index/Document.iwa')) throw new Error('Unsupported NUMBERS file');
if(safegetzipfile(zip, 'Index/Document.iwa')) {
if(typeof Uint8Array == "undefined") throw new Error('NUMBERS file parsing requires Uint8Array support');
if(typeof NUMBERS != "undefined") {
if(zip.FileIndex) return NUMBERS.parse_numbers(zip);
var _zip = CFB.utils.cfb_new();
zipentries(zip).forEach(function(e) { zip_add_file(_zip, e, getzipbin(zip, e)); });
return NUMBERS.parse_numbers(_zip);
}
throw new Error('Unsupported NUMBERS file');
}
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
@ -31165,6 +31736,29 @@ function readFileSync(filename, opts) {
var o = opts||{}; o.type = 'file';
return readSync(filename, o);
}
function write_obj_str(factory) {
return function write_str(wb, o) {
var idx = 0;
if(o.sheet) {
if(typeof o.sheet == "number") idx = o.sheet;
else idx = wb.SheetNames.indexOf(o.sheet);
if(!wb.SheetNames[idx]) throw new Error("Sheet not found: " + o.sheet + " : " + (typeof o.sheet));
}
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
function write_cfb_ctr(cfb, o) {
switch(o.type) {
case "base64": case "binary": break;
@ -31846,5 +32440,3 @@ else if(typeof define === 'function' && define.amd) define('xlsx', function() {
else make_xlsx_lib(XLSX);
/* NOTE: the following extra line is needed for "Lightning Locker Service" */
if(typeof window !== 'undefined' && !window.XLSX) try { window.XLSX = XLSX; } catch(e) {}
/*exported XLS, ODS */
var XLS = XLSX, ODS = XLSX;

36
dist/xlsx.full.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.full.min.map generated vendored

File diff suppressed because one or more lines are too long

652
dist/xlsx.js generated vendored
View File

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.17.5';
XLSX.version = '0.18.0';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -14,7 +14,7 @@ if(typeof module !== "undefined" && typeof require !== 'undefined') {
}
}
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
var VALID_ANSI = [ 874, 932, 936, 949, 950, 10000 ];
for(var i = 0; i <= 8; ++i) VALID_ANSI.push(1250 + i);
/* ECMA-376 Part I 18.4.1 charset to codepage mapping */
var CS2CP = ({
@ -2942,6 +2942,12 @@ function getzipstr(zip, file, safe) {
try { return getzipstr(zip, file); } catch(e) { return null; }
}
function getzipbin(zip, file, safe) {
if(!safe) return getdatabin(getzipfile(zip, file));
if(!file) return null;
try { return getzipbin(zip, file); } catch(e) { return null; }
}
function zipentries(zip) {
var k = zip.FullPaths || keys(zip.files), o = [];
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i]);
@ -8858,15 +8864,19 @@ function parse_rpr(rpr) {
case '<color':
if(y.rgb) font.color = y.rgb.slice(2,8);
break;
case '<color>': case '<color/>': case '</color>': break;
/* 18.8.18 family ST_FontFamily */
case '<family': font.family = y.val; break;
case '<family>': case '<family/>': case '</family>': break;
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty TODO */
case '<vertAlign': font.valign = y.val; break;
case '<vertAlign>': case '<vertAlign/>': case '</vertAlign>': break;
/* 18.8.35 scheme CT_FontScheme TODO */
case '<scheme': break;
case '<scheme>': case '<scheme/>': case '</scheme>': break;
/* 18.2.10 extLst CT_ExtensionList ? */
case '<extLst': case '<extLst>': case '</extLst>': break;
@ -18509,14 +18519,14 @@ var PSCLSID = {
};
function parse_xls_props(cfb, props, o) {
/* [MS-OSHARED] 2.3.3.2.2 Document Summary Information Property Set */
var DSI = CFB.find(cfb, '!DocumentSummaryInformation');
var DSI = CFB.find(cfb, '/!DocumentSummaryInformation');
if(DSI && DSI.size > 0) try {
var DocSummary = parse_PropertySetStream(DSI, DocSummaryPIDDSI, PSCLSID.DSI);
for(var d in DocSummary) props[d] = DocSummary[d];
} catch(e) {if(o.WTF) throw e;/* empty */}
/* [MS-OSHARED] 2.3.3.2.1 Summary Information Property Set*/
var SI = CFB.find(cfb, '!SummaryInformation');
var SI = CFB.find(cfb, '/!SummaryInformation');
if(SI && SI.size > 0) try {
var Summary = parse_PropertySetStream(SI, SummaryPIDSI, PSCLSID.SI);
for(var s in Summary) if(props[s] == null) props[s] = Summary[s];
@ -20317,7 +20327,7 @@ function write_biff_buf(wb, opts) {
if(!ws || !ws["!ref"]) continue;
var range = decode_range(ws["!ref"]);
if(range.e.c > 255) { // note: 255 is IV
console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
}
@ -21431,31 +21441,583 @@ function write_ods(wb, opts) {
return zip;
}
function write_sheet_index(wb, sheet) {
if(!sheet) return 0;
var idx = wb.SheetNames.indexOf(sheet);
if(idx == -1) throw new Error("Sheet not found: " + sheet);
return idx;
}
var NUMBERS = (function() {
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = function(target) {
return __defProp(target, "__esModule", { value: true });
};
var __export = function(target, all) {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = function(target, module, copyDefault, desc) {
if (module && typeof module === "object" || typeof module === "function")
for (var keys = __getOwnPropNames(module), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
__defProp(target, key, { get: function(k) {
return module[k];
}.bind(null, key), enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}
return target;
};
var __toCommonJS = /* @__PURE__ */ function(cache) {
return function(module, temp) {
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
};
}(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
function write_obj_str(factory) {
return function write_str(wb, o) {
var idx = write_sheet_index(wb, o.sheet);
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
// 83_numbers.ts
var numbers_exports = {};
__export(numbers_exports, {
parse_numbers: function() {
return numbers_default;
}
});
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
// src/util.ts
var u8_to_dataview = function(array) {
return new DataView(array.buffer, array.byteOffset, array.byteLength);
};
var u8str = function(u8) {
return typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
};
var u8concat = function(u8a) {
var len = u8a.reduce(function(acc, x) {
return acc + x.length;
}, 0);
var out = new Uint8Array(len);
var off = 0;
u8a.forEach(function(u8) {
out.set(u8, off);
off += u8.length;
});
return out;
};
var popcnt = function(x) {
x -= x >> 1 & 1431655765;
x = (x & 858993459) + (x >> 2 & 858993459);
return (x + (x >> 4) & 252645135) * 16843009 >>> 24;
};
// src/proto.ts
function parse_varint49(buf, ptr) {
var l = ptr ? ptr[0] : 0;
var usz = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
usz |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 28);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 35);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 42);
++l;
if (buf[l++] < 128)
break varint;
}
if (ptr)
ptr[0] = l;
return usz;
}
function varint_to_i32(buf) {
var l = 0, i32 = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
i32 |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 28;
}
return i32;
}
function parse_shallow(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var off = ptr[0];
var num = parse_varint49(buf, ptr);
var type = num & 7;
num = Math.floor(num / 8);
var len = 0;
var res;
if (num == 0)
break;
switch (type) {
case 0:
{
var l = ptr[0];
while (buf[ptr[0]++] >= 128)
;
res = buf.slice(l, ptr[0]);
}
break;
case 5:
len = 4;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 1:
len = 8;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 2:
len = parse_varint49(buf, ptr);
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 3:
case 4:
default:
throw new Error("PB Type ".concat(type, " for Field ").concat(num, " at offset ").concat(off));
}
var v = { offset: off, data: res, type: type };
if (out[num] == null)
out[num] = [v];
else
out[num].push(v);
}
return out;
}
function mappa(data, cb) {
if (!data)
return [];
return data.map(function(d) {
var _a;
try {
return cb(d.data);
} catch (e) {
var m = (_a = e.message) == null ? void 0 : _a.match(/at offset (\d+)/);
if (m)
e.message = e.message.replace(/at offset (\d+)/, "at offset " + (+m[1] + d.offset));
throw e;
}
});
}
// src/frame.ts
function deframe(buf) {
var out = [];
var l = 0;
while (l < buf.length) {
var t = buf[l++];
var len = buf[l] | buf[l + 1] << 8 | buf[l + 2] << 16;
l += 3;
out.push(parse_snappy_chunk(t, buf.slice(l, l + len)));
l += len;
}
if (l !== buf.length)
throw new Error("data is not a valid framed stream!");
return u8concat(out);
}
function parse_snappy_chunk(type, buf) {
if (type != 0)
throw new Error("Unexpected Snappy chunk type ".concat(type));
var ptr = [0];
var usz = parse_varint49(buf, ptr);
var chunks = [];
while (ptr[0] < buf.length) {
var tag = buf[ptr[0]] & 3;
if (tag == 0) {
var len = buf[ptr[0]++] >> 2;
if (len < 60)
++len;
else {
var c = len - 59;
len = buf[ptr[0]];
if (c > 1)
len |= buf[ptr[0] + 1] << 8;
if (c > 2)
len |= buf[ptr[0] + 2] << 16;
if (c > 3)
len |= buf[ptr[0] + 3] << 24;
len >>>= 0;
len++;
ptr[0] += c;
}
chunks.push(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
continue;
} else {
var offset = 0, length = 0;
if (tag == 1) {
length = (buf[ptr[0]] >> 2 & 7) + 4;
offset = (buf[ptr[0]++] & 224) << 3;
offset |= buf[ptr[0]++];
} else {
length = (buf[ptr[0]++] >> 2) + 1;
if (tag == 2) {
offset = buf[ptr[0]] | buf[ptr[0] + 1] << 8;
ptr[0] += 2;
} else {
offset = (buf[ptr[0]] | buf[ptr[0] + 1] << 8 | buf[ptr[0] + 2] << 16 | buf[ptr[0] + 3] << 24) >>> 0;
ptr[0] += 4;
}
}
chunks = [u8concat(chunks)];
if (offset == 0)
throw new Error("Invalid offset 0");
if (offset > chunks[0].length)
throw new Error("Invalid offset beyond length");
if (length >= offset) {
chunks.push(chunks[0].slice(-offset));
length -= offset;
while (length >= chunks[chunks.length - 1].length) {
chunks.push(chunks[chunks.length - 1]);
length -= chunks[chunks.length - 1].length;
}
}
chunks.push(chunks[0].slice(-offset, -offset + length));
}
}
var o = u8concat(chunks);
if (o.length != usz)
throw new Error("Unexpected length: ".concat(o.length, " != ").concat(usz));
return o;
}
// src/iwa.ts
function parse_iwa(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var len = parse_varint49(buf, ptr);
var ai = parse_shallow(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
var res = {
id: varint_to_i32(ai[1][0].data),
messages: []
};
ai[2].forEach(function(b) {
var mi = parse_shallow(b.data);
var fl = varint_to_i32(mi[3][0].data);
res.messages.push({
meta: mi,
data: buf.slice(ptr[0], ptr[0] + fl)
});
ptr[0] += fl;
});
out.push(res);
}
return out;
}
// src/prebnccell.ts
function parseit(buf, sst, rsst, version) {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 3470) * 4;
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if (flags & 512) {
ridx = dv.getUint32(data_offset, true);
data_offset += 4;
}
data_offset += popcnt(flags & 12288) * 4;
if (flags & 16) {
sidx = dv.getUint32(data_offset, true);
data_offset += 4;
}
if (flags & 32) {
ieee = dv.getFloat64(data_offset, true);
data_offset += 8;
}
if (flags & 64) {
dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1e3);
data_offset += 8;
}
var ret;
switch (ctype) {
case 0:
break;
case 2:
ret = { t: "n", v: ieee };
break;
case 3:
ret = { t: "s", v: sst[sidx] };
break;
case 5:
ret = { t: "d", v: dt };
break;
case 6:
ret = { t: "b", v: ieee > 0 };
break;
case 7:
ret = { t: "n", v: ieee };
break;
case 8:
ret = { t: "e", v: 0 };
break;
case 9:
{
if (ridx > -1)
ret = { t: "s", v: rsst[ridx] };
else if (sidx > -1)
ret = { t: "s", v: sst[sidx] };
else if (!isNaN(ieee))
ret = { t: "n", v: ieee };
else
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
break;
default:
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
return ret;
}
function parse(buf, sst, rsst) {
var version = buf[0];
switch (version) {
case 3:
case 4:
return parseit(buf, sst, rsst, version);
default:
throw new Error("Unsupported pre-BNC version ".concat(version));
}
}
// src/numbers.ts
var encode_col = function(C) {
var s = "";
for (++C; C; C = Math.floor((C - 1) / 26))
s = String.fromCharCode((C - 1) % 26 + 65) + s;
return s;
};
var encode_cell = function(c) {
return "".concat(encode_col(c.c)).concat(c.r + 1);
};
var encode_range = function(r) {
return encode_cell(r.s) + ":" + encode_cell(r.e);
};
var book_new = function() {
return { Sheets: {}, SheetNames: [] };
};
var book_append_sheet = function(wb, ws, name) {
if (!name)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf(name = "Sheet ".concat(i)) == -1)
break;
}
else if (wb.SheetNames.indexOf(name) > -1)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf("".concat(name, "_").concat(i)) == -1) {
name = "".concat(name, "_").concat(i);
break;
}
}
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
};
function parse_numbers(cfb) {
var out = [];
cfb.FileIndex.forEach(function(s) {
if (!s.name.match(/\.iwa$/))
return;
var o;
try {
o = deframe(s.content);
} catch (e) {
return console.log("?? " + s.content.length + " " + (e.message || e));
}
var packets;
try {
packets = parse_iwa(o);
} catch (e) {
return console.log("## " + (e.message || e));
}
packets.forEach(function(packet) {
out[+packet.id] = packet.messages;
});
});
if (!out.length)
throw new Error("File has no messages");
var docroot;
out.forEach(function(iwams) {
iwams.forEach(function(iwam) {
var mtype = varint_to_i32(iwam.meta[1][0].data) >>> 0;
if (mtype == 1) {
if (!docroot)
docroot = iwam;
else
throw new Error("Document has multiple roots");
}
});
});
if (!docroot)
throw new Error("Cannot find Document root");
return parse_docroot(out, docroot);
}
var numbers_default = parse_numbers;
function parse_Reference(buf) {
var pb = parse_shallow(buf);
return parse_varint49(pb[1][0].data);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries || []).forEach(function(entry) {
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data) >>> 0;
switch (type) {
case 1:
data[key] = u8str(le[3][0].data);
break;
case 8:
{
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if (mtype != 2001)
throw new Error("2000 unexpected reference to ".concat(mtype));
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(function(x) {
return u8str(x.data);
}).join("");
}
break;
}
});
return data;
}
function parse_TST_TileRowInfo(u8) {
var pb = parse_shallow(u8);
var R = varint_to_i32(pb[1][0].data) >>> 0;
var storage = pb[3][0].data;
var offsets = u8_to_dataview(pb[4][0].data);
var cells = [];
for (var C = 0; C < offsets.byteLength / 2; ++C) {
var off = offsets.getUint16(C * 2, true);
if (off > storage.length)
continue;
cells[C] = storage.subarray(off, offsets.getUint16(C * 2 + 2, true));
}
return { R: R, cells: cells };
}
function parse_TST_Tile(M, root) {
var pb = parse_shallow(root.data);
var ri = mappa(pb[5], parse_TST_TileRowInfo);
return ri.reduce(function(acc, x) {
if (!acc[x.R])
acc[x.R] = [];
x.cells.forEach(function(cell, C) {
if (acc[x.R][C])
throw new Error("Duplicate cell r=".concat(x.R, " c=").concat(C));
acc[x.R][C] = cell;
});
return acc;
}, []);
}
function parse_TST_TableModelArchive(M, root, ws) {
var _a;
var pb = parse_shallow(root.data);
var range = { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } };
range.e.r = (varint_to_i32(pb[6][0].data) >>> 0) - 1;
if (range.e.r < 0)
throw new Error("Invalid row varint ".concat(pb[6][0].data));
range.e.c = (varint_to_i32(pb[7][0].data) >>> 0) - 1;
if (range.e.c < 0)
throw new Error("Invalid col varint ".concat(pb[7][0].data));
ws["!ref"] = encode_range(range);
{
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst = ((_a = store[17]) == null ? void 0 : _a[0]) ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
var tile = parse_shallow(store[3][0].data);
var tiles = [];
tile[1].forEach(function(t) {
var tl = parse_shallow(t.data);
var ref = M[parse_Reference(tl[2][0].data)][0];
var mtype = varint_to_i32(ref.meta[1][0].data);
if (mtype != 6002)
throw new Error("6001 unexpected reference to ".concat(mtype));
tiles.push({ id: varint_to_i32(tl[1][0].data), ref: parse_TST_Tile(M, ref) });
});
tiles.forEach(function(tile2) {
tile2.ref.forEach(function(row, R) {
row.forEach(function(buf, C) {
var addr = encode_cell({ r: R, c: C });
var res = parse(buf, sst, rsst);
if (res)
ws[addr] = res;
});
});
});
}
}
}
function parse_TST_TableInfoArchive(M, root) {
var pb = parse_shallow(root.data);
var out = { "!ref": "A1" };
var tableref = M[parse_Reference(pb[2][0].data)];
var mtype = varint_to_i32(tableref[0].meta[1][0].data);
if (mtype != 6001)
throw new Error("6000 unexpected reference to ".concat(mtype));
parse_TST_TableModelArchive(M, tableref[0], out);
return out;
}
function parse_sheetroot(M, root) {
var _a;
var pb = parse_shallow(root.data);
var out = {
name: ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : "",
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
shapeoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 6e3)
out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
}
function parse_docroot(M, root) {
var out = book_new();
var pb = parse_shallow(root.data);
var sheetoffs = mappa(pb[1], parse_Reference);
sheetoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 2) {
var root2 = parse_sheetroot(M, m);
root2.sheets.forEach(function(sheet) {
book_append_sheet(out, sheet, root2.name);
});
}
});
});
if (out.SheetNames.length == 0)
throw new Error("Empty NUMBERS file");
return out;
}
return __toCommonJS(numbers_exports);
})();
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
function fix_opts_func(defaults) {
return function fix_opts(opts) {
for(var i = 0; i != defaults.length; ++i) {
@ -21562,7 +22124,16 @@ function parse_zip(zip, opts) {
/* UOC */
if(safegetzipfile(zip, 'objectdata.xml')) return parse_ods(zip, opts);
/* Numbers */
if(safegetzipfile(zip, 'Index/Document.iwa')) throw new Error('Unsupported NUMBERS file');
if(safegetzipfile(zip, 'Index/Document.iwa')) {
if(typeof Uint8Array == "undefined") throw new Error('NUMBERS file parsing requires Uint8Array support');
if(typeof NUMBERS != "undefined") {
if(zip.FileIndex) return NUMBERS.parse_numbers(zip);
var _zip = CFB.utils.cfb_new();
zipentries(zip).forEach(function(e) { zip_add_file(_zip, e, getzipbin(zip, e)); });
return NUMBERS.parse_numbers(_zip);
}
throw new Error('Unsupported NUMBERS file');
}
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
@ -22008,6 +22579,29 @@ function readFileSync(filename, opts) {
var o = opts||{}; o.type = 'file';
return readSync(filename, o);
}
function write_obj_str(factory) {
return function write_str(wb, o) {
var idx = 0;
if(o.sheet) {
if(typeof o.sheet == "number") idx = o.sheet;
else idx = wb.SheetNames.indexOf(o.sheet);
if(!wb.SheetNames[idx]) throw new Error("Sheet not found: " + o.sheet + " : " + (typeof o.sheet));
}
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
function write_cfb_ctr(cfb, o) {
switch(o.type) {
case "base64": case "binary": break;
@ -22689,5 +23283,3 @@ else if(typeof define === 'function' && define.amd) define('xlsx', function() {
else make_xlsx_lib(XLSX);
/* NOTE: the following extra line is needed for "Lightning Locker Service" */
if(typeof window !== 'undefined' && !window.XLSX) try { window.XLSX = XLSX; } catch(e) {}
/*exported XLS, ODS */
var XLS = XLSX, ODS = XLSX;

28
dist/xlsx.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.min.map generated vendored

File diff suppressed because one or more lines are too long

16
dist/xlsx.mini.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.mini.min.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -217,7 +217,7 @@ This format has been used up through the current release (Numbers 11.2).
The parser focuses on extracting raw data from tables. Numbers technically
supports multiple tables in a logical worksheet, including custom titles. This
parser will only extract the raw data from the first table from each worksheet.
parser will generate one worksheet per Numbers table.
</details>

View File

@ -45,7 +45,7 @@ bits/74_xmlbin.js
bits/79_html.js
bits/80_parseods.js
bits/81_writeods.js
bits/82_sheeter.js
bits/83_numbers.js
bits/84_defaults.js
bits/85_parsezip.js
bits/86_writezip.js

View File

@ -118,6 +118,7 @@ Community Translations of this README:
+ [Lotus 1-2-3 (WKS/WK1/WK2/WK3/WK4/123)](#lotus-1-2-3-wkswk1wk2wk3wk4123)
+ [Quattro Pro (WQ1/WQ2/WB1/WB2/WB3/QPW)](#quattro-pro-wq1wq2wb1wb2wb3qpw)
+ [Works for DOS / Windows Spreadsheet (WKS/XLR)](#works-for-dos--windows-spreadsheet-wksxlr)
+ [Numbers 3.0+ / iWork 2013+ Spreadsheet (NUMBERS)](#numbers-30--iwork-2013-spreadsheet-numbers)
+ [OpenDocument Spreadsheet (ODS/FODS)](#opendocument-spreadsheet-odsfods)
+ [Uniform Office Spreadsheet (UOS1/2)](#uniform-office-spreadsheet-uos12)
* [Other Single-Worksheet Formats](#other-single-worksheet-formats)
@ -1692,7 +1693,7 @@ file but Excel will know how to handle it. This library applies similar logic:
| `0xD0` | CFB Container | BIFF 5/8 or protected XLSX/XLSB or WQ3/QPW or XLR |
| `0x09` | BIFF Stream | BIFF 2/3/4/5 |
| `0x3C` | XML/HTML | SpreadsheetML / Flat ODS / UOS1 / HTML / plain text |
| `0x50` | ZIP Archive | XLSB or XLSX/M or ODS or UOS2 or plain text |
| `0x50` | ZIP Archive | XLSB or XLSX/M or ODS or UOS2 or NUMBERS or text |
| `0x49` | Plain Text | SYLK or plain text |
| `0x54` | Plain Text | DIF or plain text |
| `0xEF` | UTF8 Encoded | SpreadsheetML / Flat ODS / UOS1 / HTML / plain text |
@ -2302,6 +2303,7 @@ Despite the library name `xlsx`, it supports numerous spreadsheet file formats:
| Lotus Formatted Text (PRN) | ✔ | ✔ |
| UTF-16 Unicode Text (TXT) | ✔ | ✔ |
| **Other Workbook/Worksheet Formats** |:-----:|:-----:|
| Numbers 3.0+ / iWork 2013+ Spreadsheet (NUMBERS) | ✔ | |
| OpenDocument Spreadsheet (ODS) | ✔ | ✔ |
| Flat XML ODF Spreadsheet (FODS) | ✔ | ✔ |
| Uniform Office Format Spreadsheet (标文通 UOS1/UOS2) | ✔ | |
@ -2457,6 +2459,18 @@ includes two empty worksheets but the main worksheet has an identical encoding.
XLR also includes a `WksSSWorkBook` stream similar to Lotus FM3/FMT files.
#### Numbers 3.0+ / iWork 2013+ Spreadsheet (NUMBERS)
iWork 2013 (Numbers 3.0 / Pages 5.0 / Keynote 6.0) switched from a proprietary
XML-based format to the current file format based on the iWork Archive (IWA).
This format has been used up through the current release (Numbers 11.2).
The parser focuses on extracting raw data from tables. Numbers technically
supports multiple tables in a logical worksheet, including custom titles. This
parser will generate one worksheet per Numbers table.
#### OpenDocument Spreadsheet (ODS/FODS)

View File

@ -69,6 +69,7 @@
+ [Lotus 1-2-3 (WKS/WK1/WK2/WK3/WK4/123)](README.md#lotus-1-2-3-wkswk1wk2wk3wk4123)
+ [Quattro Pro (WQ1/WQ2/WB1/WB2/WB3/QPW)](README.md#quattro-pro-wq1wq2wb1wb2wb3qpw)
+ [Works for DOS / Windows Spreadsheet (WKS/XLR)](README.md#works-for-dos--windows-spreadsheet-wksxlr)
+ [Numbers 3.0+ / iWork 2013+ Spreadsheet (NUMBERS)](README.md#numbers-30--iwork-2013-spreadsheet-numbers)
+ [OpenDocument Spreadsheet (ODS/FODS)](README.md#opendocument-spreadsheet-odsfods)
+ [Uniform Office Spreadsheet (UOS1/2)](README.md#uniform-office-spreadsheet-uos12)
* [Other Single-Worksheet Formats](README.md#other-single-worksheet-formats)

View File

@ -68,7 +68,7 @@ bits/78_writebiff.js
bits/79_html.js
bits/80_parseods.js
bits/81_writeods.js
bits/82_sheeter.js
bits/83_numbers.js
bits/84_defaults.js
bits/85_parsezip.js
bits/86_writezip.js

View File

@ -68,7 +68,7 @@ bits/78_writebiff.js
bits/79_html.js
bits/80_parseods.js
bits/81_writeods.js
bits/82_sheeter.js
bits/83_numbers.js
bits/84_defaults.js
bits/85_parsezip.js
bits/86_writezip.js

View File

@ -40,7 +40,7 @@ var NUMBERS = (function() {
return new DataView(array.buffer, array.byteOffset, array.byteLength);
};
var u8str = function(u8) {
return new TextDecoder().decode(u8);
return typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
};
var u8concat = function(u8a) {
var len = u8a.reduce(function(acc, x) {
@ -280,12 +280,17 @@ var NUMBERS = (function() {
}
// src/prebnccell.ts
function parseit(buf, version) {
function parseit(buf, sst, rsst, version) {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 16270) * 4;
var sidx = -1, ieee = NaN, dt = NaN;
var data_offset = 12 + popcnt(flags & 3470) * 4;
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if (flags & 512) {
ridx = dv.getUint32(data_offset, true);
data_offset += 4;
}
data_offset += popcnt(flags & 12288) * 4;
if (flags & 16) {
sidx = dv.getUint32(data_offset, true);
data_offset += 4;
@ -295,7 +300,7 @@ var NUMBERS = (function() {
data_offset += 8;
}
if (flags & 64) {
dt = dv.getFloat64(data_offset, true);
dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1e3);
data_offset += 8;
}
var ret;
@ -306,12 +311,10 @@ var NUMBERS = (function() {
ret = { t: "n", v: ieee };
break;
case 3:
ret = { t: "s", v: sidx };
ret = { t: "s", v: sst[sidx] };
break;
case 5:
var dd = new Date(2001, 0, 1);
dd.setTime(dd.getTime() + dt * 1e3);
ret = { t: "d", v: dd };
ret = { t: "d", v: dt };
break;
case 6:
ret = { t: "b", v: ieee > 0 };
@ -319,17 +322,32 @@ var NUMBERS = (function() {
case 7:
ret = { t: "n", v: ieee };
break;
case 8:
ret = { t: "e", v: 0 };
break;
case 9:
{
if (ridx > -1)
ret = { t: "s", v: rsst[ridx] };
else if (sidx > -1)
ret = { t: "s", v: sst[sidx] };
else if (!isNaN(ieee))
ret = { t: "n", v: ieee };
else
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
break;
default:
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
return ret;
}
function parse(buf) {
function parse(buf, sst, rsst) {
var version = buf[0];
switch (version) {
case 3:
case 4:
return parseit(buf, version);
return parseit(buf, sst, rsst, version);
default:
throw new Error("Unsupported pre-BNC version ".concat(version));
}
@ -352,11 +370,18 @@ var NUMBERS = (function() {
return { Sheets: {}, SheetNames: [] };
};
var book_append_sheet = function(wb, ws, name) {
if (!name) {
for (var i = 1; i < 9999; ++i)
if (!name)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf(name = "Sheet ".concat(i)) == -1)
break;
}
}
else if (wb.SheetNames.indexOf(name) > -1)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf("".concat(name, "_").concat(i)) == -1) {
name = "".concat(name, "_").concat(i);
break;
}
}
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
};
@ -406,12 +431,31 @@ var NUMBERS = (function() {
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries || []).forEach(function(entry) {
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data) >>> 0;
data[key] = u8str(le[3][0].data);
switch (type) {
case 1:
data[key] = u8str(le[3][0].data);
break;
case 8:
{
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if (mtype != 2001)
throw new Error("2000 unexpected reference to ".concat(mtype));
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(function(x) {
return u8str(x.data);
}).join("");
}
break;
}
});
return data;
}
@ -444,6 +488,7 @@ var NUMBERS = (function() {
}, []);
}
function parse_TST_TableModelArchive(M, root, ws) {
var _a;
var pb = parse_shallow(root.data);
var range = { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } };
range.e.r = (varint_to_i32(pb[6][0].data) >>> 0) - 1;
@ -456,6 +501,7 @@ var NUMBERS = (function() {
{
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst = ((_a = store[17]) == null ? void 0 : _a[0]) ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
var tile = parse_shallow(store[3][0].data);
var tiles = [];
@ -471,12 +517,9 @@ var NUMBERS = (function() {
tile2.ref.forEach(function(row, R) {
row.forEach(function(buf, C) {
var addr = encode_cell({ r: R, c: C });
var res = parse(buf);
if (res) {
var res = parse(buf, sst, rsst);
if (res)
ws[addr] = res;
if (res.t == "s" && typeof res.v == "number")
res.v = sst[res.v];
}
});
});
});
@ -496,18 +539,16 @@ var NUMBERS = (function() {
function parse_sheetroot(M, root) {
var _a;
var pb = parse_shallow(root.data);
var out = [{ "!ref": "A1" }, ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : ""];
var out = {
name: ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : "",
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
var seen = false;
shapeoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 6e3) {
if (seen)
return;
out[0] = parse_TST_TableInfoArchive(M, m);
seen = true;
}
if (mtype == 6e3)
out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
@ -521,7 +562,9 @@ var NUMBERS = (function() {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 2) {
var root2 = parse_sheetroot(M, m);
book_append_sheet(out, root2[0], root2[1]);
root2.sheets.forEach(function(sheet) {
book_append_sheet(out, sheet, root2.name);
});
}
});
});

View File

@ -1,6 +1,6 @@
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
import { CFB$Container } from 'cfb';
import { WorkBook, WorkSheet, CellAddress, Range, CellObject } from '../../';
import { WorkBook, WorkSheet, CellAddress, Range } from '../../';
import { u8str, u8_to_dataview } from './util';
import { parse_shallow, varint_to_i32, parse_varint49, mappa } from './proto';
import { deframe } from './frame';
@ -17,7 +17,11 @@ var encode_cell = (c: CellAddress): string => `${encode_col(c.c)}${c.r+1}`;
var encode_range = (r: Range): string => encode_cell(r.s) + ":" + encode_cell(r.e);
var book_new = (): WorkBook => ({Sheets:{}, SheetNames:[]});
var book_append_sheet = (wb: WorkBook, ws: WorkSheet, name?: string): void => {
if(!name) for(var i = 1; i < 9999; ++i) if(wb.SheetNames.indexOf(name = `Sheet ${i}`) == -1) break;
if(!name) for(var i = 1; i < 9999; ++i) {
if(wb.SheetNames.indexOf(name = `Sheet ${i}`) == -1) break;
} else if(wb.SheetNames.indexOf(name) > -1) for(var i = 1; i < 9999; ++i) {
if(wb.SheetNames.indexOf(`${name}_${i}`) == -1) { name = `${name}_${i}`; break; }
}
wb.SheetNames.push(name); wb.Sheets[name] = ws;
};
@ -58,12 +62,31 @@ function parse_Reference(buf: Uint8Array): number {
// .TST.TableDataList
function parse_TST_TableDataList(M: IWAMessage[][], root: IWAMessage): string[] {
var pb = parse_shallow(root.data);
// .TST.TableDataList.ListType
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries||[]).forEach(entry => {
// .TST.TableDataList.ListEntry
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data)>>>0;
data[key] = u8str(le[3][0].data);
switch(type) {
case 1: data[key] = u8str(le[3][0].data); break;
case 8: {
// .TSP.RichTextPayloadArchive
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
// .TSWP.StorageArchive
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if(mtype != 2001) throw new Error(`2000 unexpected reference to ${mtype}`);
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(x => u8str(x.data)).join("");
} break;
}
});
return data;
}
@ -116,6 +139,7 @@ function parse_TST_TableModelArchive(M: IWAMessage[][], root: IWAMessage, ws: Wo
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst: string[] = store[17]?.[0] ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
// .TST.TileStorage
var tile = parse_shallow(store[3][0].data);
@ -131,11 +155,8 @@ function parse_TST_TableModelArchive(M: IWAMessage[][], root: IWAMessage, ws: Wo
tile.ref.forEach((row, R) => {
row.forEach((buf, C) => {
var addr = encode_cell({r:R,c:C});
var res = parse_bnc(buf);
if(res) {
ws[addr] = res as CellObject;
if(res.t == "s" && typeof res.v == "number") res.v = sst[res.v];
}
var res = parse_bnc(buf, sst, rsst);
if(res) ws[addr] = res;
});
});
});
@ -155,19 +176,21 @@ function parse_TST_TableInfoArchive(M: IWAMessage[][], root: IWAMessage): WorkSh
}
// .TN.SheetArchive
function parse_sheetroot(M: IWAMessage[][], root: IWAMessage): [WorkSheet, string] {
interface NSheet {
name: string;
sheets: WorkSheet[];
}
function parse_sheetroot(M: IWAMessage[][], root: IWAMessage): NSheet {
var pb = parse_shallow(root.data);
var out: [WorkSheet, string] = [ { "!ref":"A1" }, (pb[1]?.[0] ? u8str(pb[1][0].data) : "") ];
var out: NSheet = {
name: (pb[1]?.[0] ? u8str(pb[1][0].data) : ""),
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
var seen = false;
shapeoffs.forEach((off) => {
M[off].forEach((m: IWAMessage) => {
var mtype = varint_to_i32(m.meta[1][0].data);
if(mtype == 6000) {
if(seen) return; // TODO: multiple Tables in a sheet
out[0] = parse_TST_TableInfoArchive(M, m);
seen = true;
}
if(mtype == 6000) out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
@ -183,7 +206,7 @@ function parse_docroot(M: IWAMessage[][], root: IWAMessage): WorkBook {
var mtype = varint_to_i32(m.meta[1][0].data);
if(mtype == 2) {
var root = parse_sheetroot(M, m);
book_append_sheet(out, root[0], root[1]);
root.sheets.forEach(sheet => { book_append_sheet(out, sheet, root.name); });
}
});
});

View File

@ -2,27 +2,36 @@
import { CellObject } from '../../';
import { u8_to_dataview, popcnt } from './util';
function parseit(buf: Uint8Array, version: number): CellObject {
function parseit(buf: Uint8Array, sst: string[], rsst: string[], version: number): CellObject {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
/* TODO: find the correct field position of number formats, formulae, etc */
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 0x3F8E) * 4;
var data_offset = 12 + popcnt(flags & 0x0D8E) * 4;
var sidx = -1, ieee = NaN, dt = NaN;
if(flags & 0x10) { sidx = dv.getUint32(data_offset, true); data_offset += 4; }
if(flags & 0x20) { ieee = dv.getFloat64(data_offset, true); data_offset += 8; }
if(flags & 0x40) { dt = dv.getFloat64(data_offset, true); data_offset += 8; }
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if(flags & 0x0200) { ridx = dv.getUint32(data_offset, true); data_offset += 4; }
data_offset += popcnt(flags & 0x3000) * 4;
if(flags & 0x0010) { sidx = dv.getUint32(data_offset, true); data_offset += 4; }
if(flags & 0x0020) { ieee = dv.getFloat64(data_offset, true); data_offset += 8; }
if(flags & 0x0040) { dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1000); data_offset += 8; }
var ret;
var ret: CellObject;
switch(ctype) {
case 0: break; // return { t: "z" }; // blank?
case 2: ret = { t: "n", v: ieee }; break;
case 3: ret = { t: "s", v: sidx }; break;
case 5: var dd = new Date(2001, 0, 1); dd.setTime(dd.getTime() + dt * 1000); ret = { t: "d", v: dd }; break; // date-time TODO: relative or absolute?
case 6: ret = { t: "b", v: ieee > 0 }; break;
case 2: ret = { t: "n", v: ieee }; break; // number
case 3: ret = { t: "s", v: sst[sidx] }; break; // string
case 5: ret = { t: "d", v: dt }; break; // date-time
case 6: ret = { t: "b", v: ieee > 0 }; break; // boolean
case 7: ret = { t: "n", v: ieee }; break; // duration in seconds TODO: emit [hh]:[mm] style format with adjusted value
case 8: ret = { t: "e", v: 0}; break; // "formula error" TODO: enumerate and map errors to csf equivalents
case 9: { // "automatic"?
if(ridx > -1) ret = { t: "s", v: rsst[ridx] };
else if(sidx > -1) ret = { t: "s", v: sst[sidx] };
else if(!isNaN(ieee)) ret = { t: "n", v: ieee };
else throw new Error(`Unsupported cell type ${buf.slice(0,4)}`);
} break;
default: throw new Error(`Unsupported cell type ${buf.slice(0,4)}`);
}
/* TODO: Some fields appear after the cell data */
@ -30,10 +39,10 @@ function parseit(buf: Uint8Array, version: number): CellObject {
return ret;
}
function parse(buf: Uint8Array): CellObject {
function parse(buf: Uint8Array, sst: string[], rsst: string[]): CellObject {
var version = buf[0]; // numbers 3.5 uses "3", 6.x - 11.x use "4"
switch(version) {
case 3: case 4: return parseit(buf, version);
case 3: case 4: return parseit(buf, sst, rsst, version);
default: throw new Error(`Unsupported pre-BNC version ${version}`);
}
}

View File

@ -2,7 +2,7 @@
var u8_to_dataview = (array: Uint8Array): DataView => new DataView(array.buffer, array.byteOffset, array.byteLength);
export { u8_to_dataview };
var u8str = (u8: Uint8Array): string => /* Buffer.isBuffer(u8) ? u8.toString() :*/ new TextDecoder().decode(u8);
var u8str = (u8: Uint8Array): string => /* Buffer.isBuffer(u8) ? u8.toString() :*/ typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
export { u8str };
var u8concat = (u8a: Uint8Array[]): Uint8Array => {

View File

@ -1,6 +1,6 @@
{
"name": "xlsx",
"version": "0.17.5",
"version": "0.18.0",
"author": "sheetjs",
"description": "SheetJS Spreadsheet data parser and writer",
"keywords": [
@ -32,10 +32,10 @@
"fs": false
},
"dependencies": {
"adler-32": "~1.2.0",
"adler-32": "~1.3.0",
"cfb": "^1.1.4",
"codepage": "~1.15.0",
"crc-32": "~1.2.0",
"crc-32": "~1.2.1",
"ssf": "~0.11.2",
"wmf": "~1.0.1",
"word": "~0.3.0"

14
test.js
View File

@ -1631,7 +1631,7 @@ describe('roundtrip features', function() {
});
describe('should preserve column properties', function() { [
'xlml', /*'biff2', 'biff8', */ 'xlsx', 'xlsb', 'slk'
/*'xlml',*/ /*'biff2', 'biff8', */ 'xlsx', 'xlsb', 'slk'
].forEach(function(w) { it(w, function() {
var ws1 = X.utils.aoa_to_sheet([["hpx12", "hpt24", "hpx48", "hidden"]]);
ws1['!cols'] = [{wch:9},{wpx:100},{width:80},{hidden:true}];
@ -2108,6 +2108,18 @@ describe('sylk', function() {
});
});
(typeof Uint8Array !== "undefined" ? describe : describe.skip)('numbers', function() {
it('should parse files from Numbers 6.x', function() {
var wb = X.read(fs.readFileSync(dir + 'numbers/types_61.numbers'), {type:TYPE, WTF:1});
var ws = wb.Sheets["Sheet 1"];
assert.equal(get_cell(ws, "A1").v, "Sheet");
assert.equal(get_cell(ws, "B1").v, "JS");
assert.equal(get_cell(ws, "B2").v, 123);
assert.equal(get_cell(ws, "B11").v, true);
assert.equal(get_cell(ws, "B13").v, 50);
});
});
if(fs.existsSync(dir + 'dbf/d11.dbf')) describe('dbf', function() {
var wbs/*:Array<any>*/ = ([
['d11', dir + 'dbf/d11.dbf'],

@ -1 +1 @@
Subproject commit dbaaa95888f0926c2f9395a72f435fdf7fef351a
Subproject commit c8fe8a48a8cfc3c480b02f0a6df75cc2aff1932d

View File

@ -1443,3 +1443,4 @@ artifacts/wps/write.xlsx
artifacts/wps/write.xml
dbf/d11.dbf
dbf/vfp3.dbf
numbers/types_61.numbers

14
tests/core.js generated
View File

@ -1631,7 +1631,7 @@ describe('roundtrip features', function() {
});
describe('should preserve column properties', function() { [
'xlml', /*'biff2', 'biff8', */ 'xlsx', 'xlsb', 'slk'
/*'xlml',*/ /*'biff2', 'biff8', */ 'xlsx', 'xlsb', 'slk'
].forEach(function(w) { it(w, function() {
var ws1 = X.utils.aoa_to_sheet([["hpx12", "hpt24", "hpx48", "hidden"]]);
ws1['!cols'] = [{wch:9},{wpx:100},{width:80},{hidden:true}];
@ -2108,6 +2108,18 @@ describe('sylk', function() {
});
});
(typeof Uint8Array !== "undefined" ? describe : describe.skip)('numbers', function() {
it('should parse files from Numbers 6.x', function() {
var wb = X.read(fs.readFileSync(dir + 'numbers/types_61.numbers'), {type:TYPE, WTF:1});
var ws = wb.Sheets["Sheet 1"];
assert.equal(get_cell(ws, "A1").v, "Sheet");
assert.equal(get_cell(ws, "B1").v, "JS");
assert.equal(get_cell(ws, "B2").v, 123);
assert.equal(get_cell(ws, "B11").v, true);
assert.equal(get_cell(ws, "B13").v, 50);
});
});
if(fs.existsSync(dir + 'dbf/d11.dbf')) describe('dbf', function() {
var wbs/*:Array<any>*/ = ([
['d11', dir + 'dbf/d11.dbf'],

41
tests/fixtures.js generated

File diff suppressed because one or more lines are too long

View File

@ -169,3 +169,4 @@
./test_files/dbf/vfp3.dbf
./test_files/wtf_path.xlsx
./test_files/wtf_path.xlsb
./test_files/numbers/types_61.numbers

642
xlsx.esm.mjs generated
View File

@ -3,7 +3,7 @@
/*exported XLSX */
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
XLSX.version = '0.17.5';
XLSX.version = '0.18.0';
var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
@ -8879,15 +8879,19 @@ function parse_rpr(rpr) {
case '<color':
if(y.rgb) font.color = y.rgb.slice(2,8);
break;
case '<color>': case '<color/>': case '</color>': break;
/* 18.8.18 family ST_FontFamily */
case '<family': font.family = y.val; break;
case '<family>': case '<family/>': case '</family>': break;
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty TODO */
case '<vertAlign': font.valign = y.val; break;
case '<vertAlign>': case '<vertAlign/>': case '</vertAlign>': break;
/* 18.8.35 scheme CT_FontScheme TODO */
case '<scheme': break;
case '<scheme>': case '<scheme/>': case '</scheme>': break;
/* 18.2.10 extLst CT_ExtensionList ? */
case '<extLst': case '<extLst>': case '</extLst>': break;
@ -18549,14 +18553,14 @@ var PSCLSID = {
};
function parse_xls_props(cfb/*:CFBContainer*/, props, o) {
/* [MS-OSHARED] 2.3.3.2.2 Document Summary Information Property Set */
var DSI = CFB.find(cfb, '!DocumentSummaryInformation');
var DSI = CFB.find(cfb, '/!DocumentSummaryInformation');
if(DSI && DSI.size > 0) try {
var DocSummary = parse_PropertySetStream(DSI, DocSummaryPIDDSI, PSCLSID.DSI);
for(var d in DocSummary) props[d] = DocSummary[d];
} catch(e) {if(o.WTF) throw e;/* empty */}
/* [MS-OSHARED] 2.3.3.2.1 Summary Information Property Set*/
var SI = CFB.find(cfb, '!SummaryInformation');
var SI = CFB.find(cfb, '/!SummaryInformation');
if(SI && SI.size > 0) try {
var Summary = parse_PropertySetStream(SI, SummaryPIDSI, PSCLSID.SI);
for(var s in Summary) if(props[s] == null) props[s] = Summary[s];
@ -20358,7 +20362,7 @@ function write_biff_buf(wb/*:Workbook*/, opts/*:WriteOpts*/) {
if(!ws || !ws["!ref"]) continue;
var range = decode_range(ws["!ref"]);
if(range.e.c > 255) { // note: 255 is IV
console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
}
@ -21472,31 +21476,583 @@ function write_ods(wb/*:any*/, opts/*:any*/) {
return zip;
}
function write_sheet_index(wb/*:Workbook*/, sheet/*:?string*/)/*:number*/ {
if(!sheet) return 0;
var idx = wb.SheetNames.indexOf(sheet);
if(idx == -1) throw new Error("Sheet not found: " + sheet);
return idx;
}
var NUMBERS = (function() {
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = function(target) {
return __defProp(target, "__esModule", { value: true });
};
var __export = function(target, all) {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = function(target, module, copyDefault, desc) {
if (module && typeof module === "object" || typeof module === "function")
for (var keys = __getOwnPropNames(module), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
__defProp(target, key, { get: function(k) {
return module[k];
}.bind(null, key), enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}
return target;
};
var __toCommonJS = /* @__PURE__ */ function(cache) {
return function(module, temp) {
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
};
}(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
function write_obj_str(factory/*:WriteObjStrFactory*/) {
return function write_str(wb/*:Workbook*/, o/*:WriteOpts*/)/*:string*/ {
var idx = write_sheet_index(wb, o.sheet);
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
// 83_numbers.ts
var numbers_exports = {};
__export(numbers_exports, {
parse_numbers: function() {
return numbers_default;
}
});
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
// src/util.ts
var u8_to_dataview = function(array) {
return new DataView(array.buffer, array.byteOffset, array.byteLength);
};
var u8str = function(u8) {
return typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
};
var u8concat = function(u8a) {
var len = u8a.reduce(function(acc, x) {
return acc + x.length;
}, 0);
var out = new Uint8Array(len);
var off = 0;
u8a.forEach(function(u8) {
out.set(u8, off);
off += u8.length;
});
return out;
};
var popcnt = function(x) {
x -= x >> 1 & 1431655765;
x = (x & 858993459) + (x >> 2 & 858993459);
return (x + (x >> 4) & 252645135) * 16843009 >>> 24;
};
// src/proto.ts
function parse_varint49(buf, ptr) {
var l = ptr ? ptr[0] : 0;
var usz = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
usz |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 28);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 35);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 42);
++l;
if (buf[l++] < 128)
break varint;
}
if (ptr)
ptr[0] = l;
return usz;
}
function varint_to_i32(buf) {
var l = 0, i32 = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
i32 |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 28;
}
return i32;
}
function parse_shallow(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var off = ptr[0];
var num = parse_varint49(buf, ptr);
var type = num & 7;
num = Math.floor(num / 8);
var len = 0;
var res;
if (num == 0)
break;
switch (type) {
case 0:
{
var l = ptr[0];
while (buf[ptr[0]++] >= 128)
;
res = buf.slice(l, ptr[0]);
}
break;
case 5:
len = 4;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 1:
len = 8;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 2:
len = parse_varint49(buf, ptr);
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 3:
case 4:
default:
throw new Error("PB Type ".concat(type, " for Field ").concat(num, " at offset ").concat(off));
}
var v = { offset: off, data: res, type: type };
if (out[num] == null)
out[num] = [v];
else
out[num].push(v);
}
return out;
}
function mappa(data, cb) {
if (!data)
return [];
return data.map(function(d) {
var _a;
try {
return cb(d.data);
} catch (e) {
var m = (_a = e.message) == null ? void 0 : _a.match(/at offset (\d+)/);
if (m)
e.message = e.message.replace(/at offset (\d+)/, "at offset " + (+m[1] + d.offset));
throw e;
}
});
}
// src/frame.ts
function deframe(buf) {
var out = [];
var l = 0;
while (l < buf.length) {
var t = buf[l++];
var len = buf[l] | buf[l + 1] << 8 | buf[l + 2] << 16;
l += 3;
out.push(parse_snappy_chunk(t, buf.slice(l, l + len)));
l += len;
}
if (l !== buf.length)
throw new Error("data is not a valid framed stream!");
return u8concat(out);
}
function parse_snappy_chunk(type, buf) {
if (type != 0)
throw new Error("Unexpected Snappy chunk type ".concat(type));
var ptr = [0];
var usz = parse_varint49(buf, ptr);
var chunks = [];
while (ptr[0] < buf.length) {
var tag = buf[ptr[0]] & 3;
if (tag == 0) {
var len = buf[ptr[0]++] >> 2;
if (len < 60)
++len;
else {
var c = len - 59;
len = buf[ptr[0]];
if (c > 1)
len |= buf[ptr[0] + 1] << 8;
if (c > 2)
len |= buf[ptr[0] + 2] << 16;
if (c > 3)
len |= buf[ptr[0] + 3] << 24;
len >>>= 0;
len++;
ptr[0] += c;
}
chunks.push(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
continue;
} else {
var offset = 0, length = 0;
if (tag == 1) {
length = (buf[ptr[0]] >> 2 & 7) + 4;
offset = (buf[ptr[0]++] & 224) << 3;
offset |= buf[ptr[0]++];
} else {
length = (buf[ptr[0]++] >> 2) + 1;
if (tag == 2) {
offset = buf[ptr[0]] | buf[ptr[0] + 1] << 8;
ptr[0] += 2;
} else {
offset = (buf[ptr[0]] | buf[ptr[0] + 1] << 8 | buf[ptr[0] + 2] << 16 | buf[ptr[0] + 3] << 24) >>> 0;
ptr[0] += 4;
}
}
chunks = [u8concat(chunks)];
if (offset == 0)
throw new Error("Invalid offset 0");
if (offset > chunks[0].length)
throw new Error("Invalid offset beyond length");
if (length >= offset) {
chunks.push(chunks[0].slice(-offset));
length -= offset;
while (length >= chunks[chunks.length - 1].length) {
chunks.push(chunks[chunks.length - 1]);
length -= chunks[chunks.length - 1].length;
}
}
chunks.push(chunks[0].slice(-offset, -offset + length));
}
}
var o = u8concat(chunks);
if (o.length != usz)
throw new Error("Unexpected length: ".concat(o.length, " != ").concat(usz));
return o;
}
// src/iwa.ts
function parse_iwa(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var len = parse_varint49(buf, ptr);
var ai = parse_shallow(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
var res = {
id: varint_to_i32(ai[1][0].data),
messages: []
};
ai[2].forEach(function(b) {
var mi = parse_shallow(b.data);
var fl = varint_to_i32(mi[3][0].data);
res.messages.push({
meta: mi,
data: buf.slice(ptr[0], ptr[0] + fl)
});
ptr[0] += fl;
});
out.push(res);
}
return out;
}
// src/prebnccell.ts
function parseit(buf, sst, rsst, version) {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 3470) * 4;
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if (flags & 512) {
ridx = dv.getUint32(data_offset, true);
data_offset += 4;
}
data_offset += popcnt(flags & 12288) * 4;
if (flags & 16) {
sidx = dv.getUint32(data_offset, true);
data_offset += 4;
}
if (flags & 32) {
ieee = dv.getFloat64(data_offset, true);
data_offset += 8;
}
if (flags & 64) {
dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1e3);
data_offset += 8;
}
var ret;
switch (ctype) {
case 0:
break;
case 2:
ret = { t: "n", v: ieee };
break;
case 3:
ret = { t: "s", v: sst[sidx] };
break;
case 5:
ret = { t: "d", v: dt };
break;
case 6:
ret = { t: "b", v: ieee > 0 };
break;
case 7:
ret = { t: "n", v: ieee };
break;
case 8:
ret = { t: "e", v: 0 };
break;
case 9:
{
if (ridx > -1)
ret = { t: "s", v: rsst[ridx] };
else if (sidx > -1)
ret = { t: "s", v: sst[sidx] };
else if (!isNaN(ieee))
ret = { t: "n", v: ieee };
else
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
break;
default:
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
return ret;
}
function parse(buf, sst, rsst) {
var version = buf[0];
switch (version) {
case 3:
case 4:
return parseit(buf, sst, rsst, version);
default:
throw new Error("Unsupported pre-BNC version ".concat(version));
}
}
// src/numbers.ts
var encode_col = function(C) {
var s = "";
for (++C; C; C = Math.floor((C - 1) / 26))
s = String.fromCharCode((C - 1) % 26 + 65) + s;
return s;
};
var encode_cell = function(c) {
return "".concat(encode_col(c.c)).concat(c.r + 1);
};
var encode_range = function(r) {
return encode_cell(r.s) + ":" + encode_cell(r.e);
};
var book_new = function() {
return { Sheets: {}, SheetNames: [] };
};
var book_append_sheet = function(wb, ws, name) {
if (!name)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf(name = "Sheet ".concat(i)) == -1)
break;
}
else if (wb.SheetNames.indexOf(name) > -1)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf("".concat(name, "_").concat(i)) == -1) {
name = "".concat(name, "_").concat(i);
break;
}
}
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
};
function parse_numbers(cfb) {
var out = [];
cfb.FileIndex.forEach(function(s) {
if (!s.name.match(/\.iwa$/))
return;
var o;
try {
o = deframe(s.content);
} catch (e) {
return console.log("?? " + s.content.length + " " + (e.message || e));
}
var packets;
try {
packets = parse_iwa(o);
} catch (e) {
return console.log("## " + (e.message || e));
}
packets.forEach(function(packet) {
out[+packet.id] = packet.messages;
});
});
if (!out.length)
throw new Error("File has no messages");
var docroot;
out.forEach(function(iwams) {
iwams.forEach(function(iwam) {
var mtype = varint_to_i32(iwam.meta[1][0].data) >>> 0;
if (mtype == 1) {
if (!docroot)
docroot = iwam;
else
throw new Error("Document has multiple roots");
}
});
});
if (!docroot)
throw new Error("Cannot find Document root");
return parse_docroot(out, docroot);
}
var numbers_default = parse_numbers;
function parse_Reference(buf) {
var pb = parse_shallow(buf);
return parse_varint49(pb[1][0].data);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries || []).forEach(function(entry) {
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data) >>> 0;
switch (type) {
case 1:
data[key] = u8str(le[3][0].data);
break;
case 8:
{
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if (mtype != 2001)
throw new Error("2000 unexpected reference to ".concat(mtype));
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(function(x) {
return u8str(x.data);
}).join("");
}
break;
}
});
return data;
}
function parse_TST_TileRowInfo(u8) {
var pb = parse_shallow(u8);
var R = varint_to_i32(pb[1][0].data) >>> 0;
var storage = pb[3][0].data;
var offsets = u8_to_dataview(pb[4][0].data);
var cells = [];
for (var C = 0; C < offsets.byteLength / 2; ++C) {
var off = offsets.getUint16(C * 2, true);
if (off > storage.length)
continue;
cells[C] = storage.subarray(off, offsets.getUint16(C * 2 + 2, true));
}
return { R: R, cells: cells };
}
function parse_TST_Tile(M, root) {
var pb = parse_shallow(root.data);
var ri = mappa(pb[5], parse_TST_TileRowInfo);
return ri.reduce(function(acc, x) {
if (!acc[x.R])
acc[x.R] = [];
x.cells.forEach(function(cell, C) {
if (acc[x.R][C])
throw new Error("Duplicate cell r=".concat(x.R, " c=").concat(C));
acc[x.R][C] = cell;
});
return acc;
}, []);
}
function parse_TST_TableModelArchive(M, root, ws) {
var _a;
var pb = parse_shallow(root.data);
var range = { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } };
range.e.r = (varint_to_i32(pb[6][0].data) >>> 0) - 1;
if (range.e.r < 0)
throw new Error("Invalid row varint ".concat(pb[6][0].data));
range.e.c = (varint_to_i32(pb[7][0].data) >>> 0) - 1;
if (range.e.c < 0)
throw new Error("Invalid col varint ".concat(pb[7][0].data));
ws["!ref"] = encode_range(range);
{
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst = ((_a = store[17]) == null ? void 0 : _a[0]) ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
var tile = parse_shallow(store[3][0].data);
var tiles = [];
tile[1].forEach(function(t) {
var tl = parse_shallow(t.data);
var ref = M[parse_Reference(tl[2][0].data)][0];
var mtype = varint_to_i32(ref.meta[1][0].data);
if (mtype != 6002)
throw new Error("6001 unexpected reference to ".concat(mtype));
tiles.push({ id: varint_to_i32(tl[1][0].data), ref: parse_TST_Tile(M, ref) });
});
tiles.forEach(function(tile2) {
tile2.ref.forEach(function(row, R) {
row.forEach(function(buf, C) {
var addr = encode_cell({ r: R, c: C });
var res = parse(buf, sst, rsst);
if (res)
ws[addr] = res;
});
});
});
}
}
}
function parse_TST_TableInfoArchive(M, root) {
var pb = parse_shallow(root.data);
var out = { "!ref": "A1" };
var tableref = M[parse_Reference(pb[2][0].data)];
var mtype = varint_to_i32(tableref[0].meta[1][0].data);
if (mtype != 6001)
throw new Error("6000 unexpected reference to ".concat(mtype));
parse_TST_TableModelArchive(M, tableref[0], out);
return out;
}
function parse_sheetroot(M, root) {
var _a;
var pb = parse_shallow(root.data);
var out = {
name: ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : "",
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
shapeoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 6e3)
out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
}
function parse_docroot(M, root) {
var out = book_new();
var pb = parse_shallow(root.data);
var sheetoffs = mappa(pb[1], parse_Reference);
sheetoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 2) {
var root2 = parse_sheetroot(M, m);
root2.sheets.forEach(function(sheet) {
book_append_sheet(out, sheet, root2.name);
});
}
});
});
if (out.SheetNames.length == 0)
throw new Error("Empty NUMBERS file");
return out;
}
return __toCommonJS(numbers_exports);
})();
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
function fix_opts_func(defaults/*:Array<Array<any> >*/)/*:{(o:any):void}*/ {
return function fix_opts(opts) {
for(var i = 0; i != defaults.length; ++i) {
@ -21603,7 +22159,16 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
/* UOC */
if(safegetzipfile(zip, 'objectdata.xml')) return parse_ods(zip, opts);
/* Numbers */
if(safegetzipfile(zip, 'Index/Document.iwa')) throw new Error('Unsupported NUMBERS file');
if(safegetzipfile(zip, 'Index/Document.iwa')) {
if(typeof Uint8Array == "undefined") throw new Error('NUMBERS file parsing requires Uint8Array support');
if(typeof NUMBERS != "undefined") {
if(zip.FileIndex) return NUMBERS.parse_numbers(zip);
var _zip = CFB.utils.cfb_new();
zipentries(zip).forEach(function(e) { zip_add_file(_zip, e, getzipbin(zip, e)); });
return NUMBERS.parse_numbers(_zip);
}
throw new Error('Unsupported NUMBERS file');
}
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
@ -22052,6 +22617,29 @@ function readFileSync(filename/*:string*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
var o = opts||{}; o.type = 'file';
return readSync(filename, o);
}
function write_obj_str(factory/*:WriteObjStrFactory*/) {
return function write_str(wb/*:Workbook*/, o/*:WriteOpts*/)/*:string*/ {
var idx = 0;
if(o.sheet) {
if(typeof o.sheet == "number") idx = o.sheet;
else idx = wb.SheetNames.indexOf(o.sheet);
if(!wb.SheetNames[idx]) throw new Error("Sheet not found: " + o.sheet + " : " + (typeof o.sheet));
}
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
function write_cfb_ctr(cfb/*:CFBContainer*/, o/*:WriteOpts*/)/*:any*/ {
switch(o.type) {
case "base64": case "binary": break;

View File

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.17.5';
XLSX.version = '0.18.0';
var current_codepage = 1200, current_ansi = 1252;
/*:: declare var cptable:any; */
/*global cptable:true, window */
@ -15,7 +15,7 @@ if(typeof module !== "undefined" && typeof require !== 'undefined') {
}
}
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
var VALID_ANSI = [ 874, 932, 936, 949, 950, 10000 ];
for(var i = 0; i <= 8; ++i) VALID_ANSI.push(1250 + i);
/* ECMA-376 Part I 18.4.1 charset to codepage mapping */
var CS2CP = ({
@ -3022,6 +3022,12 @@ function getzipstr(zip, file/*:string*/, safe/*:?boolean*/)/*:?string*/ {
try { return getzipstr(zip, file); } catch(e) { return null; }
}
function getzipbin(zip, file/*:string*/, safe/*:?boolean*/)/*:any*/ {
if(!safe) return getdatabin(getzipfile(zip, file));
if(!file) return null;
try { return getzipbin(zip, file); } catch(e) { return null; }
}
function zipentries(zip) {
var k = zip.FullPaths || keys(zip.files), o = [];
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i]);
@ -8956,15 +8962,19 @@ function parse_rpr(rpr) {
case '<color':
if(y.rgb) font.color = y.rgb.slice(2,8);
break;
case '<color>': case '<color/>': case '</color>': break;
/* 18.8.18 family ST_FontFamily */
case '<family': font.family = y.val; break;
case '<family>': case '<family/>': case '</family>': break;
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty TODO */
case '<vertAlign': font.valign = y.val; break;
case '<vertAlign>': case '<vertAlign/>': case '</vertAlign>': break;
/* 18.8.35 scheme CT_FontScheme TODO */
case '<scheme': break;
case '<scheme>': case '<scheme/>': case '</scheme>': break;
/* 18.2.10 extLst CT_ExtensionList ? */
case '<extLst': case '<extLst>': case '</extLst>': break;
@ -18626,14 +18636,14 @@ var PSCLSID = {
};
function parse_xls_props(cfb/*:CFBContainer*/, props, o) {
/* [MS-OSHARED] 2.3.3.2.2 Document Summary Information Property Set */
var DSI = CFB.find(cfb, '!DocumentSummaryInformation');
var DSI = CFB.find(cfb, '/!DocumentSummaryInformation');
if(DSI && DSI.size > 0) try {
var DocSummary = parse_PropertySetStream(DSI, DocSummaryPIDDSI, PSCLSID.DSI);
for(var d in DocSummary) props[d] = DocSummary[d];
} catch(e) {if(o.WTF) throw e;/* empty */}
/* [MS-OSHARED] 2.3.3.2.1 Summary Information Property Set*/
var SI = CFB.find(cfb, '!SummaryInformation');
var SI = CFB.find(cfb, '/!SummaryInformation');
if(SI && SI.size > 0) try {
var Summary = parse_PropertySetStream(SI, SummaryPIDSI, PSCLSID.SI);
for(var s in Summary) if(props[s] == null) props[s] = Summary[s];
@ -20435,7 +20445,7 @@ function write_biff_buf(wb/*:Workbook*/, opts/*:WriteOpts*/) {
if(!ws || !ws["!ref"]) continue;
var range = decode_range(ws["!ref"]);
if(range.e.c > 255) { // note: 255 is IV
console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
}
@ -21549,31 +21559,583 @@ function write_ods(wb/*:any*/, opts/*:any*/) {
return zip;
}
function write_sheet_index(wb/*:Workbook*/, sheet/*:?string*/)/*:number*/ {
if(!sheet) return 0;
var idx = wb.SheetNames.indexOf(sheet);
if(idx == -1) throw new Error("Sheet not found: " + sheet);
return idx;
}
var NUMBERS = (function() {
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = function(target) {
return __defProp(target, "__esModule", { value: true });
};
var __export = function(target, all) {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = function(target, module, copyDefault, desc) {
if (module && typeof module === "object" || typeof module === "function")
for (var keys = __getOwnPropNames(module), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
__defProp(target, key, { get: function(k) {
return module[k];
}.bind(null, key), enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}
return target;
};
var __toCommonJS = /* @__PURE__ */ function(cache) {
return function(module, temp) {
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
};
}(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
function write_obj_str(factory/*:WriteObjStrFactory*/) {
return function write_str(wb/*:Workbook*/, o/*:WriteOpts*/)/*:string*/ {
var idx = write_sheet_index(wb, o.sheet);
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
// 83_numbers.ts
var numbers_exports = {};
__export(numbers_exports, {
parse_numbers: function() {
return numbers_default;
}
});
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
// src/util.ts
var u8_to_dataview = function(array) {
return new DataView(array.buffer, array.byteOffset, array.byteLength);
};
var u8str = function(u8) {
return typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
};
var u8concat = function(u8a) {
var len = u8a.reduce(function(acc, x) {
return acc + x.length;
}, 0);
var out = new Uint8Array(len);
var off = 0;
u8a.forEach(function(u8) {
out.set(u8, off);
off += u8.length;
});
return out;
};
var popcnt = function(x) {
x -= x >> 1 & 1431655765;
x = (x & 858993459) + (x >> 2 & 858993459);
return (x + (x >> 4) & 252645135) * 16843009 >>> 24;
};
// src/proto.ts
function parse_varint49(buf, ptr) {
var l = ptr ? ptr[0] : 0;
var usz = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
usz |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 28);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 35);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 42);
++l;
if (buf[l++] < 128)
break varint;
}
if (ptr)
ptr[0] = l;
return usz;
}
function varint_to_i32(buf) {
var l = 0, i32 = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
i32 |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 28;
}
return i32;
}
function parse_shallow(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var off = ptr[0];
var num = parse_varint49(buf, ptr);
var type = num & 7;
num = Math.floor(num / 8);
var len = 0;
var res;
if (num == 0)
break;
switch (type) {
case 0:
{
var l = ptr[0];
while (buf[ptr[0]++] >= 128)
;
res = buf.slice(l, ptr[0]);
}
break;
case 5:
len = 4;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 1:
len = 8;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 2:
len = parse_varint49(buf, ptr);
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 3:
case 4:
default:
throw new Error("PB Type ".concat(type, " for Field ").concat(num, " at offset ").concat(off));
}
var v = { offset: off, data: res, type: type };
if (out[num] == null)
out[num] = [v];
else
out[num].push(v);
}
return out;
}
function mappa(data, cb) {
if (!data)
return [];
return data.map(function(d) {
var _a;
try {
return cb(d.data);
} catch (e) {
var m = (_a = e.message) == null ? void 0 : _a.match(/at offset (\d+)/);
if (m)
e.message = e.message.replace(/at offset (\d+)/, "at offset " + (+m[1] + d.offset));
throw e;
}
});
}
// src/frame.ts
function deframe(buf) {
var out = [];
var l = 0;
while (l < buf.length) {
var t = buf[l++];
var len = buf[l] | buf[l + 1] << 8 | buf[l + 2] << 16;
l += 3;
out.push(parse_snappy_chunk(t, buf.slice(l, l + len)));
l += len;
}
if (l !== buf.length)
throw new Error("data is not a valid framed stream!");
return u8concat(out);
}
function parse_snappy_chunk(type, buf) {
if (type != 0)
throw new Error("Unexpected Snappy chunk type ".concat(type));
var ptr = [0];
var usz = parse_varint49(buf, ptr);
var chunks = [];
while (ptr[0] < buf.length) {
var tag = buf[ptr[0]] & 3;
if (tag == 0) {
var len = buf[ptr[0]++] >> 2;
if (len < 60)
++len;
else {
var c = len - 59;
len = buf[ptr[0]];
if (c > 1)
len |= buf[ptr[0] + 1] << 8;
if (c > 2)
len |= buf[ptr[0] + 2] << 16;
if (c > 3)
len |= buf[ptr[0] + 3] << 24;
len >>>= 0;
len++;
ptr[0] += c;
}
chunks.push(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
continue;
} else {
var offset = 0, length = 0;
if (tag == 1) {
length = (buf[ptr[0]] >> 2 & 7) + 4;
offset = (buf[ptr[0]++] & 224) << 3;
offset |= buf[ptr[0]++];
} else {
length = (buf[ptr[0]++] >> 2) + 1;
if (tag == 2) {
offset = buf[ptr[0]] | buf[ptr[0] + 1] << 8;
ptr[0] += 2;
} else {
offset = (buf[ptr[0]] | buf[ptr[0] + 1] << 8 | buf[ptr[0] + 2] << 16 | buf[ptr[0] + 3] << 24) >>> 0;
ptr[0] += 4;
}
}
chunks = [u8concat(chunks)];
if (offset == 0)
throw new Error("Invalid offset 0");
if (offset > chunks[0].length)
throw new Error("Invalid offset beyond length");
if (length >= offset) {
chunks.push(chunks[0].slice(-offset));
length -= offset;
while (length >= chunks[chunks.length - 1].length) {
chunks.push(chunks[chunks.length - 1]);
length -= chunks[chunks.length - 1].length;
}
}
chunks.push(chunks[0].slice(-offset, -offset + length));
}
}
var o = u8concat(chunks);
if (o.length != usz)
throw new Error("Unexpected length: ".concat(o.length, " != ").concat(usz));
return o;
}
// src/iwa.ts
function parse_iwa(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var len = parse_varint49(buf, ptr);
var ai = parse_shallow(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
var res = {
id: varint_to_i32(ai[1][0].data),
messages: []
};
ai[2].forEach(function(b) {
var mi = parse_shallow(b.data);
var fl = varint_to_i32(mi[3][0].data);
res.messages.push({
meta: mi,
data: buf.slice(ptr[0], ptr[0] + fl)
});
ptr[0] += fl;
});
out.push(res);
}
return out;
}
// src/prebnccell.ts
function parseit(buf, sst, rsst, version) {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 3470) * 4;
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if (flags & 512) {
ridx = dv.getUint32(data_offset, true);
data_offset += 4;
}
data_offset += popcnt(flags & 12288) * 4;
if (flags & 16) {
sidx = dv.getUint32(data_offset, true);
data_offset += 4;
}
if (flags & 32) {
ieee = dv.getFloat64(data_offset, true);
data_offset += 8;
}
if (flags & 64) {
dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1e3);
data_offset += 8;
}
var ret;
switch (ctype) {
case 0:
break;
case 2:
ret = { t: "n", v: ieee };
break;
case 3:
ret = { t: "s", v: sst[sidx] };
break;
case 5:
ret = { t: "d", v: dt };
break;
case 6:
ret = { t: "b", v: ieee > 0 };
break;
case 7:
ret = { t: "n", v: ieee };
break;
case 8:
ret = { t: "e", v: 0 };
break;
case 9:
{
if (ridx > -1)
ret = { t: "s", v: rsst[ridx] };
else if (sidx > -1)
ret = { t: "s", v: sst[sidx] };
else if (!isNaN(ieee))
ret = { t: "n", v: ieee };
else
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
break;
default:
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
return ret;
}
function parse(buf, sst, rsst) {
var version = buf[0];
switch (version) {
case 3:
case 4:
return parseit(buf, sst, rsst, version);
default:
throw new Error("Unsupported pre-BNC version ".concat(version));
}
}
// src/numbers.ts
var encode_col = function(C) {
var s = "";
for (++C; C; C = Math.floor((C - 1) / 26))
s = String.fromCharCode((C - 1) % 26 + 65) + s;
return s;
};
var encode_cell = function(c) {
return "".concat(encode_col(c.c)).concat(c.r + 1);
};
var encode_range = function(r) {
return encode_cell(r.s) + ":" + encode_cell(r.e);
};
var book_new = function() {
return { Sheets: {}, SheetNames: [] };
};
var book_append_sheet = function(wb, ws, name) {
if (!name)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf(name = "Sheet ".concat(i)) == -1)
break;
}
else if (wb.SheetNames.indexOf(name) > -1)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf("".concat(name, "_").concat(i)) == -1) {
name = "".concat(name, "_").concat(i);
break;
}
}
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
};
function parse_numbers(cfb) {
var out = [];
cfb.FileIndex.forEach(function(s) {
if (!s.name.match(/\.iwa$/))
return;
var o;
try {
o = deframe(s.content);
} catch (e) {
return console.log("?? " + s.content.length + " " + (e.message || e));
}
var packets;
try {
packets = parse_iwa(o);
} catch (e) {
return console.log("## " + (e.message || e));
}
packets.forEach(function(packet) {
out[+packet.id] = packet.messages;
});
});
if (!out.length)
throw new Error("File has no messages");
var docroot;
out.forEach(function(iwams) {
iwams.forEach(function(iwam) {
var mtype = varint_to_i32(iwam.meta[1][0].data) >>> 0;
if (mtype == 1) {
if (!docroot)
docroot = iwam;
else
throw new Error("Document has multiple roots");
}
});
});
if (!docroot)
throw new Error("Cannot find Document root");
return parse_docroot(out, docroot);
}
var numbers_default = parse_numbers;
function parse_Reference(buf) {
var pb = parse_shallow(buf);
return parse_varint49(pb[1][0].data);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries || []).forEach(function(entry) {
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data) >>> 0;
switch (type) {
case 1:
data[key] = u8str(le[3][0].data);
break;
case 8:
{
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if (mtype != 2001)
throw new Error("2000 unexpected reference to ".concat(mtype));
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(function(x) {
return u8str(x.data);
}).join("");
}
break;
}
});
return data;
}
function parse_TST_TileRowInfo(u8) {
var pb = parse_shallow(u8);
var R = varint_to_i32(pb[1][0].data) >>> 0;
var storage = pb[3][0].data;
var offsets = u8_to_dataview(pb[4][0].data);
var cells = [];
for (var C = 0; C < offsets.byteLength / 2; ++C) {
var off = offsets.getUint16(C * 2, true);
if (off > storage.length)
continue;
cells[C] = storage.subarray(off, offsets.getUint16(C * 2 + 2, true));
}
return { R: R, cells: cells };
}
function parse_TST_Tile(M, root) {
var pb = parse_shallow(root.data);
var ri = mappa(pb[5], parse_TST_TileRowInfo);
return ri.reduce(function(acc, x) {
if (!acc[x.R])
acc[x.R] = [];
x.cells.forEach(function(cell, C) {
if (acc[x.R][C])
throw new Error("Duplicate cell r=".concat(x.R, " c=").concat(C));
acc[x.R][C] = cell;
});
return acc;
}, []);
}
function parse_TST_TableModelArchive(M, root, ws) {
var _a;
var pb = parse_shallow(root.data);
var range = { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } };
range.e.r = (varint_to_i32(pb[6][0].data) >>> 0) - 1;
if (range.e.r < 0)
throw new Error("Invalid row varint ".concat(pb[6][0].data));
range.e.c = (varint_to_i32(pb[7][0].data) >>> 0) - 1;
if (range.e.c < 0)
throw new Error("Invalid col varint ".concat(pb[7][0].data));
ws["!ref"] = encode_range(range);
{
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst = ((_a = store[17]) == null ? void 0 : _a[0]) ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
var tile = parse_shallow(store[3][0].data);
var tiles = [];
tile[1].forEach(function(t) {
var tl = parse_shallow(t.data);
var ref = M[parse_Reference(tl[2][0].data)][0];
var mtype = varint_to_i32(ref.meta[1][0].data);
if (mtype != 6002)
throw new Error("6001 unexpected reference to ".concat(mtype));
tiles.push({ id: varint_to_i32(tl[1][0].data), ref: parse_TST_Tile(M, ref) });
});
tiles.forEach(function(tile2) {
tile2.ref.forEach(function(row, R) {
row.forEach(function(buf, C) {
var addr = encode_cell({ r: R, c: C });
var res = parse(buf, sst, rsst);
if (res)
ws[addr] = res;
});
});
});
}
}
}
function parse_TST_TableInfoArchive(M, root) {
var pb = parse_shallow(root.data);
var out = { "!ref": "A1" };
var tableref = M[parse_Reference(pb[2][0].data)];
var mtype = varint_to_i32(tableref[0].meta[1][0].data);
if (mtype != 6001)
throw new Error("6000 unexpected reference to ".concat(mtype));
parse_TST_TableModelArchive(M, tableref[0], out);
return out;
}
function parse_sheetroot(M, root) {
var _a;
var pb = parse_shallow(root.data);
var out = {
name: ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : "",
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
shapeoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 6e3)
out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
}
function parse_docroot(M, root) {
var out = book_new();
var pb = parse_shallow(root.data);
var sheetoffs = mappa(pb[1], parse_Reference);
sheetoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 2) {
var root2 = parse_sheetroot(M, m);
root2.sheets.forEach(function(sheet) {
book_append_sheet(out, sheet, root2.name);
});
}
});
});
if (out.SheetNames.length == 0)
throw new Error("Empty NUMBERS file");
return out;
}
return __toCommonJS(numbers_exports);
})();
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
function fix_opts_func(defaults/*:Array<Array<any> >*/)/*:{(o:any):void}*/ {
return function fix_opts(opts) {
for(var i = 0; i != defaults.length; ++i) {
@ -21680,7 +22242,16 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
/* UOC */
if(safegetzipfile(zip, 'objectdata.xml')) return parse_ods(zip, opts);
/* Numbers */
if(safegetzipfile(zip, 'Index/Document.iwa')) throw new Error('Unsupported NUMBERS file');
if(safegetzipfile(zip, 'Index/Document.iwa')) {
if(typeof Uint8Array == "undefined") throw new Error('NUMBERS file parsing requires Uint8Array support');
if(typeof NUMBERS != "undefined") {
if(zip.FileIndex) return NUMBERS.parse_numbers(zip);
var _zip = CFB.utils.cfb_new();
zipentries(zip).forEach(function(e) { zip_add_file(_zip, e, getzipbin(zip, e)); });
return NUMBERS.parse_numbers(_zip);
}
throw new Error('Unsupported NUMBERS file');
}
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
@ -22129,6 +22700,29 @@ function readFileSync(filename/*:string*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
var o = opts||{}; o.type = 'file';
return readSync(filename, o);
}
function write_obj_str(factory/*:WriteObjStrFactory*/) {
return function write_str(wb/*:Workbook*/, o/*:WriteOpts*/)/*:string*/ {
var idx = 0;
if(o.sheet) {
if(typeof o.sheet == "number") idx = o.sheet;
else idx = wb.SheetNames.indexOf(o.sheet);
if(!wb.SheetNames[idx]) throw new Error("Sheet not found: " + o.sheet + " : " + (typeof o.sheet));
}
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
function write_cfb_ctr(cfb/*:CFBContainer*/, o/*:WriteOpts*/)/*:any*/ {
switch(o.type) {
case "base64": case "binary": break;
@ -22818,5 +23412,3 @@ else if(typeof define === 'function' && define.amd) define('xlsx', function() {
else make_xlsx_lib(XLSX);
/* NOTE: the following extra line is needed for "Lightning Locker Service" */
if(typeof window !== 'undefined' && !window.XLSX) try { window.XLSX = XLSX; } catch(e) {}
/*exported XLS, ODS */
var XLS = XLSX, ODS = XLSX;

652
xlsx.js generated
View File

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.17.5';
XLSX.version = '0.18.0';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -14,7 +14,7 @@ if(typeof module !== "undefined" && typeof require !== 'undefined') {
}
}
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
var VALID_ANSI = [ 874, 932, 936, 949, 950, 10000 ];
for(var i = 0; i <= 8; ++i) VALID_ANSI.push(1250 + i);
/* ECMA-376 Part I 18.4.1 charset to codepage mapping */
var CS2CP = ({
@ -2942,6 +2942,12 @@ function getzipstr(zip, file, safe) {
try { return getzipstr(zip, file); } catch(e) { return null; }
}
function getzipbin(zip, file, safe) {
if(!safe) return getdatabin(getzipfile(zip, file));
if(!file) return null;
try { return getzipbin(zip, file); } catch(e) { return null; }
}
function zipentries(zip) {
var k = zip.FullPaths || keys(zip.files), o = [];
for(var i = 0; i < k.length; ++i) if(k[i].slice(-1) != '/') o.push(k[i]);
@ -8858,15 +8864,19 @@ function parse_rpr(rpr) {
case '<color':
if(y.rgb) font.color = y.rgb.slice(2,8);
break;
case '<color>': case '<color/>': case '</color>': break;
/* 18.8.18 family ST_FontFamily */
case '<family': font.family = y.val; break;
case '<family>': case '<family/>': case '</family>': break;
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty TODO */
case '<vertAlign': font.valign = y.val; break;
case '<vertAlign>': case '<vertAlign/>': case '</vertAlign>': break;
/* 18.8.35 scheme CT_FontScheme TODO */
case '<scheme': break;
case '<scheme>': case '<scheme/>': case '</scheme>': break;
/* 18.2.10 extLst CT_ExtensionList ? */
case '<extLst': case '<extLst>': case '</extLst>': break;
@ -18509,14 +18519,14 @@ var PSCLSID = {
};
function parse_xls_props(cfb, props, o) {
/* [MS-OSHARED] 2.3.3.2.2 Document Summary Information Property Set */
var DSI = CFB.find(cfb, '!DocumentSummaryInformation');
var DSI = CFB.find(cfb, '/!DocumentSummaryInformation');
if(DSI && DSI.size > 0) try {
var DocSummary = parse_PropertySetStream(DSI, DocSummaryPIDDSI, PSCLSID.DSI);
for(var d in DocSummary) props[d] = DocSummary[d];
} catch(e) {if(o.WTF) throw e;/* empty */}
/* [MS-OSHARED] 2.3.3.2.1 Summary Information Property Set*/
var SI = CFB.find(cfb, '!SummaryInformation');
var SI = CFB.find(cfb, '/!SummaryInformation');
if(SI && SI.size > 0) try {
var Summary = parse_PropertySetStream(SI, SummaryPIDSI, PSCLSID.SI);
for(var s in Summary) if(props[s] == null) props[s] = Summary[s];
@ -20317,7 +20327,7 @@ function write_biff_buf(wb, opts) {
if(!ws || !ws["!ref"]) continue;
var range = decode_range(ws["!ref"]);
if(range.e.c > 255) { // note: 255 is IV
console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
}
@ -21431,31 +21441,583 @@ function write_ods(wb, opts) {
return zip;
}
function write_sheet_index(wb, sheet) {
if(!sheet) return 0;
var idx = wb.SheetNames.indexOf(sheet);
if(idx == -1) throw new Error("Sheet not found: " + sheet);
return idx;
}
var NUMBERS = (function() {
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = function(target) {
return __defProp(target, "__esModule", { value: true });
};
var __export = function(target, all) {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = function(target, module, copyDefault, desc) {
if (module && typeof module === "object" || typeof module === "function")
for (var keys = __getOwnPropNames(module), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
__defProp(target, key, { get: function(k) {
return module[k];
}.bind(null, key), enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}
return target;
};
var __toCommonJS = /* @__PURE__ */ function(cache) {
return function(module, temp) {
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
};
}(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
function write_obj_str(factory) {
return function write_str(wb, o) {
var idx = write_sheet_index(wb, o.sheet);
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
// 83_numbers.ts
var numbers_exports = {};
__export(numbers_exports, {
parse_numbers: function() {
return numbers_default;
}
});
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
// src/util.ts
var u8_to_dataview = function(array) {
return new DataView(array.buffer, array.byteOffset, array.byteLength);
};
var u8str = function(u8) {
return typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
};
var u8concat = function(u8a) {
var len = u8a.reduce(function(acc, x) {
return acc + x.length;
}, 0);
var out = new Uint8Array(len);
var off = 0;
u8a.forEach(function(u8) {
out.set(u8, off);
off += u8.length;
});
return out;
};
var popcnt = function(x) {
x -= x >> 1 & 1431655765;
x = (x & 858993459) + (x >> 2 & 858993459);
return (x + (x >> 4) & 252645135) * 16843009 >>> 24;
};
// src/proto.ts
function parse_varint49(buf, ptr) {
var l = ptr ? ptr[0] : 0;
var usz = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
usz |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 28);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 35);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 42);
++l;
if (buf[l++] < 128)
break varint;
}
if (ptr)
ptr[0] = l;
return usz;
}
function varint_to_i32(buf) {
var l = 0, i32 = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
i32 |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 28;
}
return i32;
}
function parse_shallow(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var off = ptr[0];
var num = parse_varint49(buf, ptr);
var type = num & 7;
num = Math.floor(num / 8);
var len = 0;
var res;
if (num == 0)
break;
switch (type) {
case 0:
{
var l = ptr[0];
while (buf[ptr[0]++] >= 128)
;
res = buf.slice(l, ptr[0]);
}
break;
case 5:
len = 4;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 1:
len = 8;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 2:
len = parse_varint49(buf, ptr);
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 3:
case 4:
default:
throw new Error("PB Type ".concat(type, " for Field ").concat(num, " at offset ").concat(off));
}
var v = { offset: off, data: res, type: type };
if (out[num] == null)
out[num] = [v];
else
out[num].push(v);
}
return out;
}
function mappa(data, cb) {
if (!data)
return [];
return data.map(function(d) {
var _a;
try {
return cb(d.data);
} catch (e) {
var m = (_a = e.message) == null ? void 0 : _a.match(/at offset (\d+)/);
if (m)
e.message = e.message.replace(/at offset (\d+)/, "at offset " + (+m[1] + d.offset));
throw e;
}
});
}
// src/frame.ts
function deframe(buf) {
var out = [];
var l = 0;
while (l < buf.length) {
var t = buf[l++];
var len = buf[l] | buf[l + 1] << 8 | buf[l + 2] << 16;
l += 3;
out.push(parse_snappy_chunk(t, buf.slice(l, l + len)));
l += len;
}
if (l !== buf.length)
throw new Error("data is not a valid framed stream!");
return u8concat(out);
}
function parse_snappy_chunk(type, buf) {
if (type != 0)
throw new Error("Unexpected Snappy chunk type ".concat(type));
var ptr = [0];
var usz = parse_varint49(buf, ptr);
var chunks = [];
while (ptr[0] < buf.length) {
var tag = buf[ptr[0]] & 3;
if (tag == 0) {
var len = buf[ptr[0]++] >> 2;
if (len < 60)
++len;
else {
var c = len - 59;
len = buf[ptr[0]];
if (c > 1)
len |= buf[ptr[0] + 1] << 8;
if (c > 2)
len |= buf[ptr[0] + 2] << 16;
if (c > 3)
len |= buf[ptr[0] + 3] << 24;
len >>>= 0;
len++;
ptr[0] += c;
}
chunks.push(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
continue;
} else {
var offset = 0, length = 0;
if (tag == 1) {
length = (buf[ptr[0]] >> 2 & 7) + 4;
offset = (buf[ptr[0]++] & 224) << 3;
offset |= buf[ptr[0]++];
} else {
length = (buf[ptr[0]++] >> 2) + 1;
if (tag == 2) {
offset = buf[ptr[0]] | buf[ptr[0] + 1] << 8;
ptr[0] += 2;
} else {
offset = (buf[ptr[0]] | buf[ptr[0] + 1] << 8 | buf[ptr[0] + 2] << 16 | buf[ptr[0] + 3] << 24) >>> 0;
ptr[0] += 4;
}
}
chunks = [u8concat(chunks)];
if (offset == 0)
throw new Error("Invalid offset 0");
if (offset > chunks[0].length)
throw new Error("Invalid offset beyond length");
if (length >= offset) {
chunks.push(chunks[0].slice(-offset));
length -= offset;
while (length >= chunks[chunks.length - 1].length) {
chunks.push(chunks[chunks.length - 1]);
length -= chunks[chunks.length - 1].length;
}
}
chunks.push(chunks[0].slice(-offset, -offset + length));
}
}
var o = u8concat(chunks);
if (o.length != usz)
throw new Error("Unexpected length: ".concat(o.length, " != ").concat(usz));
return o;
}
// src/iwa.ts
function parse_iwa(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var len = parse_varint49(buf, ptr);
var ai = parse_shallow(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
var res = {
id: varint_to_i32(ai[1][0].data),
messages: []
};
ai[2].forEach(function(b) {
var mi = parse_shallow(b.data);
var fl = varint_to_i32(mi[3][0].data);
res.messages.push({
meta: mi,
data: buf.slice(ptr[0], ptr[0] + fl)
});
ptr[0] += fl;
});
out.push(res);
}
return out;
}
// src/prebnccell.ts
function parseit(buf, sst, rsst, version) {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 3470) * 4;
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if (flags & 512) {
ridx = dv.getUint32(data_offset, true);
data_offset += 4;
}
data_offset += popcnt(flags & 12288) * 4;
if (flags & 16) {
sidx = dv.getUint32(data_offset, true);
data_offset += 4;
}
if (flags & 32) {
ieee = dv.getFloat64(data_offset, true);
data_offset += 8;
}
if (flags & 64) {
dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1e3);
data_offset += 8;
}
var ret;
switch (ctype) {
case 0:
break;
case 2:
ret = { t: "n", v: ieee };
break;
case 3:
ret = { t: "s", v: sst[sidx] };
break;
case 5:
ret = { t: "d", v: dt };
break;
case 6:
ret = { t: "b", v: ieee > 0 };
break;
case 7:
ret = { t: "n", v: ieee };
break;
case 8:
ret = { t: "e", v: 0 };
break;
case 9:
{
if (ridx > -1)
ret = { t: "s", v: rsst[ridx] };
else if (sidx > -1)
ret = { t: "s", v: sst[sidx] };
else if (!isNaN(ieee))
ret = { t: "n", v: ieee };
else
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
break;
default:
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
return ret;
}
function parse(buf, sst, rsst) {
var version = buf[0];
switch (version) {
case 3:
case 4:
return parseit(buf, sst, rsst, version);
default:
throw new Error("Unsupported pre-BNC version ".concat(version));
}
}
// src/numbers.ts
var encode_col = function(C) {
var s = "";
for (++C; C; C = Math.floor((C - 1) / 26))
s = String.fromCharCode((C - 1) % 26 + 65) + s;
return s;
};
var encode_cell = function(c) {
return "".concat(encode_col(c.c)).concat(c.r + 1);
};
var encode_range = function(r) {
return encode_cell(r.s) + ":" + encode_cell(r.e);
};
var book_new = function() {
return { Sheets: {}, SheetNames: [] };
};
var book_append_sheet = function(wb, ws, name) {
if (!name)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf(name = "Sheet ".concat(i)) == -1)
break;
}
else if (wb.SheetNames.indexOf(name) > -1)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf("".concat(name, "_").concat(i)) == -1) {
name = "".concat(name, "_").concat(i);
break;
}
}
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
};
function parse_numbers(cfb) {
var out = [];
cfb.FileIndex.forEach(function(s) {
if (!s.name.match(/\.iwa$/))
return;
var o;
try {
o = deframe(s.content);
} catch (e) {
return console.log("?? " + s.content.length + " " + (e.message || e));
}
var packets;
try {
packets = parse_iwa(o);
} catch (e) {
return console.log("## " + (e.message || e));
}
packets.forEach(function(packet) {
out[+packet.id] = packet.messages;
});
});
if (!out.length)
throw new Error("File has no messages");
var docroot;
out.forEach(function(iwams) {
iwams.forEach(function(iwam) {
var mtype = varint_to_i32(iwam.meta[1][0].data) >>> 0;
if (mtype == 1) {
if (!docroot)
docroot = iwam;
else
throw new Error("Document has multiple roots");
}
});
});
if (!docroot)
throw new Error("Cannot find Document root");
return parse_docroot(out, docroot);
}
var numbers_default = parse_numbers;
function parse_Reference(buf) {
var pb = parse_shallow(buf);
return parse_varint49(pb[1][0].data);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries || []).forEach(function(entry) {
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data) >>> 0;
switch (type) {
case 1:
data[key] = u8str(le[3][0].data);
break;
case 8:
{
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if (mtype != 2001)
throw new Error("2000 unexpected reference to ".concat(mtype));
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(function(x) {
return u8str(x.data);
}).join("");
}
break;
}
});
return data;
}
function parse_TST_TileRowInfo(u8) {
var pb = parse_shallow(u8);
var R = varint_to_i32(pb[1][0].data) >>> 0;
var storage = pb[3][0].data;
var offsets = u8_to_dataview(pb[4][0].data);
var cells = [];
for (var C = 0; C < offsets.byteLength / 2; ++C) {
var off = offsets.getUint16(C * 2, true);
if (off > storage.length)
continue;
cells[C] = storage.subarray(off, offsets.getUint16(C * 2 + 2, true));
}
return { R: R, cells: cells };
}
function parse_TST_Tile(M, root) {
var pb = parse_shallow(root.data);
var ri = mappa(pb[5], parse_TST_TileRowInfo);
return ri.reduce(function(acc, x) {
if (!acc[x.R])
acc[x.R] = [];
x.cells.forEach(function(cell, C) {
if (acc[x.R][C])
throw new Error("Duplicate cell r=".concat(x.R, " c=").concat(C));
acc[x.R][C] = cell;
});
return acc;
}, []);
}
function parse_TST_TableModelArchive(M, root, ws) {
var _a;
var pb = parse_shallow(root.data);
var range = { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } };
range.e.r = (varint_to_i32(pb[6][0].data) >>> 0) - 1;
if (range.e.r < 0)
throw new Error("Invalid row varint ".concat(pb[6][0].data));
range.e.c = (varint_to_i32(pb[7][0].data) >>> 0) - 1;
if (range.e.c < 0)
throw new Error("Invalid col varint ".concat(pb[7][0].data));
ws["!ref"] = encode_range(range);
{
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst = ((_a = store[17]) == null ? void 0 : _a[0]) ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
var tile = parse_shallow(store[3][0].data);
var tiles = [];
tile[1].forEach(function(t) {
var tl = parse_shallow(t.data);
var ref = M[parse_Reference(tl[2][0].data)][0];
var mtype = varint_to_i32(ref.meta[1][0].data);
if (mtype != 6002)
throw new Error("6001 unexpected reference to ".concat(mtype));
tiles.push({ id: varint_to_i32(tl[1][0].data), ref: parse_TST_Tile(M, ref) });
});
tiles.forEach(function(tile2) {
tile2.ref.forEach(function(row, R) {
row.forEach(function(buf, C) {
var addr = encode_cell({ r: R, c: C });
var res = parse(buf, sst, rsst);
if (res)
ws[addr] = res;
});
});
});
}
}
}
function parse_TST_TableInfoArchive(M, root) {
var pb = parse_shallow(root.data);
var out = { "!ref": "A1" };
var tableref = M[parse_Reference(pb[2][0].data)];
var mtype = varint_to_i32(tableref[0].meta[1][0].data);
if (mtype != 6001)
throw new Error("6000 unexpected reference to ".concat(mtype));
parse_TST_TableModelArchive(M, tableref[0], out);
return out;
}
function parse_sheetroot(M, root) {
var _a;
var pb = parse_shallow(root.data);
var out = {
name: ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : "",
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
shapeoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 6e3)
out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
}
function parse_docroot(M, root) {
var out = book_new();
var pb = parse_shallow(root.data);
var sheetoffs = mappa(pb[1], parse_Reference);
sheetoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 2) {
var root2 = parse_sheetroot(M, m);
root2.sheets.forEach(function(sheet) {
book_append_sheet(out, sheet, root2.name);
});
}
});
});
if (out.SheetNames.length == 0)
throw new Error("Empty NUMBERS file");
return out;
}
return __toCommonJS(numbers_exports);
})();
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
function fix_opts_func(defaults) {
return function fix_opts(opts) {
for(var i = 0; i != defaults.length; ++i) {
@ -21562,7 +22124,16 @@ function parse_zip(zip, opts) {
/* UOC */
if(safegetzipfile(zip, 'objectdata.xml')) return parse_ods(zip, opts);
/* Numbers */
if(safegetzipfile(zip, 'Index/Document.iwa')) throw new Error('Unsupported NUMBERS file');
if(safegetzipfile(zip, 'Index/Document.iwa')) {
if(typeof Uint8Array == "undefined") throw new Error('NUMBERS file parsing requires Uint8Array support');
if(typeof NUMBERS != "undefined") {
if(zip.FileIndex) return NUMBERS.parse_numbers(zip);
var _zip = CFB.utils.cfb_new();
zipentries(zip).forEach(function(e) { zip_add_file(_zip, e, getzipbin(zip, e)); });
return NUMBERS.parse_numbers(_zip);
}
throw new Error('Unsupported NUMBERS file');
}
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
@ -22008,6 +22579,29 @@ function readFileSync(filename, opts) {
var o = opts||{}; o.type = 'file';
return readSync(filename, o);
}
function write_obj_str(factory) {
return function write_str(wb, o) {
var idx = 0;
if(o.sheet) {
if(typeof o.sheet == "number") idx = o.sheet;
else idx = wb.SheetNames.indexOf(o.sheet);
if(!wb.SheetNames[idx]) throw new Error("Sheet not found: " + o.sheet + " : " + (typeof o.sheet));
}
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
function write_cfb_ctr(cfb, o) {
switch(o.type) {
case "base64": case "binary": break;
@ -22689,5 +23283,3 @@ else if(typeof define === 'function' && define.amd) define('xlsx', function() {
else make_xlsx_lib(XLSX);
/* NOTE: the following extra line is needed for "Lightning Locker Service" */
if(typeof window !== 'undefined' && !window.XLSX) try { window.XLSX = XLSX; } catch(e) {}
/*exported XLS, ODS */
var XLS = XLSX, ODS = XLSX;

View File

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.17.5';
XLSX.version = '0.18.0';
var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
@ -5857,15 +5857,19 @@ function parse_rpr(rpr) {
case '<color':
if(y.rgb) font.color = y.rgb.slice(2,8);
break;
case '<color>': case '<color/>': case '</color>': break;
/* 18.8.18 family ST_FontFamily */
case '<family': font.family = y.val; break;
case '<family>': case '<family/>': case '</family>': break;
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty TODO */
case '<vertAlign': font.valign = y.val; break;
case '<vertAlign>': case '<vertAlign/>': case '</vertAlign>': break;
/* 18.8.35 scheme CT_FontScheme TODO */
case '<scheme': break;
case '<scheme>': case '<scheme/>': case '</scheme>': break;
/* 18.2.10 extLst CT_ExtensionList ? */
case '<extLst': case '<extLst>': case '</extLst>': break;
@ -9665,31 +9669,583 @@ function write_ods(wb/*:any*/, opts/*:any*/) {
return zip;
}
function write_sheet_index(wb/*:Workbook*/, sheet/*:?string*/)/*:number*/ {
if(!sheet) return 0;
var idx = wb.SheetNames.indexOf(sheet);
if(idx == -1) throw new Error("Sheet not found: " + sheet);
return idx;
}
var NUMBERS = (function() {
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = function(target) {
return __defProp(target, "__esModule", { value: true });
};
var __export = function(target, all) {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = function(target, module, copyDefault, desc) {
if (module && typeof module === "object" || typeof module === "function")
for (var keys = __getOwnPropNames(module), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
__defProp(target, key, { get: function(k) {
return module[k];
}.bind(null, key), enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}
return target;
};
var __toCommonJS = /* @__PURE__ */ function(cache) {
return function(module, temp) {
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
};
}(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
function write_obj_str(factory/*:WriteObjStrFactory*/) {
return function write_str(wb/*:Workbook*/, o/*:WriteOpts*/)/*:string*/ {
var idx = write_sheet_index(wb, o.sheet);
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
// 83_numbers.ts
var numbers_exports = {};
__export(numbers_exports, {
parse_numbers: function() {
return numbers_default;
}
});
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
// src/util.ts
var u8_to_dataview = function(array) {
return new DataView(array.buffer, array.byteOffset, array.byteLength);
};
var u8str = function(u8) {
return typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
};
var u8concat = function(u8a) {
var len = u8a.reduce(function(acc, x) {
return acc + x.length;
}, 0);
var out = new Uint8Array(len);
var off = 0;
u8a.forEach(function(u8) {
out.set(u8, off);
off += u8.length;
});
return out;
};
var popcnt = function(x) {
x -= x >> 1 & 1431655765;
x = (x & 858993459) + (x >> 2 & 858993459);
return (x + (x >> 4) & 252645135) * 16843009 >>> 24;
};
// src/proto.ts
function parse_varint49(buf, ptr) {
var l = ptr ? ptr[0] : 0;
var usz = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
usz |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 28);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 35);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 42);
++l;
if (buf[l++] < 128)
break varint;
}
if (ptr)
ptr[0] = l;
return usz;
}
function varint_to_i32(buf) {
var l = 0, i32 = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
i32 |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 28;
}
return i32;
}
function parse_shallow(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var off = ptr[0];
var num = parse_varint49(buf, ptr);
var type = num & 7;
num = Math.floor(num / 8);
var len = 0;
var res;
if (num == 0)
break;
switch (type) {
case 0:
{
var l = ptr[0];
while (buf[ptr[0]++] >= 128)
;
res = buf.slice(l, ptr[0]);
}
break;
case 5:
len = 4;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 1:
len = 8;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 2:
len = parse_varint49(buf, ptr);
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 3:
case 4:
default:
throw new Error("PB Type ".concat(type, " for Field ").concat(num, " at offset ").concat(off));
}
var v = { offset: off, data: res, type: type };
if (out[num] == null)
out[num] = [v];
else
out[num].push(v);
}
return out;
}
function mappa(data, cb) {
if (!data)
return [];
return data.map(function(d) {
var _a;
try {
return cb(d.data);
} catch (e) {
var m = (_a = e.message) == null ? void 0 : _a.match(/at offset (\d+)/);
if (m)
e.message = e.message.replace(/at offset (\d+)/, "at offset " + (+m[1] + d.offset));
throw e;
}
});
}
// src/frame.ts
function deframe(buf) {
var out = [];
var l = 0;
while (l < buf.length) {
var t = buf[l++];
var len = buf[l] | buf[l + 1] << 8 | buf[l + 2] << 16;
l += 3;
out.push(parse_snappy_chunk(t, buf.slice(l, l + len)));
l += len;
}
if (l !== buf.length)
throw new Error("data is not a valid framed stream!");
return u8concat(out);
}
function parse_snappy_chunk(type, buf) {
if (type != 0)
throw new Error("Unexpected Snappy chunk type ".concat(type));
var ptr = [0];
var usz = parse_varint49(buf, ptr);
var chunks = [];
while (ptr[0] < buf.length) {
var tag = buf[ptr[0]] & 3;
if (tag == 0) {
var len = buf[ptr[0]++] >> 2;
if (len < 60)
++len;
else {
var c = len - 59;
len = buf[ptr[0]];
if (c > 1)
len |= buf[ptr[0] + 1] << 8;
if (c > 2)
len |= buf[ptr[0] + 2] << 16;
if (c > 3)
len |= buf[ptr[0] + 3] << 24;
len >>>= 0;
len++;
ptr[0] += c;
}
chunks.push(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
continue;
} else {
var offset = 0, length = 0;
if (tag == 1) {
length = (buf[ptr[0]] >> 2 & 7) + 4;
offset = (buf[ptr[0]++] & 224) << 3;
offset |= buf[ptr[0]++];
} else {
length = (buf[ptr[0]++] >> 2) + 1;
if (tag == 2) {
offset = buf[ptr[0]] | buf[ptr[0] + 1] << 8;
ptr[0] += 2;
} else {
offset = (buf[ptr[0]] | buf[ptr[0] + 1] << 8 | buf[ptr[0] + 2] << 16 | buf[ptr[0] + 3] << 24) >>> 0;
ptr[0] += 4;
}
}
chunks = [u8concat(chunks)];
if (offset == 0)
throw new Error("Invalid offset 0");
if (offset > chunks[0].length)
throw new Error("Invalid offset beyond length");
if (length >= offset) {
chunks.push(chunks[0].slice(-offset));
length -= offset;
while (length >= chunks[chunks.length - 1].length) {
chunks.push(chunks[chunks.length - 1]);
length -= chunks[chunks.length - 1].length;
}
}
chunks.push(chunks[0].slice(-offset, -offset + length));
}
}
var o = u8concat(chunks);
if (o.length != usz)
throw new Error("Unexpected length: ".concat(o.length, " != ").concat(usz));
return o;
}
// src/iwa.ts
function parse_iwa(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var len = parse_varint49(buf, ptr);
var ai = parse_shallow(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
var res = {
id: varint_to_i32(ai[1][0].data),
messages: []
};
ai[2].forEach(function(b) {
var mi = parse_shallow(b.data);
var fl = varint_to_i32(mi[3][0].data);
res.messages.push({
meta: mi,
data: buf.slice(ptr[0], ptr[0] + fl)
});
ptr[0] += fl;
});
out.push(res);
}
return out;
}
// src/prebnccell.ts
function parseit(buf, sst, rsst, version) {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 3470) * 4;
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if (flags & 512) {
ridx = dv.getUint32(data_offset, true);
data_offset += 4;
}
data_offset += popcnt(flags & 12288) * 4;
if (flags & 16) {
sidx = dv.getUint32(data_offset, true);
data_offset += 4;
}
if (flags & 32) {
ieee = dv.getFloat64(data_offset, true);
data_offset += 8;
}
if (flags & 64) {
dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1e3);
data_offset += 8;
}
var ret;
switch (ctype) {
case 0:
break;
case 2:
ret = { t: "n", v: ieee };
break;
case 3:
ret = { t: "s", v: sst[sidx] };
break;
case 5:
ret = { t: "d", v: dt };
break;
case 6:
ret = { t: "b", v: ieee > 0 };
break;
case 7:
ret = { t: "n", v: ieee };
break;
case 8:
ret = { t: "e", v: 0 };
break;
case 9:
{
if (ridx > -1)
ret = { t: "s", v: rsst[ridx] };
else if (sidx > -1)
ret = { t: "s", v: sst[sidx] };
else if (!isNaN(ieee))
ret = { t: "n", v: ieee };
else
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
break;
default:
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
return ret;
}
function parse(buf, sst, rsst) {
var version = buf[0];
switch (version) {
case 3:
case 4:
return parseit(buf, sst, rsst, version);
default:
throw new Error("Unsupported pre-BNC version ".concat(version));
}
}
// src/numbers.ts
var encode_col = function(C) {
var s = "";
for (++C; C; C = Math.floor((C - 1) / 26))
s = String.fromCharCode((C - 1) % 26 + 65) + s;
return s;
};
var encode_cell = function(c) {
return "".concat(encode_col(c.c)).concat(c.r + 1);
};
var encode_range = function(r) {
return encode_cell(r.s) + ":" + encode_cell(r.e);
};
var book_new = function() {
return { Sheets: {}, SheetNames: [] };
};
var book_append_sheet = function(wb, ws, name) {
if (!name)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf(name = "Sheet ".concat(i)) == -1)
break;
}
else if (wb.SheetNames.indexOf(name) > -1)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf("".concat(name, "_").concat(i)) == -1) {
name = "".concat(name, "_").concat(i);
break;
}
}
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
};
function parse_numbers(cfb) {
var out = [];
cfb.FileIndex.forEach(function(s) {
if (!s.name.match(/\.iwa$/))
return;
var o;
try {
o = deframe(s.content);
} catch (e) {
return console.log("?? " + s.content.length + " " + (e.message || e));
}
var packets;
try {
packets = parse_iwa(o);
} catch (e) {
return console.log("## " + (e.message || e));
}
packets.forEach(function(packet) {
out[+packet.id] = packet.messages;
});
});
if (!out.length)
throw new Error("File has no messages");
var docroot;
out.forEach(function(iwams) {
iwams.forEach(function(iwam) {
var mtype = varint_to_i32(iwam.meta[1][0].data) >>> 0;
if (mtype == 1) {
if (!docroot)
docroot = iwam;
else
throw new Error("Document has multiple roots");
}
});
});
if (!docroot)
throw new Error("Cannot find Document root");
return parse_docroot(out, docroot);
}
var numbers_default = parse_numbers;
function parse_Reference(buf) {
var pb = parse_shallow(buf);
return parse_varint49(pb[1][0].data);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries || []).forEach(function(entry) {
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data) >>> 0;
switch (type) {
case 1:
data[key] = u8str(le[3][0].data);
break;
case 8:
{
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if (mtype != 2001)
throw new Error("2000 unexpected reference to ".concat(mtype));
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(function(x) {
return u8str(x.data);
}).join("");
}
break;
}
});
return data;
}
function parse_TST_TileRowInfo(u8) {
var pb = parse_shallow(u8);
var R = varint_to_i32(pb[1][0].data) >>> 0;
var storage = pb[3][0].data;
var offsets = u8_to_dataview(pb[4][0].data);
var cells = [];
for (var C = 0; C < offsets.byteLength / 2; ++C) {
var off = offsets.getUint16(C * 2, true);
if (off > storage.length)
continue;
cells[C] = storage.subarray(off, offsets.getUint16(C * 2 + 2, true));
}
return { R: R, cells: cells };
}
function parse_TST_Tile(M, root) {
var pb = parse_shallow(root.data);
var ri = mappa(pb[5], parse_TST_TileRowInfo);
return ri.reduce(function(acc, x) {
if (!acc[x.R])
acc[x.R] = [];
x.cells.forEach(function(cell, C) {
if (acc[x.R][C])
throw new Error("Duplicate cell r=".concat(x.R, " c=").concat(C));
acc[x.R][C] = cell;
});
return acc;
}, []);
}
function parse_TST_TableModelArchive(M, root, ws) {
var _a;
var pb = parse_shallow(root.data);
var range = { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } };
range.e.r = (varint_to_i32(pb[6][0].data) >>> 0) - 1;
if (range.e.r < 0)
throw new Error("Invalid row varint ".concat(pb[6][0].data));
range.e.c = (varint_to_i32(pb[7][0].data) >>> 0) - 1;
if (range.e.c < 0)
throw new Error("Invalid col varint ".concat(pb[7][0].data));
ws["!ref"] = encode_range(range);
{
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst = ((_a = store[17]) == null ? void 0 : _a[0]) ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
var tile = parse_shallow(store[3][0].data);
var tiles = [];
tile[1].forEach(function(t) {
var tl = parse_shallow(t.data);
var ref = M[parse_Reference(tl[2][0].data)][0];
var mtype = varint_to_i32(ref.meta[1][0].data);
if (mtype != 6002)
throw new Error("6001 unexpected reference to ".concat(mtype));
tiles.push({ id: varint_to_i32(tl[1][0].data), ref: parse_TST_Tile(M, ref) });
});
tiles.forEach(function(tile2) {
tile2.ref.forEach(function(row, R) {
row.forEach(function(buf, C) {
var addr = encode_cell({ r: R, c: C });
var res = parse(buf, sst, rsst);
if (res)
ws[addr] = res;
});
});
});
}
}
}
function parse_TST_TableInfoArchive(M, root) {
var pb = parse_shallow(root.data);
var out = { "!ref": "A1" };
var tableref = M[parse_Reference(pb[2][0].data)];
var mtype = varint_to_i32(tableref[0].meta[1][0].data);
if (mtype != 6001)
throw new Error("6000 unexpected reference to ".concat(mtype));
parse_TST_TableModelArchive(M, tableref[0], out);
return out;
}
function parse_sheetroot(M, root) {
var _a;
var pb = parse_shallow(root.data);
var out = {
name: ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : "",
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
shapeoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 6e3)
out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
}
function parse_docroot(M, root) {
var out = book_new();
var pb = parse_shallow(root.data);
var sheetoffs = mappa(pb[1], parse_Reference);
sheetoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 2) {
var root2 = parse_sheetroot(M, m);
root2.sheets.forEach(function(sheet) {
book_append_sheet(out, sheet, root2.name);
});
}
});
});
if (out.SheetNames.length == 0)
throw new Error("Empty NUMBERS file");
return out;
}
return __toCommonJS(numbers_exports);
})();
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
function fix_opts_func(defaults/*:Array<Array<any> >*/)/*:{(o:any):void}*/ {
return function fix_opts(opts) {
for(var i = 0; i != defaults.length; ++i) {
@ -9796,7 +10352,16 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
/* UOC */
if(safegetzipfile(zip, 'objectdata.xml')) return parse_ods(zip, opts);
/* Numbers */
if(safegetzipfile(zip, 'Index/Document.iwa')) throw new Error('Unsupported NUMBERS file');
if(safegetzipfile(zip, 'Index/Document.iwa')) {
if(typeof Uint8Array == "undefined") throw new Error('NUMBERS file parsing requires Uint8Array support');
if(typeof NUMBERS != "undefined") {
if(zip.FileIndex) return NUMBERS.parse_numbers(zip);
var _zip = CFB.utils.cfb_new();
zipentries(zip).forEach(function(e) { zip_add_file(_zip, e, getzipbin(zip, e)); });
return NUMBERS.parse_numbers(_zip);
}
throw new Error('Unsupported NUMBERS file');
}
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
@ -10245,6 +10810,29 @@ function readFileSync(filename/*:string*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
var o = opts||{}; o.type = 'file';
return readSync(filename, o);
}
function write_obj_str(factory/*:WriteObjStrFactory*/) {
return function write_str(wb/*:Workbook*/, o/*:WriteOpts*/)/*:string*/ {
var idx = 0;
if(o.sheet) {
if(typeof o.sheet == "number") idx = o.sheet;
else idx = wb.SheetNames.indexOf(o.sheet);
if(!wb.SheetNames[idx]) throw new Error("Sheet not found: " + o.sheet + " : " + (typeof o.sheet));
}
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
function write_cfb_ctr(cfb/*:CFBContainer*/, o/*:WriteOpts*/)/*:any*/ {
switch(o.type) {
case "base64": case "binary": break;
@ -10809,5 +11397,3 @@ else if(typeof define === 'function' && define.amd) define('xlsx', function() {
else make_xlsx_lib(XLSX);
/* NOTE: the following extra line is needed for "Lightning Locker Service" */
if(typeof window !== 'undefined' && !window.XLSX) try { window.XLSX = XLSX; } catch(e) {}
/*exported XLS, ODS */
var XLS = XLSX, ODS = XLSX;

View File

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
function make_xlsx_lib(XLSX){
XLSX.version = '0.17.5';
XLSX.version = '0.18.0';
var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
@ -5766,15 +5766,19 @@ function parse_rpr(rpr) {
case '<color':
if(y.rgb) font.color = y.rgb.slice(2,8);
break;
case '<color>': case '<color/>': case '</color>': break;
/* 18.8.18 family ST_FontFamily */
case '<family': font.family = y.val; break;
case '<family>': case '<family/>': case '</family>': break;
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty TODO */
case '<vertAlign': font.valign = y.val; break;
case '<vertAlign>': case '<vertAlign/>': case '</vertAlign>': break;
/* 18.8.35 scheme CT_FontScheme TODO */
case '<scheme': break;
case '<scheme>': case '<scheme/>': case '</scheme>': break;
/* 18.2.10 extLst CT_ExtensionList ? */
case '<extLst': case '<extLst>': case '</extLst>': break;
@ -9572,31 +9576,583 @@ function write_ods(wb, opts) {
return zip;
}
function write_sheet_index(wb, sheet) {
if(!sheet) return 0;
var idx = wb.SheetNames.indexOf(sheet);
if(idx == -1) throw new Error("Sheet not found: " + sheet);
return idx;
}
var NUMBERS = (function() {
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = function(target) {
return __defProp(target, "__esModule", { value: true });
};
var __export = function(target, all) {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = function(target, module, copyDefault, desc) {
if (module && typeof module === "object" || typeof module === "function")
for (var keys = __getOwnPropNames(module), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
__defProp(target, key, { get: function(k) {
return module[k];
}.bind(null, key), enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}
return target;
};
var __toCommonJS = /* @__PURE__ */ function(cache) {
return function(module, temp) {
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
};
}(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
function write_obj_str(factory) {
return function write_str(wb, o) {
var idx = write_sheet_index(wb, o.sheet);
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
// 83_numbers.ts
var numbers_exports = {};
__export(numbers_exports, {
parse_numbers: function() {
return numbers_default;
}
});
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
// src/util.ts
var u8_to_dataview = function(array) {
return new DataView(array.buffer, array.byteOffset, array.byteLength);
};
var u8str = function(u8) {
return typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
};
var u8concat = function(u8a) {
var len = u8a.reduce(function(acc, x) {
return acc + x.length;
}, 0);
var out = new Uint8Array(len);
var off = 0;
u8a.forEach(function(u8) {
out.set(u8, off);
off += u8.length;
});
return out;
};
var popcnt = function(x) {
x -= x >> 1 & 1431655765;
x = (x & 858993459) + (x >> 2 & 858993459);
return (x + (x >> 4) & 252645135) * 16843009 >>> 24;
};
// src/proto.ts
function parse_varint49(buf, ptr) {
var l = ptr ? ptr[0] : 0;
var usz = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
usz |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 28);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 35);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 42);
++l;
if (buf[l++] < 128)
break varint;
}
if (ptr)
ptr[0] = l;
return usz;
}
function varint_to_i32(buf) {
var l = 0, i32 = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
i32 |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 28;
}
return i32;
}
function parse_shallow(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var off = ptr[0];
var num = parse_varint49(buf, ptr);
var type = num & 7;
num = Math.floor(num / 8);
var len = 0;
var res;
if (num == 0)
break;
switch (type) {
case 0:
{
var l = ptr[0];
while (buf[ptr[0]++] >= 128)
;
res = buf.slice(l, ptr[0]);
}
break;
case 5:
len = 4;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 1:
len = 8;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 2:
len = parse_varint49(buf, ptr);
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 3:
case 4:
default:
throw new Error("PB Type ".concat(type, " for Field ").concat(num, " at offset ").concat(off));
}
var v = { offset: off, data: res, type: type };
if (out[num] == null)
out[num] = [v];
else
out[num].push(v);
}
return out;
}
function mappa(data, cb) {
if (!data)
return [];
return data.map(function(d) {
var _a;
try {
return cb(d.data);
} catch (e) {
var m = (_a = e.message) == null ? void 0 : _a.match(/at offset (\d+)/);
if (m)
e.message = e.message.replace(/at offset (\d+)/, "at offset " + (+m[1] + d.offset));
throw e;
}
});
}
// src/frame.ts
function deframe(buf) {
var out = [];
var l = 0;
while (l < buf.length) {
var t = buf[l++];
var len = buf[l] | buf[l + 1] << 8 | buf[l + 2] << 16;
l += 3;
out.push(parse_snappy_chunk(t, buf.slice(l, l + len)));
l += len;
}
if (l !== buf.length)
throw new Error("data is not a valid framed stream!");
return u8concat(out);
}
function parse_snappy_chunk(type, buf) {
if (type != 0)
throw new Error("Unexpected Snappy chunk type ".concat(type));
var ptr = [0];
var usz = parse_varint49(buf, ptr);
var chunks = [];
while (ptr[0] < buf.length) {
var tag = buf[ptr[0]] & 3;
if (tag == 0) {
var len = buf[ptr[0]++] >> 2;
if (len < 60)
++len;
else {
var c = len - 59;
len = buf[ptr[0]];
if (c > 1)
len |= buf[ptr[0] + 1] << 8;
if (c > 2)
len |= buf[ptr[0] + 2] << 16;
if (c > 3)
len |= buf[ptr[0] + 3] << 24;
len >>>= 0;
len++;
ptr[0] += c;
}
chunks.push(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
continue;
} else {
var offset = 0, length = 0;
if (tag == 1) {
length = (buf[ptr[0]] >> 2 & 7) + 4;
offset = (buf[ptr[0]++] & 224) << 3;
offset |= buf[ptr[0]++];
} else {
length = (buf[ptr[0]++] >> 2) + 1;
if (tag == 2) {
offset = buf[ptr[0]] | buf[ptr[0] + 1] << 8;
ptr[0] += 2;
} else {
offset = (buf[ptr[0]] | buf[ptr[0] + 1] << 8 | buf[ptr[0] + 2] << 16 | buf[ptr[0] + 3] << 24) >>> 0;
ptr[0] += 4;
}
}
chunks = [u8concat(chunks)];
if (offset == 0)
throw new Error("Invalid offset 0");
if (offset > chunks[0].length)
throw new Error("Invalid offset beyond length");
if (length >= offset) {
chunks.push(chunks[0].slice(-offset));
length -= offset;
while (length >= chunks[chunks.length - 1].length) {
chunks.push(chunks[chunks.length - 1]);
length -= chunks[chunks.length - 1].length;
}
}
chunks.push(chunks[0].slice(-offset, -offset + length));
}
}
var o = u8concat(chunks);
if (o.length != usz)
throw new Error("Unexpected length: ".concat(o.length, " != ").concat(usz));
return o;
}
// src/iwa.ts
function parse_iwa(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var len = parse_varint49(buf, ptr);
var ai = parse_shallow(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
var res = {
id: varint_to_i32(ai[1][0].data),
messages: []
};
ai[2].forEach(function(b) {
var mi = parse_shallow(b.data);
var fl = varint_to_i32(mi[3][0].data);
res.messages.push({
meta: mi,
data: buf.slice(ptr[0], ptr[0] + fl)
});
ptr[0] += fl;
});
out.push(res);
}
return out;
}
// src/prebnccell.ts
function parseit(buf, sst, rsst, version) {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 3470) * 4;
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if (flags & 512) {
ridx = dv.getUint32(data_offset, true);
data_offset += 4;
}
data_offset += popcnt(flags & 12288) * 4;
if (flags & 16) {
sidx = dv.getUint32(data_offset, true);
data_offset += 4;
}
if (flags & 32) {
ieee = dv.getFloat64(data_offset, true);
data_offset += 8;
}
if (flags & 64) {
dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1e3);
data_offset += 8;
}
var ret;
switch (ctype) {
case 0:
break;
case 2:
ret = { t: "n", v: ieee };
break;
case 3:
ret = { t: "s", v: sst[sidx] };
break;
case 5:
ret = { t: "d", v: dt };
break;
case 6:
ret = { t: "b", v: ieee > 0 };
break;
case 7:
ret = { t: "n", v: ieee };
break;
case 8:
ret = { t: "e", v: 0 };
break;
case 9:
{
if (ridx > -1)
ret = { t: "s", v: rsst[ridx] };
else if (sidx > -1)
ret = { t: "s", v: sst[sidx] };
else if (!isNaN(ieee))
ret = { t: "n", v: ieee };
else
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
break;
default:
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
return ret;
}
function parse(buf, sst, rsst) {
var version = buf[0];
switch (version) {
case 3:
case 4:
return parseit(buf, sst, rsst, version);
default:
throw new Error("Unsupported pre-BNC version ".concat(version));
}
}
// src/numbers.ts
var encode_col = function(C) {
var s = "";
for (++C; C; C = Math.floor((C - 1) / 26))
s = String.fromCharCode((C - 1) % 26 + 65) + s;
return s;
};
var encode_cell = function(c) {
return "".concat(encode_col(c.c)).concat(c.r + 1);
};
var encode_range = function(r) {
return encode_cell(r.s) + ":" + encode_cell(r.e);
};
var book_new = function() {
return { Sheets: {}, SheetNames: [] };
};
var book_append_sheet = function(wb, ws, name) {
if (!name)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf(name = "Sheet ".concat(i)) == -1)
break;
}
else if (wb.SheetNames.indexOf(name) > -1)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf("".concat(name, "_").concat(i)) == -1) {
name = "".concat(name, "_").concat(i);
break;
}
}
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
};
function parse_numbers(cfb) {
var out = [];
cfb.FileIndex.forEach(function(s) {
if (!s.name.match(/\.iwa$/))
return;
var o;
try {
o = deframe(s.content);
} catch (e) {
return console.log("?? " + s.content.length + " " + (e.message || e));
}
var packets;
try {
packets = parse_iwa(o);
} catch (e) {
return console.log("## " + (e.message || e));
}
packets.forEach(function(packet) {
out[+packet.id] = packet.messages;
});
});
if (!out.length)
throw new Error("File has no messages");
var docroot;
out.forEach(function(iwams) {
iwams.forEach(function(iwam) {
var mtype = varint_to_i32(iwam.meta[1][0].data) >>> 0;
if (mtype == 1) {
if (!docroot)
docroot = iwam;
else
throw new Error("Document has multiple roots");
}
});
});
if (!docroot)
throw new Error("Cannot find Document root");
return parse_docroot(out, docroot);
}
var numbers_default = parse_numbers;
function parse_Reference(buf) {
var pb = parse_shallow(buf);
return parse_varint49(pb[1][0].data);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries || []).forEach(function(entry) {
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data) >>> 0;
switch (type) {
case 1:
data[key] = u8str(le[3][0].data);
break;
case 8:
{
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if (mtype != 2001)
throw new Error("2000 unexpected reference to ".concat(mtype));
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(function(x) {
return u8str(x.data);
}).join("");
}
break;
}
});
return data;
}
function parse_TST_TileRowInfo(u8) {
var pb = parse_shallow(u8);
var R = varint_to_i32(pb[1][0].data) >>> 0;
var storage = pb[3][0].data;
var offsets = u8_to_dataview(pb[4][0].data);
var cells = [];
for (var C = 0; C < offsets.byteLength / 2; ++C) {
var off = offsets.getUint16(C * 2, true);
if (off > storage.length)
continue;
cells[C] = storage.subarray(off, offsets.getUint16(C * 2 + 2, true));
}
return { R: R, cells: cells };
}
function parse_TST_Tile(M, root) {
var pb = parse_shallow(root.data);
var ri = mappa(pb[5], parse_TST_TileRowInfo);
return ri.reduce(function(acc, x) {
if (!acc[x.R])
acc[x.R] = [];
x.cells.forEach(function(cell, C) {
if (acc[x.R][C])
throw new Error("Duplicate cell r=".concat(x.R, " c=").concat(C));
acc[x.R][C] = cell;
});
return acc;
}, []);
}
function parse_TST_TableModelArchive(M, root, ws) {
var _a;
var pb = parse_shallow(root.data);
var range = { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } };
range.e.r = (varint_to_i32(pb[6][0].data) >>> 0) - 1;
if (range.e.r < 0)
throw new Error("Invalid row varint ".concat(pb[6][0].data));
range.e.c = (varint_to_i32(pb[7][0].data) >>> 0) - 1;
if (range.e.c < 0)
throw new Error("Invalid col varint ".concat(pb[7][0].data));
ws["!ref"] = encode_range(range);
{
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst = ((_a = store[17]) == null ? void 0 : _a[0]) ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
var tile = parse_shallow(store[3][0].data);
var tiles = [];
tile[1].forEach(function(t) {
var tl = parse_shallow(t.data);
var ref = M[parse_Reference(tl[2][0].data)][0];
var mtype = varint_to_i32(ref.meta[1][0].data);
if (mtype != 6002)
throw new Error("6001 unexpected reference to ".concat(mtype));
tiles.push({ id: varint_to_i32(tl[1][0].data), ref: parse_TST_Tile(M, ref) });
});
tiles.forEach(function(tile2) {
tile2.ref.forEach(function(row, R) {
row.forEach(function(buf, C) {
var addr = encode_cell({ r: R, c: C });
var res = parse(buf, sst, rsst);
if (res)
ws[addr] = res;
});
});
});
}
}
}
function parse_TST_TableInfoArchive(M, root) {
var pb = parse_shallow(root.data);
var out = { "!ref": "A1" };
var tableref = M[parse_Reference(pb[2][0].data)];
var mtype = varint_to_i32(tableref[0].meta[1][0].data);
if (mtype != 6001)
throw new Error("6000 unexpected reference to ".concat(mtype));
parse_TST_TableModelArchive(M, tableref[0], out);
return out;
}
function parse_sheetroot(M, root) {
var _a;
var pb = parse_shallow(root.data);
var out = {
name: ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : "",
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
shapeoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 6e3)
out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
}
function parse_docroot(M, root) {
var out = book_new();
var pb = parse_shallow(root.data);
var sheetoffs = mappa(pb[1], parse_Reference);
sheetoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 2) {
var root2 = parse_sheetroot(M, m);
root2.sheets.forEach(function(sheet) {
book_append_sheet(out, sheet, root2.name);
});
}
});
});
if (out.SheetNames.length == 0)
throw new Error("Empty NUMBERS file");
return out;
}
return __toCommonJS(numbers_exports);
})();
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
function fix_opts_func(defaults) {
return function fix_opts(opts) {
for(var i = 0; i != defaults.length; ++i) {
@ -9703,7 +10259,16 @@ function parse_zip(zip, opts) {
/* UOC */
if(safegetzipfile(zip, 'objectdata.xml')) return parse_ods(zip, opts);
/* Numbers */
if(safegetzipfile(zip, 'Index/Document.iwa')) throw new Error('Unsupported NUMBERS file');
if(safegetzipfile(zip, 'Index/Document.iwa')) {
if(typeof Uint8Array == "undefined") throw new Error('NUMBERS file parsing requires Uint8Array support');
if(typeof NUMBERS != "undefined") {
if(zip.FileIndex) return NUMBERS.parse_numbers(zip);
var _zip = CFB.utils.cfb_new();
zipentries(zip).forEach(function(e) { zip_add_file(_zip, e, getzipbin(zip, e)); });
return NUMBERS.parse_numbers(_zip);
}
throw new Error('Unsupported NUMBERS file');
}
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
@ -10149,6 +10714,29 @@ function readFileSync(filename, opts) {
var o = opts||{}; o.type = 'file';
return readSync(filename, o);
}
function write_obj_str(factory) {
return function write_str(wb, o) {
var idx = 0;
if(o.sheet) {
if(typeof o.sheet == "number") idx = o.sheet;
else idx = wb.SheetNames.indexOf(o.sheet);
if(!wb.SheetNames[idx]) throw new Error("Sheet not found: " + o.sheet + " : " + (typeof o.sheet));
}
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
function write_cfb_ctr(cfb, o) {
switch(o.type) {
case "base64": case "binary": break;
@ -10705,5 +11293,3 @@ else if(typeof define === 'function' && define.amd) define('xlsx', function() {
else make_xlsx_lib(XLSX);
/* NOTE: the following extra line is needed for "Lightning Locker Service" */
if(typeof window !== 'undefined' && !window.XLSX) try { window.XLSX = XLSX; } catch(e) {}
/*exported XLS, ODS */
var XLS = XLSX, ODS = XLSX;

642
xlsx.mjs generated
View File

@ -3,7 +3,7 @@
/*exported XLSX */
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
XLSX.version = '0.17.5';
XLSX.version = '0.18.0';
var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
@ -8879,15 +8879,19 @@ function parse_rpr(rpr) {
case '<color':
if(y.rgb) font.color = y.rgb.slice(2,8);
break;
case '<color>': case '<color/>': case '</color>': break;
/* 18.8.18 family ST_FontFamily */
case '<family': font.family = y.val; break;
case '<family>': case '<family/>': case '</family>': break;
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty TODO */
case '<vertAlign': font.valign = y.val; break;
case '<vertAlign>': case '<vertAlign/>': case '</vertAlign>': break;
/* 18.8.35 scheme CT_FontScheme TODO */
case '<scheme': break;
case '<scheme>': case '<scheme/>': case '</scheme>': break;
/* 18.2.10 extLst CT_ExtensionList ? */
case '<extLst': case '<extLst>': case '</extLst>': break;
@ -18549,14 +18553,14 @@ var PSCLSID = {
};
function parse_xls_props(cfb/*:CFBContainer*/, props, o) {
/* [MS-OSHARED] 2.3.3.2.2 Document Summary Information Property Set */
var DSI = CFB.find(cfb, '!DocumentSummaryInformation');
var DSI = CFB.find(cfb, '/!DocumentSummaryInformation');
if(DSI && DSI.size > 0) try {
var DocSummary = parse_PropertySetStream(DSI, DocSummaryPIDDSI, PSCLSID.DSI);
for(var d in DocSummary) props[d] = DocSummary[d];
} catch(e) {if(o.WTF) throw e;/* empty */}
/* [MS-OSHARED] 2.3.3.2.1 Summary Information Property Set*/
var SI = CFB.find(cfb, '!SummaryInformation');
var SI = CFB.find(cfb, '/!SummaryInformation');
if(SI && SI.size > 0) try {
var Summary = parse_PropertySetStream(SI, SummaryPIDSI, PSCLSID.SI);
for(var s in Summary) if(props[s] == null) props[s] = Summary[s];
@ -20358,7 +20362,7 @@ function write_biff_buf(wb/*:Workbook*/, opts/*:WriteOpts*/) {
if(!ws || !ws["!ref"]) continue;
var range = decode_range(ws["!ref"]);
if(range.e.c > 255) { // note: 255 is IV
console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
if(typeof console != "undefined" && console.error) console.error("Worksheet '" + wb.SheetNames[i] + "' extends beyond column IV (255). Data may be lost.");
}
}
@ -21472,31 +21476,583 @@ function write_ods(wb/*:any*/, opts/*:any*/) {
return zip;
}
function write_sheet_index(wb/*:Workbook*/, sheet/*:?string*/)/*:number*/ {
if(!sheet) return 0;
var idx = wb.SheetNames.indexOf(sheet);
if(idx == -1) throw new Error("Sheet not found: " + sheet);
return idx;
}
var NUMBERS = (function() {
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = function(target) {
return __defProp(target, "__esModule", { value: true });
};
var __export = function(target, all) {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = function(target, module, copyDefault, desc) {
if (module && typeof module === "object" || typeof module === "function")
for (var keys = __getOwnPropNames(module), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
__defProp(target, key, { get: function(k) {
return module[k];
}.bind(null, key), enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
}
return target;
};
var __toCommonJS = /* @__PURE__ */ function(cache) {
return function(module, temp) {
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
};
}(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
function write_obj_str(factory/*:WriteObjStrFactory*/) {
return function write_str(wb/*:Workbook*/, o/*:WriteOpts*/)/*:string*/ {
var idx = write_sheet_index(wb, o.sheet);
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
// 83_numbers.ts
var numbers_exports = {};
__export(numbers_exports, {
parse_numbers: function() {
return numbers_default;
}
});
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
// src/util.ts
var u8_to_dataview = function(array) {
return new DataView(array.buffer, array.byteOffset, array.byteLength);
};
var u8str = function(u8) {
return typeof TextDecoder != "undefined" ? new TextDecoder().decode(u8) : utf8read(a2s(u8));
};
var u8concat = function(u8a) {
var len = u8a.reduce(function(acc, x) {
return acc + x.length;
}, 0);
var out = new Uint8Array(len);
var off = 0;
u8a.forEach(function(u8) {
out.set(u8, off);
off += u8.length;
});
return out;
};
var popcnt = function(x) {
x -= x >> 1 & 1431655765;
x = (x & 858993459) + (x >> 2 & 858993459);
return (x + (x >> 4) & 252645135) * 16843009 >>> 24;
};
// src/proto.ts
function parse_varint49(buf, ptr) {
var l = ptr ? ptr[0] : 0;
var usz = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
usz |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
usz |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 28);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 35);
++l;
if (buf[l++] < 128)
break varint;
usz += (buf[l] & 127) * Math.pow(2, 42);
++l;
if (buf[l++] < 128)
break varint;
}
if (ptr)
ptr[0] = l;
return usz;
}
function varint_to_i32(buf) {
var l = 0, i32 = buf[l] & 127;
varint:
if (buf[l++] >= 128) {
i32 |= (buf[l] & 127) << 7;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 14;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 21;
if (buf[l++] < 128)
break varint;
i32 |= (buf[l] & 127) << 28;
}
return i32;
}
function parse_shallow(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var off = ptr[0];
var num = parse_varint49(buf, ptr);
var type = num & 7;
num = Math.floor(num / 8);
var len = 0;
var res;
if (num == 0)
break;
switch (type) {
case 0:
{
var l = ptr[0];
while (buf[ptr[0]++] >= 128)
;
res = buf.slice(l, ptr[0]);
}
break;
case 5:
len = 4;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 1:
len = 8;
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 2:
len = parse_varint49(buf, ptr);
res = buf.slice(ptr[0], ptr[0] + len);
ptr[0] += len;
break;
case 3:
case 4:
default:
throw new Error("PB Type ".concat(type, " for Field ").concat(num, " at offset ").concat(off));
}
var v = { offset: off, data: res, type: type };
if (out[num] == null)
out[num] = [v];
else
out[num].push(v);
}
return out;
}
function mappa(data, cb) {
if (!data)
return [];
return data.map(function(d) {
var _a;
try {
return cb(d.data);
} catch (e) {
var m = (_a = e.message) == null ? void 0 : _a.match(/at offset (\d+)/);
if (m)
e.message = e.message.replace(/at offset (\d+)/, "at offset " + (+m[1] + d.offset));
throw e;
}
});
}
// src/frame.ts
function deframe(buf) {
var out = [];
var l = 0;
while (l < buf.length) {
var t = buf[l++];
var len = buf[l] | buf[l + 1] << 8 | buf[l + 2] << 16;
l += 3;
out.push(parse_snappy_chunk(t, buf.slice(l, l + len)));
l += len;
}
if (l !== buf.length)
throw new Error("data is not a valid framed stream!");
return u8concat(out);
}
function parse_snappy_chunk(type, buf) {
if (type != 0)
throw new Error("Unexpected Snappy chunk type ".concat(type));
var ptr = [0];
var usz = parse_varint49(buf, ptr);
var chunks = [];
while (ptr[0] < buf.length) {
var tag = buf[ptr[0]] & 3;
if (tag == 0) {
var len = buf[ptr[0]++] >> 2;
if (len < 60)
++len;
else {
var c = len - 59;
len = buf[ptr[0]];
if (c > 1)
len |= buf[ptr[0] + 1] << 8;
if (c > 2)
len |= buf[ptr[0] + 2] << 16;
if (c > 3)
len |= buf[ptr[0] + 3] << 24;
len >>>= 0;
len++;
ptr[0] += c;
}
chunks.push(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
continue;
} else {
var offset = 0, length = 0;
if (tag == 1) {
length = (buf[ptr[0]] >> 2 & 7) + 4;
offset = (buf[ptr[0]++] & 224) << 3;
offset |= buf[ptr[0]++];
} else {
length = (buf[ptr[0]++] >> 2) + 1;
if (tag == 2) {
offset = buf[ptr[0]] | buf[ptr[0] + 1] << 8;
ptr[0] += 2;
} else {
offset = (buf[ptr[0]] | buf[ptr[0] + 1] << 8 | buf[ptr[0] + 2] << 16 | buf[ptr[0] + 3] << 24) >>> 0;
ptr[0] += 4;
}
}
chunks = [u8concat(chunks)];
if (offset == 0)
throw new Error("Invalid offset 0");
if (offset > chunks[0].length)
throw new Error("Invalid offset beyond length");
if (length >= offset) {
chunks.push(chunks[0].slice(-offset));
length -= offset;
while (length >= chunks[chunks.length - 1].length) {
chunks.push(chunks[chunks.length - 1]);
length -= chunks[chunks.length - 1].length;
}
}
chunks.push(chunks[0].slice(-offset, -offset + length));
}
}
var o = u8concat(chunks);
if (o.length != usz)
throw new Error("Unexpected length: ".concat(o.length, " != ").concat(usz));
return o;
}
// src/iwa.ts
function parse_iwa(buf) {
var out = [], ptr = [0];
while (ptr[0] < buf.length) {
var len = parse_varint49(buf, ptr);
var ai = parse_shallow(buf.slice(ptr[0], ptr[0] + len));
ptr[0] += len;
var res = {
id: varint_to_i32(ai[1][0].data),
messages: []
};
ai[2].forEach(function(b) {
var mi = parse_shallow(b.data);
var fl = varint_to_i32(mi[3][0].data);
res.messages.push({
meta: mi,
data: buf.slice(ptr[0], ptr[0] + fl)
});
ptr[0] += fl;
});
out.push(res);
}
return out;
}
// src/prebnccell.ts
function parseit(buf, sst, rsst, version) {
var dv = u8_to_dataview(buf);
var ctype = buf[version == 4 ? 1 : 2];
var flags = dv.getUint32(4, true);
var data_offset = 12 + popcnt(flags & 3470) * 4;
var ridx = -1, sidx = -1, ieee = NaN, dt = new Date(2001, 0, 1);
if (flags & 512) {
ridx = dv.getUint32(data_offset, true);
data_offset += 4;
}
data_offset += popcnt(flags & 12288) * 4;
if (flags & 16) {
sidx = dv.getUint32(data_offset, true);
data_offset += 4;
}
if (flags & 32) {
ieee = dv.getFloat64(data_offset, true);
data_offset += 8;
}
if (flags & 64) {
dt.setTime(dt.getTime() + dv.getFloat64(data_offset, true) * 1e3);
data_offset += 8;
}
var ret;
switch (ctype) {
case 0:
break;
case 2:
ret = { t: "n", v: ieee };
break;
case 3:
ret = { t: "s", v: sst[sidx] };
break;
case 5:
ret = { t: "d", v: dt };
break;
case 6:
ret = { t: "b", v: ieee > 0 };
break;
case 7:
ret = { t: "n", v: ieee };
break;
case 8:
ret = { t: "e", v: 0 };
break;
case 9:
{
if (ridx > -1)
ret = { t: "s", v: rsst[ridx] };
else if (sidx > -1)
ret = { t: "s", v: sst[sidx] };
else if (!isNaN(ieee))
ret = { t: "n", v: ieee };
else
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
break;
default:
throw new Error("Unsupported cell type ".concat(buf.slice(0, 4)));
}
return ret;
}
function parse(buf, sst, rsst) {
var version = buf[0];
switch (version) {
case 3:
case 4:
return parseit(buf, sst, rsst, version);
default:
throw new Error("Unsupported pre-BNC version ".concat(version));
}
}
// src/numbers.ts
var encode_col = function(C) {
var s = "";
for (++C; C; C = Math.floor((C - 1) / 26))
s = String.fromCharCode((C - 1) % 26 + 65) + s;
return s;
};
var encode_cell = function(c) {
return "".concat(encode_col(c.c)).concat(c.r + 1);
};
var encode_range = function(r) {
return encode_cell(r.s) + ":" + encode_cell(r.e);
};
var book_new = function() {
return { Sheets: {}, SheetNames: [] };
};
var book_append_sheet = function(wb, ws, name) {
if (!name)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf(name = "Sheet ".concat(i)) == -1)
break;
}
else if (wb.SheetNames.indexOf(name) > -1)
for (var i = 1; i < 9999; ++i) {
if (wb.SheetNames.indexOf("".concat(name, "_").concat(i)) == -1) {
name = "".concat(name, "_").concat(i);
break;
}
}
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
};
function parse_numbers(cfb) {
var out = [];
cfb.FileIndex.forEach(function(s) {
if (!s.name.match(/\.iwa$/))
return;
var o;
try {
o = deframe(s.content);
} catch (e) {
return console.log("?? " + s.content.length + " " + (e.message || e));
}
var packets;
try {
packets = parse_iwa(o);
} catch (e) {
return console.log("## " + (e.message || e));
}
packets.forEach(function(packet) {
out[+packet.id] = packet.messages;
});
});
if (!out.length)
throw new Error("File has no messages");
var docroot;
out.forEach(function(iwams) {
iwams.forEach(function(iwam) {
var mtype = varint_to_i32(iwam.meta[1][0].data) >>> 0;
if (mtype == 1) {
if (!docroot)
docroot = iwam;
else
throw new Error("Document has multiple roots");
}
});
});
if (!docroot)
throw new Error("Cannot find Document root");
return parse_docroot(out, docroot);
}
var numbers_default = parse_numbers;
function parse_Reference(buf) {
var pb = parse_shallow(buf);
return parse_varint49(pb[1][0].data);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
var type = varint_to_i32(pb[1][0].data);
var entries = pb[3];
var data = [];
(entries || []).forEach(function(entry) {
var le = parse_shallow(entry.data);
var key = varint_to_i32(le[1][0].data) >>> 0;
switch (type) {
case 1:
data[key] = u8str(le[3][0].data);
break;
case 8:
{
var rt = M[parse_Reference(le[9][0].data)][0];
var rtp = parse_shallow(rt.data);
var rtpref = M[parse_Reference(rtp[1][0].data)][0];
var mtype = varint_to_i32(rtpref.meta[1][0].data);
if (mtype != 2001)
throw new Error("2000 unexpected reference to ".concat(mtype));
var tswpsa = parse_shallow(rtpref.data);
data[key] = tswpsa[3].map(function(x) {
return u8str(x.data);
}).join("");
}
break;
}
});
return data;
}
function parse_TST_TileRowInfo(u8) {
var pb = parse_shallow(u8);
var R = varint_to_i32(pb[1][0].data) >>> 0;
var storage = pb[3][0].data;
var offsets = u8_to_dataview(pb[4][0].data);
var cells = [];
for (var C = 0; C < offsets.byteLength / 2; ++C) {
var off = offsets.getUint16(C * 2, true);
if (off > storage.length)
continue;
cells[C] = storage.subarray(off, offsets.getUint16(C * 2 + 2, true));
}
return { R: R, cells: cells };
}
function parse_TST_Tile(M, root) {
var pb = parse_shallow(root.data);
var ri = mappa(pb[5], parse_TST_TileRowInfo);
return ri.reduce(function(acc, x) {
if (!acc[x.R])
acc[x.R] = [];
x.cells.forEach(function(cell, C) {
if (acc[x.R][C])
throw new Error("Duplicate cell r=".concat(x.R, " c=").concat(C));
acc[x.R][C] = cell;
});
return acc;
}, []);
}
function parse_TST_TableModelArchive(M, root, ws) {
var _a;
var pb = parse_shallow(root.data);
var range = { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } };
range.e.r = (varint_to_i32(pb[6][0].data) >>> 0) - 1;
if (range.e.r < 0)
throw new Error("Invalid row varint ".concat(pb[6][0].data));
range.e.c = (varint_to_i32(pb[7][0].data) >>> 0) - 1;
if (range.e.c < 0)
throw new Error("Invalid col varint ".concat(pb[7][0].data));
ws["!ref"] = encode_range(range);
{
var store = parse_shallow(pb[4][0].data);
var sst = parse_TST_TableDataList(M, M[parse_Reference(store[4][0].data)][0]);
var rsst = ((_a = store[17]) == null ? void 0 : _a[0]) ? parse_TST_TableDataList(M, M[parse_Reference(store[17][0].data)][0]) : [];
{
var tile = parse_shallow(store[3][0].data);
var tiles = [];
tile[1].forEach(function(t) {
var tl = parse_shallow(t.data);
var ref = M[parse_Reference(tl[2][0].data)][0];
var mtype = varint_to_i32(ref.meta[1][0].data);
if (mtype != 6002)
throw new Error("6001 unexpected reference to ".concat(mtype));
tiles.push({ id: varint_to_i32(tl[1][0].data), ref: parse_TST_Tile(M, ref) });
});
tiles.forEach(function(tile2) {
tile2.ref.forEach(function(row, R) {
row.forEach(function(buf, C) {
var addr = encode_cell({ r: R, c: C });
var res = parse(buf, sst, rsst);
if (res)
ws[addr] = res;
});
});
});
}
}
}
function parse_TST_TableInfoArchive(M, root) {
var pb = parse_shallow(root.data);
var out = { "!ref": "A1" };
var tableref = M[parse_Reference(pb[2][0].data)];
var mtype = varint_to_i32(tableref[0].meta[1][0].data);
if (mtype != 6001)
throw new Error("6000 unexpected reference to ".concat(mtype));
parse_TST_TableModelArchive(M, tableref[0], out);
return out;
}
function parse_sheetroot(M, root) {
var _a;
var pb = parse_shallow(root.data);
var out = {
name: ((_a = pb[1]) == null ? void 0 : _a[0]) ? u8str(pb[1][0].data) : "",
sheets: []
};
var shapeoffs = mappa(pb[2], parse_Reference);
shapeoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 6e3)
out.sheets.push(parse_TST_TableInfoArchive(M, m));
});
});
return out;
}
function parse_docroot(M, root) {
var out = book_new();
var pb = parse_shallow(root.data);
var sheetoffs = mappa(pb[1], parse_Reference);
sheetoffs.forEach(function(off) {
M[off].forEach(function(m) {
var mtype = varint_to_i32(m.meta[1][0].data);
if (mtype == 2) {
var root2 = parse_sheetroot(M, m);
root2.sheets.forEach(function(sheet) {
book_append_sheet(out, sheet, root2.name);
});
}
});
});
if (out.SheetNames.length == 0)
throw new Error("Empty NUMBERS file");
return out;
}
return __toCommonJS(numbers_exports);
})();
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
function fix_opts_func(defaults/*:Array<Array<any> >*/)/*:{(o:any):void}*/ {
return function fix_opts(opts) {
for(var i = 0; i != defaults.length; ++i) {
@ -21603,7 +22159,16 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
/* UOC */
if(safegetzipfile(zip, 'objectdata.xml')) return parse_ods(zip, opts);
/* Numbers */
if(safegetzipfile(zip, 'Index/Document.iwa')) throw new Error('Unsupported NUMBERS file');
if(safegetzipfile(zip, 'Index/Document.iwa')) {
if(typeof Uint8Array == "undefined") throw new Error('NUMBERS file parsing requires Uint8Array support');
if(typeof NUMBERS != "undefined") {
if(zip.FileIndex) return NUMBERS.parse_numbers(zip);
var _zip = CFB.utils.cfb_new();
zipentries(zip).forEach(function(e) { zip_add_file(_zip, e, getzipbin(zip, e)); });
return NUMBERS.parse_numbers(_zip);
}
throw new Error('Unsupported NUMBERS file');
}
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
@ -22052,6 +22617,29 @@ function readFileSync(filename/*:string*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
var o = opts||{}; o.type = 'file';
return readSync(filename, o);
}
function write_obj_str(factory/*:WriteObjStrFactory*/) {
return function write_str(wb/*:Workbook*/, o/*:WriteOpts*/)/*:string*/ {
var idx = 0;
if(o.sheet) {
if(typeof o.sheet == "number") idx = o.sheet;
else idx = wb.SheetNames.indexOf(o.sheet);
if(!wb.SheetNames[idx]) throw new Error("Sheet not found: " + o.sheet + " : " + (typeof o.sheet));
}
return factory.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb);
};
}
var write_htm_str = write_obj_str(HTML_);
var write_csv_str = write_obj_str({from_sheet:sheet_to_csv});
var write_slk_str = write_obj_str(typeof SYLK !== "undefined" ? SYLK : {});
var write_dif_str = write_obj_str(typeof DIF !== "undefined" ? DIF : {});
var write_prn_str = write_obj_str(typeof PRN !== "undefined" ? PRN : {});
var write_rtf_str = write_obj_str(typeof RTF !== "undefined" ? RTF : {});
var write_txt_str = write_obj_str({from_sheet:sheet_to_txt});
var write_dbf_buf = write_obj_str(typeof DBF !== "undefined" ? DBF : {});
var write_eth_str = write_obj_str(typeof ETH !== "undefined" ? ETH : {});
var write_wk1_buf = write_obj_str(typeof WK_ !== "undefined" ? {from_sheet:WK_.sheet_to_wk1} : {});
function write_cfb_ctr(cfb/*:CFBContainer*/, o/*:WriteOpts*/)/*:any*/ {
switch(o.type) {
case "base64": case "binary": break;