reamkit 1.4.0 → 1.6.0
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.md +10 -8
- package/dist/esm/core/converter/facade.d.ts +12 -6
- package/dist/esm/core/converter/facade.js +34 -5
- package/dist/esm/core/converter/ream.d.ts +5 -3
- package/dist/esm/core/converter/ream.js +18 -4
- package/dist/esm/core/document-model/index.d.ts +1 -1
- package/dist/esm/core/document-model/types.d.ts +26 -0
- package/dist/esm/core/drawingml/sparkline-geometry.d.ts +8 -0
- package/dist/esm/core/drawingml/sparkline-geometry.js +111 -0
- package/dist/esm/core/ir/adapters.d.ts +5 -5
- package/dist/esm/core/ir/sheet.d.ts +31 -0
- package/dist/esm/core/opc/relationships.js +1 -0
- package/dist/esm/core/spreadsheet-model/index.d.ts +1 -0
- package/dist/esm/core/spreadsheet-model/types.d.ts +189 -0
- package/dist/esm/excel/column-bands.d.ts +7 -0
- package/dist/esm/excel/column-bands.js +87 -0
- package/dist/esm/excel/conditional-format.d.ts +16 -0
- package/dist/esm/excel/conditional-format.js +327 -0
- package/dist/esm/excel/index.d.ts +4 -3
- package/dist/esm/excel/print-model.d.ts +2 -1
- package/dist/esm/excel/print-model.js +144 -13
- package/dist/esm/excel/sheet-drawing.d.ts +1 -1
- package/dist/esm/excel/sheet-to-flow.d.ts +3 -0
- package/dist/esm/excel/sheet-to-flow.js +51 -0
- package/dist/esm/excel/styles-parser.d.ts +1 -50
- package/dist/esm/excel/styles-parser.js +38 -1
- package/dist/esm/excel/table-parser.d.ts +2 -0
- package/dist/esm/excel/table-parser.js +51 -0
- package/dist/esm/excel/workbook-parser.d.ts +1 -5
- package/dist/esm/excel/worksheet-parser.d.ts +1 -60
- package/dist/esm/excel/worksheet-parser.js +265 -1
- package/dist/esm/excel/xlsx-reader.d.ts +3 -1
- package/dist/esm/excel/xlsx-reader.js +86 -51
- package/dist/esm/excel/xlsx-writer.d.ts +4 -0
- package/dist/esm/excel/xlsx-writer.js +278 -0
- package/dist/esm/html/html-writer.js +126 -4
- package/dist/esm/layout/styled-layout.js +160 -1
- package/dist/esm/pdf-reader/cmap.d.ts +5 -0
- package/dist/esm/pdf-reader/cmap.js +72 -0
- package/dist/esm/pdf-reader/content.d.ts +14 -0
- package/dist/esm/pdf-reader/content.js +292 -0
- package/dist/esm/pdf-reader/document.d.ts +23 -0
- package/dist/esm/pdf-reader/document.js +230 -0
- package/dist/esm/pdf-reader/flow-build.d.ts +4 -0
- package/dist/esm/pdf-reader/flow-build.js +27 -0
- package/dist/esm/pdf-reader/font.d.ts +4 -0
- package/dist/esm/pdf-reader/font.js +69 -0
- package/dist/esm/pdf-reader/layout.d.ts +3 -0
- package/dist/esm/pdf-reader/layout.js +69 -0
- package/dist/esm/pdf-reader/lexer.d.ts +43 -0
- package/dist/esm/pdf-reader/lexer.js +250 -0
- package/dist/esm/pdf-reader/parser.d.ts +10 -0
- package/dist/esm/pdf-reader/parser.js +86 -0
- package/dist/esm/pdf-reader/reader.d.ts +4 -0
- package/dist/esm/pdf-reader/reader.js +43 -0
- package/dist/esm/pdf-reader/struct-tree.d.ts +14 -0
- package/dist/esm/pdf-reader/struct-tree.js +92 -0
- package/dist/esm/pdf-reader/tagged.d.ts +3 -0
- package/dist/esm/pdf-reader/tagged.js +88 -0
- package/dist/esm/pdf-reader/text.d.ts +3 -0
- package/dist/esm/pdf-reader/text.js +18 -0
- package/package.json +4 -3
|
@@ -2,6 +2,8 @@ import { eighthPtToPt, halfPtToPt, twipsToPt } from "../core/ir/units.js";
|
|
|
2
2
|
import { parseAreaRef, parseTitleRowRange } from "./defined-name-ref.js";
|
|
3
3
|
import { applyNumberFormat } from "./number-format.js";
|
|
4
4
|
import "./index.js";
|
|
5
|
+
import { bandedTables, computeColumnBands } from "./column-bands.js";
|
|
6
|
+
import { buildConditionalFormatter } from "./conditional-format.js";
|
|
5
7
|
var TWIPS_PER_POINT = 20;
|
|
6
8
|
var TWIPS_PER_INCH = 1440;
|
|
7
9
|
var PAPER_SIZES_TWIPS = new Map([
|
|
@@ -107,6 +109,12 @@ function worksheetToBody(worksheet, sharedStrings, styles, date1904, print) {
|
|
|
107
109
|
if (m.endRow > usedRow) usedRow = m.endRow;
|
|
108
110
|
if (m.endColumn > usedCol) usedCol = m.endColumn;
|
|
109
111
|
}
|
|
112
|
+
for (const sp of worksheet.sparklines ?? []) {
|
|
113
|
+
const host = parseAreaRef(sp.sqref);
|
|
114
|
+
if (!host) continue;
|
|
115
|
+
if (host.startRow > usedRow) usedRow = host.startRow;
|
|
116
|
+
if (host.startColumn > usedCol) usedCol = host.startColumn;
|
|
117
|
+
}
|
|
110
118
|
if (usedRow < 0 || usedCol < 0) return [];
|
|
111
119
|
let rowStart = 0;
|
|
112
120
|
let colStart = 0;
|
|
@@ -184,6 +192,9 @@ function worksheetToBody(worksheet, sharedStrings, styles, date1904, print) {
|
|
|
184
192
|
}
|
|
185
193
|
return props;
|
|
186
194
|
};
|
|
195
|
+
const cfFormatter = buildConditionalFormatter(worksheet.conditionalFormats, styles, worksheet.cells);
|
|
196
|
+
const sparklineByCell = buildSparklineLookup(worksheet, print);
|
|
197
|
+
const tableFormatByCell = buildTableFormatLookup(worksheet);
|
|
187
198
|
const rows = [];
|
|
188
199
|
for (let r = 0; r < rowCount; r++) {
|
|
189
200
|
const absR = r + rowStart;
|
|
@@ -201,10 +212,28 @@ function worksheetToBody(worksheet, sharedStrings, styles, date1904, print) {
|
|
|
201
212
|
if (text.length > textBudget) text = text.slice(0, Math.max(0, textBudget));
|
|
202
213
|
textBudget -= text.length;
|
|
203
214
|
const xf = ws && ws.styleIndex !== void 0 ? styles.cellXfs[ws.styleIndex] : void 0;
|
|
204
|
-
|
|
215
|
+
let runProps = cellRunProps(xf);
|
|
205
216
|
const alignment = xf ? alignmentFromXf(xf) : void 0;
|
|
206
|
-
|
|
217
|
+
let shading = xf ? shadingFromXf(xf, styles) : void 0;
|
|
218
|
+
const tableFmt = tableFormatByCell.get(key(absR, absC));
|
|
219
|
+
if (!shading && tableFmt?.shading) shading = tableFmt.shading;
|
|
220
|
+
if (tableFmt?.fontColorHex) runProps = {
|
|
221
|
+
...runProps,
|
|
222
|
+
colorHex: tableFmt.fontColorHex
|
|
223
|
+
};
|
|
207
224
|
const borders = xf ? bordersFromXf(xf, styles) : void 0;
|
|
225
|
+
let dataBar;
|
|
226
|
+
let icon;
|
|
227
|
+
const sparkline = sparklineByCell.get(key(absR, absC));
|
|
228
|
+
if (cfFormatter && ws) {
|
|
229
|
+
const over = cfFormatter(absR, absC, ws.type === "n" && Number.isFinite(Number(ws.rawValue)) ? Number(ws.rawValue) : void 0);
|
|
230
|
+
if (over) {
|
|
231
|
+
if (over.fillHex) shading = { colorHex: over.fillHex };
|
|
232
|
+
if (over.dataBar) dataBar = over.dataBar;
|
|
233
|
+
if (over.icon) icon = over.icon;
|
|
234
|
+
runProps = applyCfOverride(runProps, over);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
208
237
|
if (text.length > 0 && !merge && ws && (ws.type === "s" || ws.type === "str" || ws.type === "inlineStr") && (alignment === void 0 || alignment === "left")) {
|
|
209
238
|
let availTwips = columnWidths[c];
|
|
210
239
|
let cc = c + 1;
|
|
@@ -222,6 +251,9 @@ function worksheetToBody(worksheet, sharedStrings, styles, date1904, print) {
|
|
|
222
251
|
...merge && visibleEndCol > merge.startColumn ? { colSpan: visibleEndCol - merge.startColumn + 1 } : {},
|
|
223
252
|
...merge && Math.min(merge.endRow, rowWindowEnd) > merge.startRow ? { merge: "start" } : {},
|
|
224
253
|
...shading ? { shading } : {},
|
|
254
|
+
...dataBar ? { dataBar } : {},
|
|
255
|
+
...icon ? { icon } : {},
|
|
256
|
+
...sparkline ? { sparkline } : {},
|
|
225
257
|
...borders ? { borders } : {}
|
|
226
258
|
};
|
|
227
259
|
const paragraphProps = cellParaProps(alignment);
|
|
@@ -260,20 +292,38 @@ function worksheetToBody(worksheet, sharedStrings, styles, date1904, print) {
|
|
|
260
292
|
width: eighthPtToPt(4)
|
|
261
293
|
};
|
|
262
294
|
const centered = worksheet.printOptions?.horizontalCentered === true;
|
|
295
|
+
const tableProperties = {
|
|
296
|
+
...print.gridLines ? { borders: {
|
|
297
|
+
top: thin,
|
|
298
|
+
bottom: thin,
|
|
299
|
+
left: thin,
|
|
300
|
+
right: thin,
|
|
301
|
+
insideH: thin,
|
|
302
|
+
insideV: thin
|
|
303
|
+
} } : {},
|
|
304
|
+
...centered ? { alignment: "center" } : {}
|
|
305
|
+
};
|
|
306
|
+
const contentWidthTwips = sheetContentWidthTwips(worksheet);
|
|
307
|
+
const colBreaksLocal = /* @__PURE__ */ new Set();
|
|
308
|
+
for (const brk of worksheet.colBreaks ?? []) {
|
|
309
|
+
const local = brk - colStart;
|
|
310
|
+
if (local > 0 && local < colCount) colBreaksLocal.add(local);
|
|
311
|
+
}
|
|
312
|
+
if (!scaled && colCount > 1 && (totalGridTwips > contentWidthTwips || colBreaksLocal.size > 0)) {
|
|
313
|
+
const bands = computeColumnBands(columnWidths, contentWidthTwips, colBreaksLocal);
|
|
314
|
+
if (bands.length > 1) return bandedTables(rows, columnWidths, bands, tableProperties);
|
|
315
|
+
}
|
|
316
|
+
const frozen = worksheet.pane && (worksheet.pane.frozenRows > 0 || worksheet.pane.frozenCols > 0) ? {
|
|
317
|
+
rows: worksheet.pane.frozenRows,
|
|
318
|
+
cols: worksheet.pane.frozenCols
|
|
319
|
+
} : void 0;
|
|
263
320
|
return [{
|
|
264
321
|
kind: "table",
|
|
265
322
|
table: {
|
|
266
|
-
properties: {
|
|
267
|
-
...
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
left: thin,
|
|
271
|
-
right: thin,
|
|
272
|
-
insideH: thin,
|
|
273
|
-
insideV: thin
|
|
274
|
-
} } : {},
|
|
275
|
-
...centered ? { alignment: "center" } : {}
|
|
276
|
-
},
|
|
323
|
+
properties: frozen ? {
|
|
324
|
+
...tableProperties,
|
|
325
|
+
frozen
|
|
326
|
+
} : tableProperties,
|
|
277
327
|
grid: columnWidths.map((w) => twipsToPt(w)),
|
|
278
328
|
rows
|
|
279
329
|
}
|
|
@@ -321,6 +371,14 @@ function runPropsFromXf(xf, styles) {
|
|
|
321
371
|
if (font.colorHex) props.colorHex = font.colorHex;
|
|
322
372
|
return props;
|
|
323
373
|
}
|
|
374
|
+
function applyCfOverride(base, o) {
|
|
375
|
+
return {
|
|
376
|
+
...base,
|
|
377
|
+
...o.fontColorHex ? { colorHex: o.fontColorHex } : {},
|
|
378
|
+
...o.bold !== void 0 ? { bold: o.bold } : {},
|
|
379
|
+
...o.italic !== void 0 ? { italic: o.italic } : {}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
324
382
|
function alignmentFromXf(xf) {
|
|
325
383
|
const align = xf.alignment;
|
|
326
384
|
if (!align) return void 0;
|
|
@@ -413,6 +471,79 @@ function mapBorderStyle(style) {
|
|
|
413
471
|
function key(row, col) {
|
|
414
472
|
return `${row},${col}`;
|
|
415
473
|
}
|
|
474
|
+
function buildSparklineLookup(worksheet, print) {
|
|
475
|
+
const out = /* @__PURE__ */ new Map();
|
|
476
|
+
for (const sp of worksheet.sparklines ?? []) {
|
|
477
|
+
const host = parseAreaRef(sp.sqref);
|
|
478
|
+
const area = parseAreaRef(sp.dataRange);
|
|
479
|
+
if (!host || !area) continue;
|
|
480
|
+
const values = collectSeriesValues(resolveSeriesGrid(sp.dataRange, worksheet, print.sheetGrids).cells, area);
|
|
481
|
+
if (values.length === 0 || values.every((v) => v === null)) continue;
|
|
482
|
+
out.set(key(host.startRow, host.startColumn), {
|
|
483
|
+
kind: sp.kind,
|
|
484
|
+
values,
|
|
485
|
+
...sp.colorHex ? { colorHex: sp.colorHex } : {}
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
return out;
|
|
489
|
+
}
|
|
490
|
+
function resolveSeriesGrid(dataRange, current, sheetGrids) {
|
|
491
|
+
if (!sheetGrids) return current;
|
|
492
|
+
const firstToken = dataRange.split(",")[0] ?? dataRange;
|
|
493
|
+
const bang = firstToken.lastIndexOf("!");
|
|
494
|
+
if (bang < 0) return current;
|
|
495
|
+
let name = firstToken.slice(0, bang).trim();
|
|
496
|
+
if (name.startsWith("'") && name.endsWith("'")) name = name.slice(1, -1).replace(/''/g, "'");
|
|
497
|
+
return sheetGrids.get(name) ?? current;
|
|
498
|
+
}
|
|
499
|
+
var MAX_SPARKLINE_POINTS = 1e3;
|
|
500
|
+
function collectSeriesValues(cells, area) {
|
|
501
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
502
|
+
for (const c of cells) {
|
|
503
|
+
if (c.row < area.startRow || c.row > area.endRow) continue;
|
|
504
|
+
if (c.column < area.startColumn || c.column > area.endColumn) continue;
|
|
505
|
+
if (c.type !== "n") continue;
|
|
506
|
+
const v = Number(c.rawValue);
|
|
507
|
+
if (Number.isFinite(v)) byKey.set(key(c.row, c.column), v);
|
|
508
|
+
}
|
|
509
|
+
if ((area.endRow - area.startRow + 1) * (area.endColumn - area.startColumn + 1) > MAX_SPARKLINE_POINTS) {
|
|
510
|
+
const pts = [...byKey.entries()].map(([k, v]) => {
|
|
511
|
+
const [r, col] = k.split(",").map(Number);
|
|
512
|
+
return {
|
|
513
|
+
r,
|
|
514
|
+
col,
|
|
515
|
+
v
|
|
516
|
+
};
|
|
517
|
+
});
|
|
518
|
+
pts.sort((a, b) => a.r - b.r || a.col - b.col);
|
|
519
|
+
return pts.map((p) => p.v);
|
|
520
|
+
}
|
|
521
|
+
const out = [];
|
|
522
|
+
for (let r = area.startRow; r <= area.endRow; r++) for (let col = area.startColumn; col <= area.endColumn; col++) out.push(byKey.get(key(r, col)) ?? null);
|
|
523
|
+
return out;
|
|
524
|
+
}
|
|
525
|
+
function buildTableFormatLookup(worksheet) {
|
|
526
|
+
const out = /* @__PURE__ */ new Map();
|
|
527
|
+
for (const t of worksheet.tables ?? []) {
|
|
528
|
+
const { ref } = t;
|
|
529
|
+
const firstDataRow = ref.startRow + t.headerRowCount;
|
|
530
|
+
for (let r = ref.startRow; r <= ref.endRow; r++) {
|
|
531
|
+
let colorHex;
|
|
532
|
+
let fontColorHex;
|
|
533
|
+
if (r < firstDataRow) {
|
|
534
|
+
colorHex = t.headerHex;
|
|
535
|
+
fontColorHex = t.headerTextHex;
|
|
536
|
+
} else if (t.showRowStripes && t.bandHex) colorHex = (r - firstDataRow) % 2 === 1 ? t.bandHex : void 0;
|
|
537
|
+
if (!colorHex && !fontColorHex) continue;
|
|
538
|
+
const fmt = {
|
|
539
|
+
...colorHex ? { shading: { colorHex } } : {},
|
|
540
|
+
...fontColorHex ? { fontColorHex } : {}
|
|
541
|
+
};
|
|
542
|
+
for (let c = ref.startColumn; c <= ref.endColumn; c++) out.set(key(r, c), fmt);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return out;
|
|
546
|
+
}
|
|
416
547
|
function cellHasContent(cell) {
|
|
417
548
|
return !!cell && (cell.rawValue !== "" || cell.inlineText !== void 0);
|
|
418
549
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OpcPackage } from '../core/opc/index.js';
|
|
2
|
-
import { ParsedWorksheet } from '
|
|
2
|
+
import { ParsedWorksheet } from '../core/spreadsheet-model/index.js';
|
|
3
3
|
export interface SheetChartRef {
|
|
4
4
|
readonly chartPartPath: string;
|
|
5
5
|
readonly widthPt: number;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { pt } from "../core/ir/units.js";
|
|
2
|
+
import { EMPTY_STYLE_SHEET, resolveBodyStyles } from "../core/style-cascade/resolver.js";
|
|
3
|
+
import "../core/style-cascade/index.js";
|
|
4
|
+
import { resolvePrintArea, resolvePrintTitleRows, sectionFromWorksheet, worksheetToBody } from "./print-model.js";
|
|
5
|
+
//#region src/excel/sheet-to-flow.ts
|
|
6
|
+
function projectSheetDoc(sheet) {
|
|
7
|
+
const body = [];
|
|
8
|
+
let firstSheetSection;
|
|
9
|
+
const sheetGrids = new Map(sheet.sheets.map((s) => [s.name, s.grid]));
|
|
10
|
+
for (let sheetIdx = 0; sheetIdx < sheet.sheets.length; sheetIdx++) {
|
|
11
|
+
const ws = sheet.sheets[sheetIdx];
|
|
12
|
+
if (sheetIdx === 0) firstSheetSection = sectionFromWorksheet(ws.grid);
|
|
13
|
+
if (sheetIdx > 0) body.push({
|
|
14
|
+
kind: "paragraph",
|
|
15
|
+
paragraph: {
|
|
16
|
+
properties: { pageBreakBefore: true },
|
|
17
|
+
runs: []
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const printArea = resolvePrintArea(sheet.definedNames, sheetIdx);
|
|
21
|
+
const titleRows = resolvePrintTitleRows(sheet.definedNames, sheetIdx);
|
|
22
|
+
const gridLines = ws.grid.printOptions?.gridLines === true;
|
|
23
|
+
body.push(...worksheetToBody(ws.grid, sheet.sharedStrings, sheet.styles, sheet.date1904, {
|
|
24
|
+
...printArea ? { printArea } : {},
|
|
25
|
+
...titleRows ? { titleRows } : {},
|
|
26
|
+
gridLines,
|
|
27
|
+
sheetGrids
|
|
28
|
+
}));
|
|
29
|
+
for (const ref of ws.charts ?? []) body.push({
|
|
30
|
+
kind: "chart",
|
|
31
|
+
chart: {
|
|
32
|
+
chartRelId: ref.chartPartPath,
|
|
33
|
+
width: pt(ref.widthPt),
|
|
34
|
+
height: pt(ref.heightPt),
|
|
35
|
+
paragraphProperties: {}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
kind: "flow",
|
|
41
|
+
body: resolveBodyStyles(body, EMPTY_STYLE_SHEET),
|
|
42
|
+
sections: [],
|
|
43
|
+
...firstSheetSection ? { section: firstSheetSection } : {},
|
|
44
|
+
styles: EMPTY_STYLE_SHEET,
|
|
45
|
+
resources: sheet.resources,
|
|
46
|
+
...sheet.chartData && sheet.chartData.size > 0 ? { charts: sheet.chartData } : {},
|
|
47
|
+
...sheet.info ? { info: sheet.info } : {}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { projectSheetDoc };
|
|
@@ -1,52 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
readonly sizePt?: number;
|
|
3
|
-
readonly bold?: boolean;
|
|
4
|
-
readonly italic?: boolean;
|
|
5
|
-
readonly underline?: boolean;
|
|
6
|
-
readonly colorHex?: string;
|
|
7
|
-
readonly name?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface XlsxFill {
|
|
10
|
-
readonly patternType?: string;
|
|
11
|
-
readonly fgColorHex?: string;
|
|
12
|
-
readonly bgColorHex?: string;
|
|
13
|
-
}
|
|
14
|
-
export type XlsxBorderStyleName = 'none' | 'thin' | 'medium' | 'thick' | 'hair' | 'dashed' | 'dotted' | 'double' | 'mediumDashed' | 'dashDot' | 'mediumDashDot' | 'dashDotDot' | 'mediumDashDotDot' | 'slantDashDot';
|
|
15
|
-
export interface XlsxBorderEdge {
|
|
16
|
-
readonly style?: XlsxBorderStyleName;
|
|
17
|
-
readonly colorHex?: string;
|
|
18
|
-
}
|
|
19
|
-
export interface XlsxBorder {
|
|
20
|
-
readonly top?: XlsxBorderEdge;
|
|
21
|
-
readonly right?: XlsxBorderEdge;
|
|
22
|
-
readonly bottom?: XlsxBorderEdge;
|
|
23
|
-
readonly left?: XlsxBorderEdge;
|
|
24
|
-
}
|
|
25
|
-
export type XlsxHorizontalAlign = 'left' | 'center' | 'right' | 'fill' | 'justify' | 'centerContinuous' | 'distributed';
|
|
26
|
-
export type XlsxVerticalAlign = 'top' | 'center' | 'bottom' | 'justify' | 'distributed';
|
|
27
|
-
export interface XlsxCellAlignment {
|
|
28
|
-
readonly horizontal?: XlsxHorizontalAlign;
|
|
29
|
-
readonly vertical?: XlsxVerticalAlign;
|
|
30
|
-
readonly wrapText?: boolean;
|
|
31
|
-
}
|
|
32
|
-
export interface XlsxCellXf {
|
|
33
|
-
readonly numFmtId: number;
|
|
34
|
-
readonly fontId: number;
|
|
35
|
-
readonly fillId: number;
|
|
36
|
-
readonly borderId: number;
|
|
37
|
-
readonly applyNumberFormat?: boolean;
|
|
38
|
-
readonly applyFont?: boolean;
|
|
39
|
-
readonly applyFill?: boolean;
|
|
40
|
-
readonly applyBorder?: boolean;
|
|
41
|
-
readonly applyAlignment?: boolean;
|
|
42
|
-
readonly alignment?: XlsxCellAlignment;
|
|
43
|
-
}
|
|
44
|
-
export interface XlsxStyles {
|
|
45
|
-
readonly numFmts: ReadonlyMap<number, string>;
|
|
46
|
-
readonly fonts: ReadonlyArray<XlsxFont>;
|
|
47
|
-
readonly fills: ReadonlyArray<XlsxFill>;
|
|
48
|
-
readonly borders: ReadonlyArray<XlsxBorder>;
|
|
49
|
-
readonly cellXfs: ReadonlyArray<XlsxCellXf>;
|
|
50
|
-
}
|
|
1
|
+
import { XlsxStyles } from '../core/spreadsheet-model/index.js';
|
|
51
2
|
export declare const EMPTY_XLSX_STYLES: XlsxStyles;
|
|
52
3
|
export declare function parseXlsxStyles(data: Uint8Array): XlsxStyles;
|
|
@@ -21,14 +21,51 @@ function parseXlsxStyles(data) {
|
|
|
21
21
|
const xml = decoder.decode(data);
|
|
22
22
|
const root = asObject(parser.parse(xml)["styleSheet"]);
|
|
23
23
|
if (!root) return EMPTY_XLSX_STYLES;
|
|
24
|
+
const dxfs = parseDxfs(root);
|
|
24
25
|
return {
|
|
25
26
|
numFmts: parseNumFmts(root),
|
|
26
27
|
fonts: parseFonts(root),
|
|
27
28
|
fills: parseFills(root),
|
|
28
29
|
borders: parseBorders(root),
|
|
29
|
-
cellXfs: parseCellXfs(root)
|
|
30
|
+
cellXfs: parseCellXfs(root),
|
|
31
|
+
...dxfs.length > 0 ? { dxfs } : {}
|
|
30
32
|
};
|
|
31
33
|
}
|
|
34
|
+
function parseDxfs(root) {
|
|
35
|
+
const node = asObject(root["dxfs"]);
|
|
36
|
+
if (!node) return [];
|
|
37
|
+
const out = [];
|
|
38
|
+
for (const item of asArray(node["dxf"])) {
|
|
39
|
+
const obj = asObject(item);
|
|
40
|
+
if (!obj) {
|
|
41
|
+
out.push({});
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const dxf = {};
|
|
45
|
+
const fontObj = asObject(obj["font"]);
|
|
46
|
+
if (fontObj) {
|
|
47
|
+
const font = {};
|
|
48
|
+
if (hasChild(fontObj, "b")) font.bold = childToggle(fontObj, "b");
|
|
49
|
+
if (hasChild(fontObj, "i")) font.italic = childToggle(fontObj, "i");
|
|
50
|
+
const colorHex = colorOf(asObject(fontObj["color"]));
|
|
51
|
+
if (colorHex) font.colorHex = colorHex;
|
|
52
|
+
if (Object.keys(font).length > 0) dxf.font = font;
|
|
53
|
+
}
|
|
54
|
+
const pf = asObject(asObject(obj["fill"])?.["patternFill"]);
|
|
55
|
+
if (pf) {
|
|
56
|
+
const fill = {};
|
|
57
|
+
const pt = strAttr(pf, "patternType");
|
|
58
|
+
if (pt) fill.patternType = pt;
|
|
59
|
+
const fg = colorOf(asObject(pf["fgColor"]));
|
|
60
|
+
const bg = colorOf(asObject(pf["bgColor"]));
|
|
61
|
+
if (fg) fill.fgColorHex = fg;
|
|
62
|
+
if (bg) fill.bgColorHex = bg;
|
|
63
|
+
if (Object.keys(fill).length > 0) dxf.fill = fill;
|
|
64
|
+
}
|
|
65
|
+
out.push(dxf);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
32
69
|
var VALID_BORDER_STYLES = new Set([
|
|
33
70
|
"none",
|
|
34
71
|
"thin",
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { parseAreaRef } from "./defined-name-ref.js";
|
|
2
|
+
import { XMLParser } from "fast-xml-parser";
|
|
3
|
+
//#region src/excel/table-parser.ts
|
|
4
|
+
var decoder = new TextDecoder("utf-8");
|
|
5
|
+
var parser = new XMLParser({
|
|
6
|
+
ignoreAttributes: false,
|
|
7
|
+
attributeNamePrefix: "@_",
|
|
8
|
+
parseAttributeValue: false,
|
|
9
|
+
parseTagValue: false,
|
|
10
|
+
removeNSPrefix: true
|
|
11
|
+
});
|
|
12
|
+
function parseTablePart(data) {
|
|
13
|
+
const t = asObj(parser.parse(decoder.decode(data))["table"]);
|
|
14
|
+
if (!t) return void 0;
|
|
15
|
+
const refStr = strAttr(t, "ref");
|
|
16
|
+
const ref = refStr ? parseAreaRef(refStr) : void 0;
|
|
17
|
+
if (!ref) return void 0;
|
|
18
|
+
const si = asObj(t["tableStyleInfo"]);
|
|
19
|
+
const name = strAttr(t, "name");
|
|
20
|
+
const styleName = si ? strAttr(si, "name") : void 0;
|
|
21
|
+
return {
|
|
22
|
+
ref,
|
|
23
|
+
...name ? { name } : {},
|
|
24
|
+
...styleName ? { styleName } : {},
|
|
25
|
+
headerRowCount: numAttr(t, "headerRowCount") ?? 1,
|
|
26
|
+
showRowStripes: si ? boolAttr(si, "showRowStripes") : false,
|
|
27
|
+
showColumnStripes: si ? boolAttr(si, "showColumnStripes") : false,
|
|
28
|
+
showFirstColumn: si ? boolAttr(si, "showFirstColumn") : false,
|
|
29
|
+
showLastColumn: si ? boolAttr(si, "showLastColumn") : false,
|
|
30
|
+
autoFilter: asObj(t["autoFilter"]) !== void 0
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function asObj(v) {
|
|
34
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : void 0;
|
|
35
|
+
}
|
|
36
|
+
function strAttr(obj, name) {
|
|
37
|
+
const v = obj[`@_${name}`];
|
|
38
|
+
return typeof v === "string" ? v : void 0;
|
|
39
|
+
}
|
|
40
|
+
function numAttr(obj, name) {
|
|
41
|
+
const v = strAttr(obj, name);
|
|
42
|
+
if (v === void 0) return void 0;
|
|
43
|
+
const n = Number(v);
|
|
44
|
+
return Number.isFinite(n) ? n : void 0;
|
|
45
|
+
}
|
|
46
|
+
function boolAttr(obj, name) {
|
|
47
|
+
const v = strAttr(obj, name);
|
|
48
|
+
return v === "1" || v === "true";
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { parseTablePart };
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
+
import { DefinedName } from '../core/spreadsheet-model/index.js';
|
|
1
2
|
export interface SheetReference {
|
|
2
3
|
readonly name: string;
|
|
3
4
|
readonly sheetId: string;
|
|
4
5
|
readonly relationshipId: string;
|
|
5
6
|
}
|
|
6
|
-
export interface DefinedName {
|
|
7
|
-
readonly name: string;
|
|
8
|
-
readonly localSheetId?: number;
|
|
9
|
-
readonly value: string;
|
|
10
|
-
}
|
|
11
7
|
export interface ParsedWorkbook {
|
|
12
8
|
readonly sheets: ReadonlyArray<SheetReference>;
|
|
13
9
|
readonly date1904: boolean;
|
|
@@ -1,61 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export interface WorksheetCell {
|
|
3
|
-
readonly column: number;
|
|
4
|
-
readonly row: number;
|
|
5
|
-
readonly type: CellType;
|
|
6
|
-
readonly rawValue: string;
|
|
7
|
-
readonly inlineText?: string;
|
|
8
|
-
readonly styleIndex?: number;
|
|
9
|
-
}
|
|
10
|
-
export interface ColumnWidth {
|
|
11
|
-
readonly min: number;
|
|
12
|
-
readonly max: number;
|
|
13
|
-
readonly widthChars: number;
|
|
14
|
-
}
|
|
15
|
-
export interface MergedRange {
|
|
16
|
-
readonly startColumn: number;
|
|
17
|
-
readonly startRow: number;
|
|
18
|
-
readonly endColumn: number;
|
|
19
|
-
readonly endRow: number;
|
|
20
|
-
}
|
|
21
|
-
export interface RowHeight {
|
|
22
|
-
readonly row: number;
|
|
23
|
-
readonly heightPt: number;
|
|
24
|
-
readonly customHeight: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface XlsxPageMargins {
|
|
27
|
-
readonly leftInches: number;
|
|
28
|
-
readonly rightInches: number;
|
|
29
|
-
readonly topInches: number;
|
|
30
|
-
readonly bottomInches: number;
|
|
31
|
-
readonly headerInches?: number;
|
|
32
|
-
readonly footerInches?: number;
|
|
33
|
-
}
|
|
34
|
-
export interface XlsxPageSetup {
|
|
35
|
-
readonly paperSize?: number;
|
|
36
|
-
readonly orientation?: 'portrait' | 'landscape' | 'default';
|
|
37
|
-
readonly scale?: number;
|
|
38
|
-
readonly fitToWidth?: number;
|
|
39
|
-
readonly fitToHeight?: number;
|
|
40
|
-
}
|
|
41
|
-
export interface XlsxPrintOptions {
|
|
42
|
-
readonly gridLines?: boolean;
|
|
43
|
-
readonly horizontalCentered?: boolean;
|
|
44
|
-
readonly verticalCentered?: boolean;
|
|
45
|
-
}
|
|
46
|
-
export interface ParsedWorksheet {
|
|
47
|
-
readonly cells: ReadonlyArray<WorksheetCell>;
|
|
48
|
-
readonly maxRow: number;
|
|
49
|
-
readonly maxColumn: number;
|
|
50
|
-
readonly columns: ReadonlyArray<ColumnWidth>;
|
|
51
|
-
readonly merges: ReadonlyArray<MergedRange>;
|
|
52
|
-
readonly rowHeights: ReadonlyArray<RowHeight>;
|
|
53
|
-
readonly pageMargins?: XlsxPageMargins;
|
|
54
|
-
readonly pageSetup?: XlsxPageSetup;
|
|
55
|
-
readonly fitToPage?: boolean;
|
|
56
|
-
readonly printOptions?: XlsxPrintOptions;
|
|
57
|
-
readonly rowBreaks?: ReadonlyArray<number>;
|
|
58
|
-
readonly colBreaks?: ReadonlyArray<number>;
|
|
59
|
-
readonly drawingRelId?: string;
|
|
60
|
-
}
|
|
1
|
+
import { ParsedWorksheet } from '../core/spreadsheet-model/index.js';
|
|
61
2
|
export declare function parseWorksheet(data: Uint8Array): ParsedWorksheet;
|