@file-viewer/renderer-spreadsheet 3.3.1 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +14 -0
- package/README.md +14 -0
- package/README.zh-CN.md +14 -0
- package/dist/spreadsheet/autoRowHeight.d.ts +16 -0
- package/dist/spreadsheet/autoRowHeight.js +208 -0
- package/dist/spreadsheet/chartRenderer.js +0 -5
- package/dist/spreadsheet/chartSampling.d.ts +0 -4
- package/dist/spreadsheet/chartSampling.js +0 -6
- package/dist/spreadsheet/comments.d.ts +40 -0
- package/dist/spreadsheet/comments.js +388 -0
- package/dist/spreadsheet/drawingAutoHeight.d.ts +7 -0
- package/dist/spreadsheet/drawingAutoHeight.js +51 -0
- package/dist/spreadsheet/rangeNavigation.d.ts +0 -2
- package/dist/spreadsheet/rangeNavigation.js +0 -4
- package/dist/spreadsheet/sourceRegion.d.ts +37 -0
- package/dist/spreadsheet/sourceRegion.js +54 -0
- package/dist/spreadsheet/state.d.ts +7 -2
- package/dist/spreadsheet/state.js +6 -2
- package/dist/spreadsheet/view.d.ts +9 -4
- package/dist/spreadsheet/view.js +98 -39
- package/dist/spreadsheet/viewport.d.ts +0 -1
- package/dist/spreadsheet/viewport.js +0 -2
- package/dist/spreadsheet/worker/sheetjs/SheetJsModel.d.ts +61 -2
- package/dist/spreadsheet/worker/sheetjs/SheetJsModel.js +134 -43
- package/dist/spreadsheet/worker/sheetjs/chartParser.d.ts +3 -2
- package/dist/spreadsheet/worker/sheetjs/chartParser.js +13 -24
- package/dist/spreadsheet/worker/sheetjs/color.js +8 -10
- package/dist/spreadsheet/worker/sheetjs/commentParser.d.ts +7 -0
- package/dist/spreadsheet/worker/sheetjs/commentParser.js +232 -0
- package/dist/spreadsheet/worker/sheetjs/drawingRowAnchor.d.ts +4 -0
- package/dist/spreadsheet/worker/sheetjs/drawingRowAnchor.js +90 -0
- package/dist/spreadsheet/worker/sheetjs/formulaValues.js +0 -9
- package/dist/spreadsheet/worker/sheetjs/parser.d.ts +40 -4
- package/dist/spreadsheet/worker/sheetjs/parser.js +453 -78
- package/dist/spreadsheet/worker/sheetjs/richDataParser.js +5 -4
- package/dist/spreadsheet/worker/sheetjs/richText.js +0 -1
- package/dist/spreadsheet/worker/sheetjs/rowSizing.d.ts +10 -0
- package/dist/spreadsheet/worker/sheetjs/rowSizing.js +156 -0
- package/dist/spreadsheet/worker/sheetjs/sheetLayout.d.ts +2 -4
- package/dist/spreadsheet/worker/sheetjs/sheetLayout.js +0 -8
- package/dist/spreadsheet/worker/sheetjs/sourceAnchor.d.ts +10 -0
- package/dist/spreadsheet/worker/sheetjs/sourceAnchor.js +286 -0
- package/dist/spreadsheet/worker/sheetjs/textEncoding.d.ts +1 -1
- package/dist/spreadsheet/worker/sheetjs/textEncoding.js +1 -8
- package/dist/spreadsheet/worker/sheetjs/workbookFont.d.ts +4 -0
- package/dist/spreadsheet/worker/sheetjs/workbookFont.js +15 -0
- package/dist/spreadsheet/worker/sheetjs/xmlBudget.d.ts +11 -0
- package/dist/spreadsheet/worker/sheetjs/xmlBudget.js +39 -0
- package/dist/spreadsheet/worker/type.d.ts +145 -3
- package/dist/spreadsheet.js +150 -63
- package/dist/worker/sheet.worker.js +49 -65
- package/package.json +23 -3
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import JSZip from 'jszip';
|
|
2
|
+
import { utils } from 'styled-exceljs';
|
|
3
|
+
import { childElements, elementsByLocal, loadRelationships, loadXml, localName, relationById, relationshipId, } from './chartParser.js';
|
|
4
|
+
const MAX_COMMENT_PART_BYTES = 4 * 1024 * 1024;
|
|
5
|
+
const MAX_COMMENT_XML_BYTES = 16 * 1024 * 1024;
|
|
6
|
+
const decodeText = (value) => value.replace(/_x([0-9a-f]{4})_/gi, (_, code) => String.fromCharCode(Number.parseInt(code, 16)));
|
|
7
|
+
const text = (node) => decodeText((node === null || node === void 0 ? void 0 : node.textContent) || '');
|
|
8
|
+
const direct = (node, name) => childElements(node).filter((item) => localName(item) === name);
|
|
9
|
+
const noteText = (node) => childElements(node)
|
|
10
|
+
.flatMap((child) => {
|
|
11
|
+
if (localName(child) === 't')
|
|
12
|
+
return [text(child)];
|
|
13
|
+
return localName(child) === 'r' ? direct(child, 't').map(text) : [];
|
|
14
|
+
})
|
|
15
|
+
.join('');
|
|
16
|
+
const addressOf = (value) => {
|
|
17
|
+
if (!value || !/^[A-Z]{1,3}[1-9][0-9]{0,6}$/i.test(value))
|
|
18
|
+
return null;
|
|
19
|
+
const cell = utils.decode_cell(value.toUpperCase());
|
|
20
|
+
return cell.r < 1048576 && cell.c < 16384
|
|
21
|
+
? { address: utils.encode_cell(cell), row: cell.r, col: cell.c }
|
|
22
|
+
: null;
|
|
23
|
+
};
|
|
24
|
+
const worksheetCells = (sheet) => {
|
|
25
|
+
const rows = Array.isArray(sheet) ? sheet : sheet === null || sheet === void 0 ? void 0 : sheet['!data'];
|
|
26
|
+
if (Array.isArray(rows)) {
|
|
27
|
+
return rows.flatMap((row, r) => Array.isArray(row)
|
|
28
|
+
? row.map((cell, c) => [
|
|
29
|
+
utils.encode_cell({ r, c }),
|
|
30
|
+
cell,
|
|
31
|
+
])
|
|
32
|
+
: []);
|
|
33
|
+
}
|
|
34
|
+
return Object.entries(sheet || {}).filter(([address]) => addressOf(address));
|
|
35
|
+
};
|
|
36
|
+
const legacyMessages = (cell) => {
|
|
37
|
+
if (!cell ||
|
|
38
|
+
typeof cell !== 'object' ||
|
|
39
|
+
!('c' in cell) ||
|
|
40
|
+
!Array.isArray(cell.c))
|
|
41
|
+
return [];
|
|
42
|
+
return cell.c.flatMap((note) => {
|
|
43
|
+
if (!note ||
|
|
44
|
+
typeof note !== 'object' ||
|
|
45
|
+
!('t' in note) ||
|
|
46
|
+
typeof note.t !== 'string' ||
|
|
47
|
+
('T' in note && note.T))
|
|
48
|
+
return [];
|
|
49
|
+
return [
|
|
50
|
+
{
|
|
51
|
+
id: '',
|
|
52
|
+
parentId: null,
|
|
53
|
+
text: note.t,
|
|
54
|
+
createdAt: null,
|
|
55
|
+
author: 'a' in note && typeof note.a === 'string' ? note.a : '',
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
export const readWorkbookNotes = (workbook) => Object.fromEntries(workbook.SheetNames.map((name) => [
|
|
61
|
+
name,
|
|
62
|
+
worksheetCells(workbook.Sheets[name]).flatMap(([address, cell]) => {
|
|
63
|
+
const location = addressOf(address);
|
|
64
|
+
const messages = legacyMessages(cell);
|
|
65
|
+
return location && messages.length
|
|
66
|
+
? [{ ...location, kind: 'note', resolved: false, messages }]
|
|
67
|
+
: [];
|
|
68
|
+
}),
|
|
69
|
+
]));
|
|
70
|
+
export const parseSpreadsheetComments = async (data, workbook) => {
|
|
71
|
+
const comments = readWorkbookNotes(workbook);
|
|
72
|
+
if (data.byteLength < 2 || new DataView(data).getUint16(0, false) !== 0x504b)
|
|
73
|
+
return { comments, hasError: false };
|
|
74
|
+
const zip = await JSZip.loadAsync(data);
|
|
75
|
+
if (!zip.file('xl/workbook.xml'))
|
|
76
|
+
return { comments, hasError: false };
|
|
77
|
+
let hasError = false;
|
|
78
|
+
const budget = {
|
|
79
|
+
maxPartBytes: MAX_COMMENT_PART_BYTES,
|
|
80
|
+
remainingBytes: MAX_COMMENT_XML_BYTES,
|
|
81
|
+
};
|
|
82
|
+
const cache = new Map();
|
|
83
|
+
const xml = async (path, required = true) => {
|
|
84
|
+
if (cache.has(path))
|
|
85
|
+
return cache.get(path) || null;
|
|
86
|
+
try {
|
|
87
|
+
const part = zip.file(path);
|
|
88
|
+
if (!part) {
|
|
89
|
+
if (required)
|
|
90
|
+
hasError = true;
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const document = await loadXml(zip, path, budget);
|
|
94
|
+
cache.set(path, document);
|
|
95
|
+
return document;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
hasError = true;
|
|
99
|
+
cache.set(path, null);
|
|
100
|
+
console.warn('[file-viewer] Spreadsheet comment part could not be read.', error);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const relationshipsFor = (path) => loadRelationships(zip, path, (part) => xml(part, false));
|
|
105
|
+
const workbookXml = await xml('xl/workbook.xml');
|
|
106
|
+
const relationships = await relationshipsFor('xl/workbook.xml');
|
|
107
|
+
const people = new Map();
|
|
108
|
+
for (const relationship of relationships.filter((item) => item.type.toLowerCase().endsWith('/person'))) {
|
|
109
|
+
const persons = await xml(relationship.target);
|
|
110
|
+
for (const person of elementsByLocal(persons === null || persons === void 0 ? void 0 : persons.documentElement, 'person')) {
|
|
111
|
+
const id = person.getAttribute('id');
|
|
112
|
+
if (id)
|
|
113
|
+
people.set(id, person.getAttribute('displayName') ||
|
|
114
|
+
person.getAttribute('userId') ||
|
|
115
|
+
'');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
for (const sheet of elementsByLocal(workbookXml === null || workbookXml === void 0 ? void 0 : workbookXml.documentElement, 'sheet')) {
|
|
119
|
+
const name = sheet.getAttribute('name');
|
|
120
|
+
const relation = relationById(relationships, relationshipId(sheet));
|
|
121
|
+
if (!name || !relation || !relation.type.endsWith('/worksheet'))
|
|
122
|
+
continue;
|
|
123
|
+
const sheetRelationships = await relationshipsFor(relation.target);
|
|
124
|
+
const cells = new Map((comments[name] || []).map((item) => [item.address, item]));
|
|
125
|
+
for (const part of sheetRelationships.filter((item) => item.type.toLowerCase().endsWith('/comments'))) {
|
|
126
|
+
const document = await xml(part.target);
|
|
127
|
+
const authors = elementsByLocal(document === null || document === void 0 ? void 0 : document.documentElement, 'author').map(text);
|
|
128
|
+
for (const comment of elementsByLocal(document === null || document === void 0 ? void 0 : document.documentElement, 'comment')) {
|
|
129
|
+
const location = addressOf(comment.getAttribute('ref'));
|
|
130
|
+
if (!location) {
|
|
131
|
+
hasError = true;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
cells.set(location.address, {
|
|
135
|
+
...location,
|
|
136
|
+
kind: 'note',
|
|
137
|
+
resolved: false,
|
|
138
|
+
messages: [
|
|
139
|
+
{
|
|
140
|
+
id: '',
|
|
141
|
+
parentId: null,
|
|
142
|
+
author: authors[Number(comment.getAttribute('authorId'))] || '',
|
|
143
|
+
text: noteText(direct(comment, 'text')[0]),
|
|
144
|
+
createdAt: null,
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const messages = [];
|
|
151
|
+
for (const part of sheetRelationships.filter((item) => item.type.toLowerCase().endsWith('/threadedcomment'))) {
|
|
152
|
+
const document = await xml(part.target);
|
|
153
|
+
for (const comment of elementsByLocal(document === null || document === void 0 ? void 0 : document.documentElement, 'threadedComment')) {
|
|
154
|
+
const location = addressOf(comment.getAttribute('ref'));
|
|
155
|
+
if (!location) {
|
|
156
|
+
hasError = true;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const timestamp = comment.getAttribute('dT') || '';
|
|
160
|
+
messages.push({
|
|
161
|
+
...location,
|
|
162
|
+
id: comment.getAttribute('id') || '',
|
|
163
|
+
parentId: comment.getAttribute('parentId') || null,
|
|
164
|
+
author: people.get(comment.getAttribute('personId') || '') || '',
|
|
165
|
+
text: text(direct(comment, 'text')[0]),
|
|
166
|
+
createdAt: timestamp && Number.isFinite(Date.parse(timestamp))
|
|
167
|
+
? timestamp
|
|
168
|
+
: null,
|
|
169
|
+
resolved: ['1', 'true'].includes(comment.getAttribute('done') || ''),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const byId = new Map(messages.filter((item) => item.id).map((item) => [item.id, item]));
|
|
174
|
+
const threads = new Map();
|
|
175
|
+
const roots = new Map();
|
|
176
|
+
for (const message of messages) {
|
|
177
|
+
let root = message;
|
|
178
|
+
const path = [];
|
|
179
|
+
const visited = new Set();
|
|
180
|
+
while (root.parentId) {
|
|
181
|
+
const cached = roots.get(root.id);
|
|
182
|
+
if (cached) {
|
|
183
|
+
root = cached;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
if (visited.has(root.id)) {
|
|
187
|
+
hasError = true;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
visited.add(root.id);
|
|
191
|
+
path.push(root);
|
|
192
|
+
const parent = byId.get(root.parentId);
|
|
193
|
+
if (!parent || parent.address !== message.address) {
|
|
194
|
+
hasError = true;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
root = parent;
|
|
198
|
+
}
|
|
199
|
+
for (const item of path)
|
|
200
|
+
if (item.id)
|
|
201
|
+
roots.set(item.id, root);
|
|
202
|
+
if (root.id)
|
|
203
|
+
roots.set(root.id, root);
|
|
204
|
+
const thread = threads.get(root.address) || {
|
|
205
|
+
address: root.address,
|
|
206
|
+
row: root.row,
|
|
207
|
+
col: root.col,
|
|
208
|
+
kind: 'thread',
|
|
209
|
+
resolved: root.resolved,
|
|
210
|
+
messages: [],
|
|
211
|
+
};
|
|
212
|
+
thread.messages.push({
|
|
213
|
+
id: message.id,
|
|
214
|
+
parentId: message.parentId,
|
|
215
|
+
author: message.author,
|
|
216
|
+
text: message.text,
|
|
217
|
+
createdAt: message.createdAt,
|
|
218
|
+
});
|
|
219
|
+
threads.set(root.address, thread);
|
|
220
|
+
}
|
|
221
|
+
for (const [address, thread] of threads) {
|
|
222
|
+
thread.messages.sort((a, b) => a.parentId === null && b.parentId !== null
|
|
223
|
+
? -1
|
|
224
|
+
: b.parentId === null && a.parentId !== null
|
|
225
|
+
? 1
|
|
226
|
+
: (a.createdAt || '').localeCompare(b.createdAt || ''));
|
|
227
|
+
cells.set(address, thread);
|
|
228
|
+
}
|
|
229
|
+
comments[name] = [...cells.values()].sort((a, b) => a.row - b.row || a.col - b.col);
|
|
230
|
+
}
|
|
231
|
+
return { comments, hasError };
|
|
232
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DrawingImage } from 'styled-exceljs';
|
|
2
|
+
import type { SheetDrawingMarker, SheetRowAnchor } from '../type.js';
|
|
3
|
+
export declare const createDrawingRowAnchor: (type: string, editAs: string | null, from?: SheetDrawingMarker, to?: SheetDrawingMarker) => SheetRowAnchor | undefined;
|
|
4
|
+
export declare const readImageRowAnchors: (raw: unknown, images: DrawingImage[]) => Map<DrawingImage, SheetRowAnchor>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DOMParser } from '@xmldom/xmldom';
|
|
2
|
+
export const createDrawingRowAnchor = (type, editAs, from, to) => {
|
|
3
|
+
if (type === 'absoluteAnchor')
|
|
4
|
+
return { mode: 'absolute', fromRow: 0, fromOffset: 0 };
|
|
5
|
+
if (type !== 'oneCellAnchor' && type !== 'twoCellAnchor')
|
|
6
|
+
return undefined;
|
|
7
|
+
if (!from ||
|
|
8
|
+
!Number.isSafeInteger(from.row) ||
|
|
9
|
+
from.row < 0 ||
|
|
10
|
+
!Number.isFinite(from.rowOff))
|
|
11
|
+
return undefined;
|
|
12
|
+
if (type === 'twoCellAnchor' &&
|
|
13
|
+
editAs &&
|
|
14
|
+
!['absolute', 'oneCell', 'twoCell'].includes(editAs))
|
|
15
|
+
return undefined;
|
|
16
|
+
const mode = type === 'oneCellAnchor' ? 'oneCell' : editAs || 'twoCell';
|
|
17
|
+
if (mode === 'twoCell' &&
|
|
18
|
+
(!to ||
|
|
19
|
+
!Number.isSafeInteger(to.row) ||
|
|
20
|
+
to.row < from.row ||
|
|
21
|
+
!Number.isFinite(to.rowOff)))
|
|
22
|
+
return undefined;
|
|
23
|
+
return {
|
|
24
|
+
mode: mode,
|
|
25
|
+
fromRow: from.row,
|
|
26
|
+
fromOffset: from.rowOff,
|
|
27
|
+
...(to ? { toRow: to.row, toOffset: to.rowOff } : {}),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export const readImageRowAnchors = (raw, images) => {
|
|
31
|
+
const result = new Map();
|
|
32
|
+
if (typeof raw !== 'string' || raw.length > 8 * 1024 * 1024)
|
|
33
|
+
return result;
|
|
34
|
+
let document;
|
|
35
|
+
try {
|
|
36
|
+
document = new DOMParser({ onError: () => { } }).parseFromString(raw, 'application/xml');
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
const local = (node) => { var _a; return node.localName || ((_a = node.nodeName) === null || _a === void 0 ? void 0 : _a.split(':').pop()) || ''; };
|
|
42
|
+
const children = (node) => Array.from((node === null || node === void 0 ? void 0 : node.childNodes) || []).filter((child) => child.nodeType === 1);
|
|
43
|
+
const descendants = (node) => Array.from((node === null || node === void 0 ? void 0 : node.getElementsByTagName('*')) || []);
|
|
44
|
+
const marker = (node) => {
|
|
45
|
+
if (!node)
|
|
46
|
+
return undefined;
|
|
47
|
+
const number = (name) => {
|
|
48
|
+
var _a;
|
|
49
|
+
return Number(((_a = children(node).find((child) => local(child) === name)) === null || _a === void 0 ? void 0 : _a.textContent) || 0);
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
row: number('row'),
|
|
53
|
+
col: number('col'),
|
|
54
|
+
rowOff: number('rowOff'),
|
|
55
|
+
colOff: number('colOff'),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const candidates = children(document.documentElement).flatMap((anchor) => {
|
|
59
|
+
const type = local(anchor), from = marker(children(anchor).find((child) => local(child) === 'from'));
|
|
60
|
+
const to = marker(children(anchor).find((child) => local(child) === 'to'));
|
|
61
|
+
const rowAnchor = createDrawingRowAnchor(type, anchor.getAttribute('editAs'), from, to);
|
|
62
|
+
if (!rowAnchor)
|
|
63
|
+
return [];
|
|
64
|
+
return descendants(anchor)
|
|
65
|
+
.filter((node) => local(node) === 'blip')
|
|
66
|
+
.map((blip) => ({
|
|
67
|
+
type,
|
|
68
|
+
from,
|
|
69
|
+
to,
|
|
70
|
+
rowAnchor,
|
|
71
|
+
id: blip.getAttributeNS('http://schemas.openxmlformats.org/officeDocument/2006/relationships', 'embed') || blip.getAttribute('r:embed'),
|
|
72
|
+
}));
|
|
73
|
+
});
|
|
74
|
+
const sameMarker = (a, b) => (!a && !b) ||
|
|
75
|
+
(!!a &&
|
|
76
|
+
!!b &&
|
|
77
|
+
['row', 'col', 'rowOff', 'colOff'].every((key) => a[key] === b[key]));
|
|
78
|
+
for (const image of images) {
|
|
79
|
+
const matches = candidates.filter((candidate) => {
|
|
80
|
+
var _a, _b, _c;
|
|
81
|
+
return candidate.id === image.id &&
|
|
82
|
+
candidate.type === ((_a = image.anchor) === null || _a === void 0 ? void 0 : _a.type) &&
|
|
83
|
+
sameMarker(candidate.from, (_b = image.anchor) === null || _b === void 0 ? void 0 : _b.from) &&
|
|
84
|
+
sameMarker(candidate.to, (_c = image.anchor) === null || _c === void 0 ? void 0 : _c.to);
|
|
85
|
+
});
|
|
86
|
+
if (matches.length === 1)
|
|
87
|
+
result.set(image, matches[0].rowAnchor);
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
};
|
|
@@ -79,7 +79,6 @@ class FormulaParser {
|
|
|
79
79
|
};
|
|
80
80
|
while (((_a = precedence[this.current().kind]) !== null && _a !== void 0 ? _a : -1) >= minimum) {
|
|
81
81
|
const op = this.tokens[this.index++].kind;
|
|
82
|
-
// Excel exponentiation is left associative.
|
|
83
82
|
left = { kind: 'binary', op, left, right: this.expression(precedence[op] + 1) };
|
|
84
83
|
}
|
|
85
84
|
this.depth--;
|
|
@@ -163,8 +162,6 @@ const numeric = (value) => {
|
|
|
163
162
|
return 0;
|
|
164
163
|
if (typeof value === 'boolean')
|
|
165
164
|
return value ? 1 : 0;
|
|
166
|
-
// Blank cells use null. Empty strings and JavaScript-only hexadecimal text
|
|
167
|
-
// are not Excel arithmetic numbers and must not silently become 0 or 16.
|
|
168
165
|
if (typeof value === 'string' &&
|
|
169
166
|
!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?$/.test(value.trim()))
|
|
170
167
|
return unavailable();
|
|
@@ -292,8 +289,6 @@ export function recoverUncachedFormulaValues(workbook) {
|
|
|
292
289
|
if (node.op === '&')
|
|
293
290
|
return textValue(left) + textValue(right);
|
|
294
291
|
if (['=', '<>', '<', '>', '<=', '>='].includes(node.op)) {
|
|
295
|
-
// Excel compares text without case sensitivity. Different value types
|
|
296
|
-
// are ordered number < text < logical; empty cells take the other type.
|
|
297
292
|
const normalize = (value, other) => value === null
|
|
298
293
|
? typeof other === 'string'
|
|
299
294
|
? ''
|
|
@@ -321,7 +316,6 @@ export function recoverUncachedFormulaValues(workbook) {
|
|
|
321
316
|
const a = numeric(left), b = numeric(right);
|
|
322
317
|
if (node.op === '/' && b === 0)
|
|
323
318
|
return unavailable();
|
|
324
|
-
// Office POWER(0,0) is an error, unlike JavaScript's finite result1.
|
|
325
319
|
if (node.op === '^' && a === 0 && b === 0)
|
|
326
320
|
return unavailable();
|
|
327
321
|
const value = node.op === '+'
|
|
@@ -391,7 +385,6 @@ export function recoverUncachedFormulaValues(workbook) {
|
|
|
391
385
|
readCell(name, row, col, 0);
|
|
392
386
|
}
|
|
393
387
|
catch {
|
|
394
|
-
/* keep the original formula visible */
|
|
395
388
|
}
|
|
396
389
|
}
|
|
397
390
|
for (const { cells } of sheets.values())
|
|
@@ -402,13 +395,11 @@ export function recoverUncachedFormulaValues(workbook) {
|
|
|
402
395
|
const value = (_a = results.get(cell)) !== null && _a !== void 0 ? _a : 0;
|
|
403
396
|
cell.v = value;
|
|
404
397
|
cell.t = typeof value === 'boolean' ? 'b' : typeof value === 'string' ? 's' : 'n';
|
|
405
|
-
// The parser may have produced w="0" for an empty cached value.
|
|
406
398
|
delete cell.w;
|
|
407
399
|
try {
|
|
408
400
|
cell.w = utils.format_cell(cell);
|
|
409
401
|
}
|
|
410
402
|
catch {
|
|
411
|
-
/* plain value is still available */
|
|
412
403
|
}
|
|
413
404
|
calculated++;
|
|
414
405
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { WorkBook } from 'styled-exceljs';
|
|
1
|
+
import type { WorkBook, WorkSheet } from 'styled-exceljs';
|
|
2
2
|
import { type SpreadsheetTextSource } from './textEncoding.js';
|
|
3
|
-
import type { SheetCellImage, SheetChartDefinition, SheetDefinition } from '../type.js';
|
|
3
|
+
import type { SheetCellImage, SheetChartDefinition, SheetComment, SheetDefinition, SheetOccupiedRegion, SheetSourceDiscovery } from '../type.js';
|
|
4
4
|
interface DrawingMarkerLike {
|
|
5
5
|
row?: number;
|
|
6
6
|
col?: number;
|
|
@@ -21,9 +21,10 @@ export interface SpreadsheetParserContext {
|
|
|
21
21
|
sheets: SheetDefinition[];
|
|
22
22
|
charts: Record<string, SheetChartDefinition[]>;
|
|
23
23
|
cellImages: Record<string, SheetCellImage[]>;
|
|
24
|
+
comments: Record<string, SheetComment[]>;
|
|
25
|
+
commentsError: boolean;
|
|
24
26
|
}
|
|
25
27
|
export interface SpreadsheetWorkbookSource extends SpreadsheetTextSource {
|
|
26
|
-
/** Retain truly empty sheets only for the opt-in Excel viewport grid. */
|
|
27
28
|
includeEmptySheets?: boolean;
|
|
28
29
|
}
|
|
29
30
|
export interface SpreadsheetWorkerRequest {
|
|
@@ -65,9 +66,44 @@ export interface WorksheetDisplayBounds {
|
|
|
65
66
|
observedColCount: number;
|
|
66
67
|
trimmed: boolean;
|
|
67
68
|
}
|
|
68
|
-
export declare const
|
|
69
|
+
export declare const classifySpreadsheetCell: (value: unknown, defaultFont?: object) => {
|
|
70
|
+
value: boolean;
|
|
71
|
+
style: "unknown" | "default" | "authored";
|
|
72
|
+
visual: boolean;
|
|
73
|
+
};
|
|
74
|
+
export declare const getWorksheetDisplayBounds: (worksheet: WorksheetRangeLike | undefined, charts: SheetChartDefinition[] | undefined, _comments?: SheetComment[], options?: {
|
|
75
|
+
defaultFont?: object;
|
|
76
|
+
}) => WorksheetDisplayBounds;
|
|
69
77
|
export declare const parseSpreadsheetWorkbook: (context: SpreadsheetParserContext, data: ArrayBuffer, source?: SpreadsheetWorkbookSource) => Promise<SpreadsheetWorkerResponse[]>;
|
|
70
78
|
export declare const parseSpreadsheetSheet: (context: SpreadsheetParserContext, payload?: Record<string, any>) => SpreadsheetWorkerResponse[];
|
|
79
|
+
export declare const parseSpreadsheetRegion: (context: SpreadsheetParserContext, payload?: Record<string, any>) => SpreadsheetWorkerResponse[];
|
|
80
|
+
export declare const indexOccupiedRegions: (worksheet: WorkSheet, budget?: {
|
|
81
|
+
tiles: number;
|
|
82
|
+
visitedCells: number;
|
|
83
|
+
}) => {
|
|
84
|
+
regions: SheetOccupiedRegion[];
|
|
85
|
+
index: {
|
|
86
|
+
coverage: "value-formula-link-rich-text-cells-only";
|
|
87
|
+
status: "complete" | "budget-exceeded";
|
|
88
|
+
visitedCells: number;
|
|
89
|
+
indexedTiles: number;
|
|
90
|
+
limits: {
|
|
91
|
+
tiles: number;
|
|
92
|
+
visitedCells: number;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
export declare const discoverSpreadsheetSource: (worksheet: WorkSheet, sources?: {
|
|
97
|
+
charts?: SheetChartDefinition[];
|
|
98
|
+
cellImages?: SheetCellImage[];
|
|
99
|
+
defaultFont?: object;
|
|
100
|
+
}, budget?: Partial<SheetSourceDiscovery["limits"]>) => {
|
|
101
|
+
extent: {
|
|
102
|
+
rows: number;
|
|
103
|
+
cols: number;
|
|
104
|
+
};
|
|
105
|
+
sourceDiscovery: SheetSourceDiscovery;
|
|
106
|
+
};
|
|
71
107
|
export declare const searchSpreadsheetWorkbook: (context: SpreadsheetParserContext, query: string, options?: SpreadsheetSearchOptions) => SpreadsheetSearchMatch[];
|
|
72
108
|
export declare const handleSpreadsheetWorkerRequest: (context: SpreadsheetParserContext, request: SpreadsheetWorkerRequest) => SpreadsheetWorkerResponse[] | Promise<SpreadsheetWorkerResponse[]>;
|
|
73
109
|
export {};
|