1
forked from sheetjs/sheetjs

NUMBERS write merges [ci skip]

This commit is contained in:
reviewher 2022-03-24 17:12:55 -07:00
parent 0400a87e62
commit d5b54855ec
4 changed files with 407 additions and 239 deletions

@ -187,6 +187,8 @@ function parse_shallow(buf) {
function write_shallow(proto) {
var out = [];
proto.forEach(function(field, idx) {
if (idx == 0)
return;
field.forEach(function(item) {
if (!item.data)
return;
@ -232,9 +234,11 @@ function parse_iwa_file(buf) {
function write_iwa_file(ias) {
var bufs = [];
ias.forEach(function(ia) {
var ai = [];
ai[1] = [{ data: write_varint49(ia.id), type: 0 }];
ai[2] = [];
var ai = [
[],
[{ data: write_varint49(ia.id), type: 0 }],
[]
];
if (ia.merge != null)
ai[3] = [{ data: write_varint49(+!!ia.merge), type: 0 }];
var midata = [];
@ -569,9 +573,10 @@ function parse_TSP_Reference(buf) {
return parse_varint49(pb[1][0].data);
}
function write_TSP_Reference(idx) {
var out = [];
out[1] = [{ type: 0, data: write_varint49(idx) }];
return write_shallow(out);
return write_shallow([
[],
[{ type: 0, data: write_varint49(idx) }]
]);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
@ -832,6 +837,12 @@ function write_tile_row(tri, data, SST) {
tri[3][0].data = u8concat(_cell_storage);
return cnt;
}
function write_iwam(type, payload) {
return {
meta: [[], [{ type: 0, data: write_varint49(type) }]],
data: payload
};
}
function write_numbers_iwa(wb, opts) {
if (!opts || !opts.numbers)
throw new Error("Must pass a `numbers` option -- check the README");
@ -905,10 +916,12 @@ function write_numbers_iwa(wb, opts) {
});
});
});
function get_unique_msgid() {
function get_unique_msgid(dep) {
for (var i = 927262; i < 2e6; ++i)
if (!dependents[i])
if (!dependents[i]) {
dependents[i] = dep;
return i;
}
throw new Error("Too many messages");
}
var entry = CFB.find(cfb, dependents[1].location);
@ -961,18 +974,22 @@ function write_numbers_iwa(wb, opts) {
cruids[1] = [];
cruids[2] = [], cruids[3] = [];
for (var C = 0; C <= range.e.c; ++C) {
var uuid = [];
uuid[1] = uuid[2] = [{ type: 0, data: write_varint49(C + 420690) }];
cruids[1].push({ type: 2, data: write_shallow(uuid) });
cruids[1].push({ type: 2, data: write_shallow([
[],
[{ type: 0, data: write_varint49(C + 420690) }],
[{ type: 0, data: write_varint49(C + 420690) }]
]) });
cruids[2].push({ type: 0, data: write_varint49(C) });
cruids[3].push({ type: 0, data: write_varint49(C) });
}
cruids[4] = [];
cruids[5] = [], cruids[6] = [];
for (var R = 0; R <= range.e.r; ++R) {
uuid = [];
uuid[1] = uuid[2] = [{ type: 0, data: write_varint49(R + 726270) }];
cruids[4].push({ type: 2, data: write_shallow(uuid) });
cruids[4].push({ type: 2, data: write_shallow([
[],
[{ type: 0, data: write_varint49(R + 726270) }],
[{ type: 0, data: write_varint49(R + 726270) }]
]) });
cruids[5].push({ type: 0, data: write_varint49(R) });
cruids[6].push({ type: 0, data: write_varint49(R) });
}
@ -1019,6 +1036,32 @@ function write_numbers_iwa(wb, opts) {
}
oldbucket.content = compress_iwa_file(write_iwa_file(_x));
oldbucket.size = oldbucket.content.length;
if (ws["!merges"]) {
var mergeid = get_unique_msgid({
type: 6144,
deps: [sheetrootref],
location: dependents[sheetrootref].location
});
var mergedata = [[], []];
ws["!merges"].forEach(function(m) {
mergedata[1].push({ type: 2, data: write_shallow([
[],
[{ type: 2, data: write_shallow([
[],
[{ type: 5, data: new Uint8Array(new Uint16Array([m.s.r, m.s.c]).buffer) }]
]) }],
[{ type: 2, data: write_shallow([
[],
[{ type: 5, data: new Uint8Array(new Uint16Array([m.e.r - m.s.r + 1, m.e.c - m.s.c + 1]).buffer) }]
]) }]
]) });
});
store[13] = [{ type: 2, data: write_TSP_Reference(mergeid) }];
x.push({
id: mergeid,
messages: [write_iwam(6144, write_shallow(mergedata))]
});
}
var sstref = parse_TSP_Reference(store[4][0].data);
(function() {
var sentry = CFB.find(cfb, dependents[sstref].location);
@ -1032,12 +1075,13 @@ function write_numbers_iwa(wb, opts) {
var sstdata = parse_shallow(sstroot.messages[0].data);
{
sstdata[3] = [];
var newsst = [];
SST.forEach(function(str, i) {
newsst[1] = [{ type: 0, data: write_varint49(i) }];
newsst[2] = [{ type: 0, data: write_varint49(1) }];
newsst[3] = [{ type: 2, data: stru8(str) }];
sstdata[3].push({ type: 2, data: write_shallow(newsst) });
sstdata[3].push({ type: 2, data: write_shallow([
[],
[{ type: 0, data: write_varint49(i) }],
[{ type: 0, data: write_varint49(1) }],
[{ type: 2, data: stru8(str) }]
]) });
});
}
sstroot.messages[0].data = write_shallow(sstdata);

@ -187,6 +187,8 @@ function parse_shallow(buf) {
function write_shallow(proto) {
var out = [];
proto.forEach(function(field, idx) {
if (idx == 0)
return;
field.forEach(function(item) {
if (!item.data)
return;
@ -232,9 +234,11 @@ function parse_iwa_file(buf) {
function write_iwa_file(ias) {
var bufs = [];
ias.forEach(function(ia) {
var ai = [];
ai[1] = [{ data: write_varint49(ia.id), type: 0 }];
ai[2] = [];
var ai = [
[],
[{ data: write_varint49(ia.id), type: 0 }],
[]
];
if (ia.merge != null)
ai[3] = [{ data: write_varint49(+!!ia.merge), type: 0 }];
var midata = [];
@ -569,9 +573,10 @@ function parse_TSP_Reference(buf) {
return parse_varint49(pb[1][0].data);
}
function write_TSP_Reference(idx) {
var out = [];
out[1] = [{ type: 0, data: write_varint49(idx) }];
return write_shallow(out);
return write_shallow([
[],
[{ type: 0, data: write_varint49(idx) }]
]);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
@ -832,6 +837,12 @@ function write_tile_row(tri, data, SST) {
tri[3][0].data = u8concat(_cell_storage);
return cnt;
}
function write_iwam(type, payload) {
return {
meta: [[], [{ type: 0, data: write_varint49(type) }]],
data: payload
};
}
function write_numbers_iwa(wb, opts) {
if (!opts || !opts.numbers)
throw new Error("Must pass a `numbers` option -- check the README");
@ -905,10 +916,12 @@ function write_numbers_iwa(wb, opts) {
});
});
});
function get_unique_msgid() {
function get_unique_msgid(dep) {
for (var i = 927262; i < 2e6; ++i)
if (!dependents[i])
if (!dependents[i]) {
dependents[i] = dep;
return i;
}
throw new Error("Too many messages");
}
var entry = CFB.find(cfb, dependents[1].location);
@ -961,18 +974,22 @@ function write_numbers_iwa(wb, opts) {
cruids[1] = [];
cruids[2] = [], cruids[3] = [];
for (var C = 0; C <= range.e.c; ++C) {
var uuid = [];
uuid[1] = uuid[2] = [{ type: 0, data: write_varint49(C + 420690) }];
cruids[1].push({ type: 2, data: write_shallow(uuid) });
cruids[1].push({ type: 2, data: write_shallow([
[],
[{ type: 0, data: write_varint49(C + 420690) }],
[{ type: 0, data: write_varint49(C + 420690) }]
]) });
cruids[2].push({ type: 0, data: write_varint49(C) });
cruids[3].push({ type: 0, data: write_varint49(C) });
}
cruids[4] = [];
cruids[5] = [], cruids[6] = [];
for (var R = 0; R <= range.e.r; ++R) {
uuid = [];
uuid[1] = uuid[2] = [{ type: 0, data: write_varint49(R + 726270) }];
cruids[4].push({ type: 2, data: write_shallow(uuid) });
cruids[4].push({ type: 2, data: write_shallow([
[],
[{ type: 0, data: write_varint49(R + 726270) }],
[{ type: 0, data: write_varint49(R + 726270) }]
]) });
cruids[5].push({ type: 0, data: write_varint49(R) });
cruids[6].push({ type: 0, data: write_varint49(R) });
}
@ -1019,6 +1036,32 @@ function write_numbers_iwa(wb, opts) {
}
oldbucket.content = compress_iwa_file(write_iwa_file(_x));
oldbucket.size = oldbucket.content.length;
if (ws["!merges"]) {
var mergeid = get_unique_msgid({
type: 6144,
deps: [sheetrootref],
location: dependents[sheetrootref].location
});
var mergedata = [[], []];
ws["!merges"].forEach(function(m) {
mergedata[1].push({ type: 2, data: write_shallow([
[],
[{ type: 2, data: write_shallow([
[],
[{ type: 5, data: new Uint8Array(new Uint16Array([m.s.r, m.s.c]).buffer) }]
]) }],
[{ type: 2, data: write_shallow([
[],
[{ type: 5, data: new Uint8Array(new Uint16Array([m.e.r - m.s.r + 1, m.e.c - m.s.c + 1]).buffer) }]
]) }]
]) });
});
store[13] = [{ type: 2, data: write_TSP_Reference(mergeid) }];
x.push({
id: mergeid,
messages: [write_iwam(6144, write_shallow(mergedata))]
});
}
var sstref = parse_TSP_Reference(store[4][0].data);
(function() {
var sentry = CFB.find(cfb, dependents[sstref].location);
@ -1032,12 +1075,13 @@ function write_numbers_iwa(wb, opts) {
var sstdata = parse_shallow(sstroot.messages[0].data);
{
sstdata[3] = [];
var newsst = [];
SST.forEach(function(str, i) {
newsst[1] = [{ type: 0, data: write_varint49(i) }];
newsst[2] = [{ type: 0, data: write_varint49(1) }];
newsst[3] = [{ type: 2, data: stru8(str) }];
sstdata[3].push({ type: 2, data: write_shallow(newsst) });
sstdata[3].push({ type: 2, data: write_shallow([
[],
[{ type: 0, data: write_varint49(i) }],
[{ type: 0, data: write_varint49(1) }],
[{ type: 2, data: stru8(str) }]
]) });
});
}
sstroot.messages[0].data = write_shallow(sstdata);

@ -159,6 +159,7 @@ function parse_shallow(buf: Uint8Array): ProtoMessage {
function write_shallow(proto: ProtoMessage): Uint8Array {
var out: Uint8Array[] = [];
proto.forEach((field, idx) => {
if(idx == 0) return;
field.forEach(item => {
if(!item.data) return;
out.push(write_varint49(idx * 8 + item.type));
@ -217,9 +218,10 @@ function parse_iwa_file(buf: Uint8Array): IWAArchiveInfo[] {
function write_iwa_file(ias: IWAArchiveInfo[]): Uint8Array {
var bufs: Uint8Array[] = [];
ias.forEach(ia => {
var ai: ProtoMessage = [];
ai[1] = [{data: write_varint49(ia.id), type: 0}];
ai[2] = [];
var ai: ProtoMessage = [ [],
[ {data: write_varint49(ia.id), type: 0} ],
[]
];
if(ia.merge != null) ai[3] = [ { data: write_varint49(+!!ia.merge), type: 0 } ];
var midata: Uint8Array[] = [];
@ -453,9 +455,10 @@ function parse_TSP_Reference(buf: Uint8Array): number {
return parse_varint49(pb[1][0].data);
}
function write_TSP_Reference(idx: number): Uint8Array {
var out: ProtoMessage = [];
out[1] = [ { type: 0, data: write_varint49(idx) } ];
return write_shallow(out)
return write_shallow([
[],
[ { type: 0, data: write_varint49(idx) } ]
]);
}
//<<export { parse_TSP_Reference, write_TSP_Reference };
@ -729,6 +732,13 @@ function write_tile_row(tri: ProtoMessage, data: any[], SST: string[]): number {
return cnt;
}
function write_iwam(type: number, payload: Uint8Array): IWAMessage {
return {
meta: [ [], [ { type: 0, data: write_varint49(type) } ] ],
data: payload
};
}
function write_numbers_iwa(wb: WorkBook, opts: any): CFB$Container {
if(!opts || !opts.numbers) throw new Error("Must pass a `numbers` option -- check the README");
/* TODO: support multiple worksheets, larger ranges, more data types, etc */
@ -784,8 +794,11 @@ function write_numbers_iwa(wb: WorkBook, opts: any): CFB$Container {
});
});
function get_unique_msgid() {
for(var i = 927262; i < 2000000; ++i) if(!dependents[i]) return i;
function get_unique_msgid(dep: DependentInfo) {
for(var i = 927262; i < 2000000; ++i) if(!dependents[i]) {
dependents[i] = dep;
return i;
}
throw new Error("Too many messages");
}
@ -842,17 +855,19 @@ function write_numbers_iwa(wb: WorkBook, opts: any): CFB$Container {
var cruids = parse_shallow(_x[j].messages[0].data);
cruids[1] = []; cruids[2] = [], cruids[3] = [];
for(var C = 0; C <= range.e.c; ++C) {
var uuid: ProtoMessage = [];
uuid[1] = uuid[2] = [ { type: 0, data: write_varint49(C + 420690) } ]
cruids[1].push({type: 2, data: write_shallow(uuid)})
cruids[1].push({type: 2, data: write_shallow([ [],
[ { type: 0, data: write_varint49(C + 420690) } ],
[ { type: 0, data: write_varint49(C + 420690) } ]
])});
cruids[2].push({type: 0, data: write_varint49(C)});
cruids[3].push({type: 0, data: write_varint49(C)});
}
cruids[4] = []; cruids[5] = [], cruids[6] = [];
for(var R = 0; R <= range.e.r; ++R) {
uuid = [];
uuid[1] = uuid[2] = [ { type: 0, data: write_varint49(R + 726270)} ];
cruids[4].push({type: 2, data: write_shallow(uuid)})
cruids[4].push({type: 2, data: write_shallow([ [],
[ { type: 0, data: write_varint49(R + 726270)} ],
[ { type: 0, data: write_varint49(R + 726270)} ]
])});
cruids[5].push({type: 0, data: write_varint49(R)});
cruids[6].push({type: 0, data: write_varint49(R)});
}
@ -897,6 +912,27 @@ function write_numbers_iwa(wb: WorkBook, opts: any): CFB$Container {
}
oldbucket.content = compress_iwa_file(write_iwa_file(_x)); oldbucket.size = oldbucket.content.length;
if(ws["!merges"]) {
var mergeid = get_unique_msgid({
type: 6144,
deps: [sheetrootref],
location: dependents[sheetrootref].location
});
var mergedata: ProtoMessage = [ [], [] ];
ws["!merges"].forEach(m => { mergedata[1].push({ type: 2, data: write_shallow([ [],
[{ type: 2, data: write_shallow([ [],
[{ type: 5, data: new Uint8Array(new Uint16Array([m.s.r, m.s.c]).buffer) }],
])}],
[{ type: 2, data: write_shallow([ [],
[{ type: 5, data: new Uint8Array(new Uint16Array([m.e.r - m.s.r + 1, m.e.c - m.s.c + 1]).buffer) }],
]) }]
]) }); });
store[13] = [ { type: 2, data: write_TSP_Reference(mergeid) } ];
x.push({
id: mergeid,
messages: [ write_iwam(6144, write_shallow(mergedata)) ]
});
}
/* ref to string table */
var sstref = parse_TSP_Reference(store[4][0].data);
@ -912,12 +948,12 @@ function write_numbers_iwa(wb: WorkBook, opts: any): CFB$Container {
var sstdata = parse_shallow(sstroot.messages[0].data);
{
sstdata[3] = [];
var newsst: ProtoMessage = [];
SST.forEach((str, i) => {
newsst[1] = [ { type: 0, data: write_varint49(i) } ];
newsst[2] = [ { type: 0, data: write_varint49(1) } ];
newsst[3] = [ { type: 2, data: stru8(str) } ];
sstdata[3].push({type: 2, data: write_shallow(newsst)});
sstdata[3].push({type: 2, data: write_shallow([ [],
[ { type: 0, data: write_varint49(i) } ],
[ { type: 0, data: write_varint49(1) } ],
[ { type: 2, data: stru8(str) } ]
])});
});
}
sstroot.messages[0].data = write_shallow(sstdata);

82
xlsx.mjs generated

@ -22180,6 +22180,8 @@ function parse_shallow(buf) {
function write_shallow(proto) {
var out = [];
proto.forEach(function(field, idx) {
if (idx == 0)
return;
field.forEach(function(item) {
if (!item.data)
return;
@ -22225,9 +22227,11 @@ function parse_iwa_file(buf) {
function write_iwa_file(ias) {
var bufs = [];
ias.forEach(function(ia) {
var ai = [];
ai[1] = [{ data: write_varint49(ia.id), type: 0 }];
ai[2] = [];
var ai = [
[],
[{ data: write_varint49(ia.id), type: 0 }],
[]
];
if (ia.merge != null)
ai[3] = [{ data: write_varint49(+!!ia.merge), type: 0 }];
var midata = [];
@ -22562,9 +22566,10 @@ function parse_TSP_Reference(buf) {
return parse_varint49(pb[1][0].data);
}
function write_TSP_Reference(idx) {
var out = [];
out[1] = [{ type: 0, data: write_varint49(idx) }];
return write_shallow(out);
return write_shallow([
[],
[{ type: 0, data: write_varint49(idx) }]
]);
}
function parse_TST_TableDataList(M, root) {
var pb = parse_shallow(root.data);
@ -22825,6 +22830,12 @@ function write_tile_row(tri, data, SST) {
tri[3][0].data = u8concat(_cell_storage);
return cnt;
}
function write_iwam(type, payload) {
return {
meta: [[], [{ type: 0, data: write_varint49(type) }]],
data: payload
};
}
function write_numbers_iwa(wb, opts) {
if (!opts || !opts.numbers)
throw new Error("Must pass a `numbers` option -- check the README");
@ -22898,10 +22909,12 @@ function write_numbers_iwa(wb, opts) {
});
});
});
function get_unique_msgid() {
function get_unique_msgid(dep) {
for (var i = 927262; i < 2e6; ++i)
if (!dependents[i])
if (!dependents[i]) {
dependents[i] = dep;
return i;
}
throw new Error("Too many messages");
}
var entry = CFB.find(cfb, dependents[1].location);
@ -22954,18 +22967,22 @@ function write_numbers_iwa(wb, opts) {
cruids[1] = [];
cruids[2] = [], cruids[3] = [];
for (var C = 0; C <= range.e.c; ++C) {
var uuid = [];
uuid[1] = uuid[2] = [{ type: 0, data: write_varint49(C + 420690) }];
cruids[1].push({ type: 2, data: write_shallow(uuid) });
cruids[1].push({ type: 2, data: write_shallow([
[],
[{ type: 0, data: write_varint49(C + 420690) }],
[{ type: 0, data: write_varint49(C + 420690) }]
]) });
cruids[2].push({ type: 0, data: write_varint49(C) });
cruids[3].push({ type: 0, data: write_varint49(C) });
}
cruids[4] = [];
cruids[5] = [], cruids[6] = [];
for (var R = 0; R <= range.e.r; ++R) {
uuid = [];
uuid[1] = uuid[2] = [{ type: 0, data: write_varint49(R + 726270) }];
cruids[4].push({ type: 2, data: write_shallow(uuid) });
cruids[4].push({ type: 2, data: write_shallow([
[],
[{ type: 0, data: write_varint49(R + 726270) }],
[{ type: 0, data: write_varint49(R + 726270) }]
]) });
cruids[5].push({ type: 0, data: write_varint49(R) });
cruids[6].push({ type: 0, data: write_varint49(R) });
}
@ -23012,6 +23029,32 @@ function write_numbers_iwa(wb, opts) {
}
oldbucket.content = compress_iwa_file(write_iwa_file(_x));
oldbucket.size = oldbucket.content.length;
if (ws["!merges"]) {
var mergeid = get_unique_msgid({
type: 6144,
deps: [sheetrootref],
location: dependents[sheetrootref].location
});
var mergedata = [[], []];
ws["!merges"].forEach(function(m) {
mergedata[1].push({ type: 2, data: write_shallow([
[],
[{ type: 2, data: write_shallow([
[],
[{ type: 5, data: new Uint8Array(new Uint16Array([m.s.r, m.s.c]).buffer) }]
]) }],
[{ type: 2, data: write_shallow([
[],
[{ type: 5, data: new Uint8Array(new Uint16Array([m.e.r - m.s.r + 1, m.e.c - m.s.c + 1]).buffer) }]
]) }]
]) });
});
store[13] = [{ type: 2, data: write_TSP_Reference(mergeid) }];
x.push({
id: mergeid,
messages: [write_iwam(6144, write_shallow(mergedata))]
});
}
var sstref = parse_TSP_Reference(store[4][0].data);
(function() {
var sentry = CFB.find(cfb, dependents[sstref].location);
@ -23025,12 +23068,13 @@ function write_numbers_iwa(wb, opts) {
var sstdata = parse_shallow(sstroot.messages[0].data);
{
sstdata[3] = [];
var newsst = [];
SST.forEach(function(str, i) {
newsst[1] = [{ type: 0, data: write_varint49(i) }];
newsst[2] = [{ type: 0, data: write_varint49(1) }];
newsst[3] = [{ type: 2, data: stru8(str) }];
sstdata[3].push({ type: 2, data: write_shallow(newsst) });
sstdata[3].push({ type: 2, data: write_shallow([
[],
[{ type: 0, data: write_varint49(i) }],
[{ type: 0, data: write_varint49(1) }],
[{ type: 2, data: stru8(str) }]
]) });
});
}
sstroot.messages[0].data = write_shallow(sstdata);