@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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { assertSheetRegion, regionIntersects, ORDINARY_GRID_BUDGET } from '../../sourceRegion.js';
|
|
2
|
+
import { readImageRowAnchors } from './drawingRowAnchor.js';
|
|
1
3
|
import { utils } from 'styled-exceljs';
|
|
2
4
|
import { getTintColor, indexedColors } from './color.js';
|
|
3
5
|
import { parseCellRichText, richTextToPlainText } from './richText.js';
|
|
@@ -43,8 +45,6 @@ const toFiniteNumber = (value) => {
|
|
|
43
45
|
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
44
46
|
};
|
|
45
47
|
const getDefaultColumnWidth = () => {
|
|
46
|
-
// Excel's displayed default is 8.43 characters plus five pixels of padding,
|
|
47
|
-
// not an already encoded OOXML <col width> value.
|
|
48
48
|
return Math.floor(EXCEL_DEFAULT_COLUMN_WIDTH * 7 + 5);
|
|
49
49
|
};
|
|
50
50
|
const getDefaultRowHeight = () => {
|
|
@@ -90,7 +90,6 @@ const getColumnPixelWidth = (column, maximumDigitWidth = 7) => {
|
|
|
90
90
|
if (maximumDigitWidth !== 7 && storedWidth !== undefined && storedWidth >= 0) {
|
|
91
91
|
return Math.trunc(((256 * storedWidth + Math.trunc(128 / maximumDigitWidth)) / 256) * maximumDigitWidth);
|
|
92
92
|
}
|
|
93
|
-
// styled-exceljs 在 browserPixels 模式下会优先输出 wpx,这是最接近浏览器渲染的列宽。
|
|
94
93
|
const wpx = toFiniteNumber(column.wpx);
|
|
95
94
|
if (wpx !== undefined && wpx >= 0) {
|
|
96
95
|
return Math.ceil(wpx);
|
|
@@ -145,8 +144,6 @@ const getRowPixelHeight = (rowMeta) => {
|
|
|
145
144
|
if (rowMeta.hidden) {
|
|
146
145
|
return 0;
|
|
147
146
|
}
|
|
148
|
-
// The parser retains OOXML points in hpt, but its legacy hpx conversion
|
|
149
|
-
// uses 96/96. Prefer the authoritative points and convert to CSS pixels once.
|
|
150
147
|
const hpt = toFiniteNumber(rowMeta.hpt);
|
|
151
148
|
if (hpt !== undefined && hpt >= 0) {
|
|
152
149
|
const converter = utils.row_height_to_px;
|
|
@@ -235,8 +232,6 @@ const isAutomaticPaletteColor = (color) => {
|
|
|
235
232
|
return indexed === 32767;
|
|
236
233
|
};
|
|
237
234
|
const normalizeFontColor = (color) => {
|
|
238
|
-
// BIFF/XLS 会把“自动字体色”解析成 indexed 32767,部分文件还会附带
|
|
239
|
-
// FFFFFF 的 rgb 值。Excel 实际显示为默认黑色,不能当成显式白色。
|
|
240
235
|
if (isAutomaticPaletteColor(color)) {
|
|
241
236
|
return EXCEL_DEFAULT_TEXT_COLOR;
|
|
242
237
|
}
|
|
@@ -322,7 +317,6 @@ const getCellStyle = (cellStyle) => {
|
|
|
322
317
|
}
|
|
323
318
|
const fontSize = Number(font.sz || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.sz));
|
|
324
319
|
if (Number.isFinite(fontSize) && fontSize > 0) {
|
|
325
|
-
// Excel 字号以 pt 存储;模型统一输出 CSS px,视图层再单独应用缩放。
|
|
326
320
|
style.fontSize = `${fontSize * 96 / 72}px`;
|
|
327
321
|
}
|
|
328
322
|
const fontName = font.name || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.name);
|
|
@@ -361,6 +355,7 @@ class SheetJsModel {
|
|
|
361
355
|
}
|
|
362
356
|
constructor(ws, options) {
|
|
363
357
|
this._ws = ws;
|
|
358
|
+
this._defaultFont = options.defaultFont;
|
|
364
359
|
this._startRow = Math.max(options.startRow || 0, 0);
|
|
365
360
|
this._pageSize = Math.max(options.pageSize || 500, 1);
|
|
366
361
|
this._totalRows = options.totalRows;
|
|
@@ -452,10 +447,18 @@ class SheetJsModel {
|
|
|
452
447
|
return this.ws[utils.encode_cell({ r: row, c: col })];
|
|
453
448
|
}
|
|
454
449
|
getAxisOffset(index, sizes, fallback) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
450
|
+
if (typeof sizes === 'number')
|
|
451
|
+
return index * sizes;
|
|
452
|
+
let offset = index * fallback;
|
|
453
|
+
if (sizes)
|
|
454
|
+
for (const key in sizes) {
|
|
455
|
+
if (!Object.prototype.hasOwnProperty.call(sizes, key))
|
|
456
|
+
continue;
|
|
457
|
+
const current = Number(key);
|
|
458
|
+
if (Number.isSafeInteger(current) && current >= 0 && current < index && sizes[current] !== undefined) {
|
|
459
|
+
offset += sizes[current] - fallback;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
459
462
|
return offset;
|
|
460
463
|
}
|
|
461
464
|
getMarkerLeft(marker) {
|
|
@@ -476,6 +479,7 @@ class SheetJsModel {
|
|
|
476
479
|
if (!images.length && !this._cellImages.length) {
|
|
477
480
|
return undefined;
|
|
478
481
|
}
|
|
482
|
+
const rowAnchors = readImageRowAnchors(drawings === null || drawings === void 0 ? void 0 : drawings.raw, images);
|
|
479
483
|
const drawingImages = images.flatMap((image, index) => {
|
|
480
484
|
var _a, _b, _c, _d, _e;
|
|
481
485
|
const anchor = image.anchor;
|
|
@@ -490,6 +494,7 @@ class SheetJsModel {
|
|
|
490
494
|
return [{
|
|
491
495
|
id: image.id || ((_e = image.objectId) === null || _e === void 0 ? void 0 : _e.toString()) || image.target || `image-${index + 1}`,
|
|
492
496
|
src: image.dataURI,
|
|
497
|
+
...(rowAnchors.has(image) ? { rowAnchor: rowAnchors.get(image) } : {}),
|
|
493
498
|
contentType: image.contentType,
|
|
494
499
|
left: Math.max(0, left),
|
|
495
500
|
top: Math.max(0, top),
|
|
@@ -507,6 +512,7 @@ class SheetJsModel {
|
|
|
507
512
|
}
|
|
508
513
|
return [{
|
|
509
514
|
...image,
|
|
515
|
+
rowAnchor: { mode: 'cell', fromRow: image.row, fromOffset: 0 },
|
|
510
516
|
left: this.getAxisOffset(image.col, this.getColWidths(), this.defaults.colWidth),
|
|
511
517
|
top: this.getAxisOffset(image.row, this.getAllRowHeights(), this.defaults.rowHeight),
|
|
512
518
|
width,
|
|
@@ -529,6 +535,7 @@ class SheetJsModel {
|
|
|
529
535
|
: top + emuToPixels((_b = chart.ext) === null || _b === void 0 ? void 0 : _b.height);
|
|
530
536
|
return {
|
|
531
537
|
id: chart.id,
|
|
538
|
+
...(chart.rowAnchor ? { rowAnchor: chart.rowAnchor } : {}),
|
|
532
539
|
type: chart.type,
|
|
533
540
|
title: chart.title,
|
|
534
541
|
categoryAxisTitle: chart.categoryAxisTitle,
|
|
@@ -578,26 +585,45 @@ class SheetJsModel {
|
|
|
578
585
|
}
|
|
579
586
|
return fixMatrix(result, this.totalCols);
|
|
580
587
|
}
|
|
581
|
-
|
|
588
|
+
getCellMetadata(rowIndex, colIndex, cell) {
|
|
582
589
|
var _a, _b;
|
|
583
|
-
const result = {};
|
|
584
590
|
const { '!cols': cols = [], '!rows': rows = [] } = this.ws;
|
|
591
|
+
const inheritedStyle = mergeStyle((_a = cols[colIndex]) === null || _a === void 0 ? void 0 : _a.s, (_b = rows[rowIndex]) === null || _b === void 0 ? void 0 : _b.s, cell === null || cell === void 0 ? void 0 : cell.s);
|
|
592
|
+
const rawStyle = resolveTableCellStyle(this.ws, rowIndex, colIndex, inheritedStyle);
|
|
593
|
+
let displayStyle = rawStyle;
|
|
594
|
+
if (this._defaultFont && (cell || rawStyle)) {
|
|
595
|
+
const explicitFont = (inheritedStyle === null || inheritedStyle === void 0 ? void 0 : inheritedStyle.font) || (['name', 'sz', 'bold', 'italic', 'color'].some(key => (inheritedStyle === null || inheritedStyle === void 0 ? void 0 : inheritedStyle[key]) !== undefined)
|
|
596
|
+
? inheritedStyle : undefined);
|
|
597
|
+
displayStyle = {
|
|
598
|
+
...rawStyle,
|
|
599
|
+
font: {
|
|
600
|
+
...(explicitFont ? {
|
|
601
|
+
name: this._defaultFont.name,
|
|
602
|
+
sz: this._defaultFont.sz,
|
|
603
|
+
...explicitFont
|
|
604
|
+
} : this._defaultFont),
|
|
605
|
+
...rawStyle === null || rawStyle === void 0 ? void 0 : rawStyle.font
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
const className = alignToClassName(rawStyle === null || rawStyle === void 0 ? void 0 : rawStyle.alignment);
|
|
610
|
+
const style = getCellStyle(displayStyle);
|
|
611
|
+
const richText = parseCellRichText(cell);
|
|
612
|
+
if (!className && !style && !(richText === null || richText === void 0 ? void 0 : richText.length))
|
|
613
|
+
return undefined;
|
|
614
|
+
return {
|
|
615
|
+
...(className ? { className } : {}),
|
|
616
|
+
style: style || {},
|
|
617
|
+
...((richText === null || richText === void 0 ? void 0 : richText.length) ? { richText } : {})
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
getCell() {
|
|
621
|
+
const result = {};
|
|
585
622
|
for (let rowIndex = this.startRow; rowIndex < this.endRow; rowIndex += 1) {
|
|
586
623
|
for (let colIndex = 0; colIndex < this.totalCols; colIndex += 1) {
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
const className = alignToClassName(rawStyle === null || rawStyle === void 0 ? void 0 : rawStyle.alignment);
|
|
591
|
-
const style = getCellStyle(rawStyle);
|
|
592
|
-
const richText = parseCellRichText(cell);
|
|
593
|
-
if (!className && !style && !(richText === null || richText === void 0 ? void 0 : richText.length)) {
|
|
594
|
-
continue;
|
|
595
|
-
}
|
|
596
|
-
result[cellKey(rowIndex - this.startRow, colIndex)] = {
|
|
597
|
-
...(className ? { className } : {}),
|
|
598
|
-
style: style || {},
|
|
599
|
-
...((richText === null || richText === void 0 ? void 0 : richText.length) ? { richText } : {})
|
|
600
|
-
};
|
|
624
|
+
const metadata = this.getCellMetadata(rowIndex, colIndex, this.getCellAt(rowIndex, colIndex));
|
|
625
|
+
if (metadata)
|
|
626
|
+
result[cellKey(rowIndex - this.startRow, colIndex)] = metadata;
|
|
601
627
|
}
|
|
602
628
|
}
|
|
603
629
|
return result;
|
|
@@ -626,24 +652,34 @@ class SheetJsModel {
|
|
|
626
652
|
}
|
|
627
653
|
}
|
|
628
654
|
}
|
|
629
|
-
if (heights.length === 1) {
|
|
655
|
+
if (heights.length === 1 && this.endRow - this.startRow === 1) {
|
|
630
656
|
return heights[0];
|
|
631
657
|
}
|
|
632
658
|
return heights.length ? heights : rowHeight;
|
|
633
659
|
}
|
|
634
|
-
// 整表行高必须按绝对行号下发,否则拖动滚动条时隐藏行和特殊行高会造成高度跳变。
|
|
635
660
|
getAllRowHeights() {
|
|
636
661
|
const { '!rows': rows = [] } = this.ws;
|
|
637
662
|
const heights = [];
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
663
|
+
let entries = 0, visited = 0;
|
|
664
|
+
for (const key in rows) {
|
|
665
|
+
if (!Object.prototype.hasOwnProperty.call(rows, key))
|
|
666
|
+
continue;
|
|
667
|
+
const absoluteRow = Number(key);
|
|
668
|
+
if (!Number.isSafeInteger(absoluteRow) || absoluteRow < 0 || absoluteRow >= this.totalRows)
|
|
669
|
+
continue;
|
|
670
|
+
if (visited >= ORDINARY_GRID_BUDGET.rows) {
|
|
671
|
+
throw Object.assign(new RangeError('Stored row layout exceeds the metadata budget; request a data-only window or source region.'), {
|
|
672
|
+
code: 'LAYOUT_BUDGET_EXCEEDED', limit: ORDINARY_GRID_BUDGET.rows,
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
visited++;
|
|
676
|
+
const height = getRowPixelHeight(rows[absoluteRow]);
|
|
677
|
+
if (height !== undefined) {
|
|
678
|
+
entries++;
|
|
679
|
+
heights[absoluteRow] = height;
|
|
644
680
|
}
|
|
645
681
|
}
|
|
646
|
-
return
|
|
682
|
+
return entries ? heights : undefined;
|
|
647
683
|
}
|
|
648
684
|
getAutoFitColumns() {
|
|
649
685
|
var _a, _b;
|
|
@@ -655,8 +691,6 @@ class SheetJsModel {
|
|
|
655
691
|
const sampleRanges = this.getAutoFitSampleRanges();
|
|
656
692
|
const fittedColumns = [];
|
|
657
693
|
for (const range of sampleRanges) {
|
|
658
|
-
// 自动列宽只作为缺失列宽的兜底。合并标题和 Excel 溢出文本不应该反向撑开基础列宽。
|
|
659
|
-
// 大表只抽样固定数量的单元格,避免为了首屏列宽扫描整张工作表。
|
|
660
694
|
const measuredColumns = autoFitColumns(this.ws, {
|
|
661
695
|
range,
|
|
662
696
|
set: false,
|
|
@@ -699,13 +733,9 @@ class SheetJsModel {
|
|
|
699
733
|
if (hasColumnWidth(sourceColumn)) {
|
|
700
734
|
return sourceColumn;
|
|
701
735
|
}
|
|
702
|
-
// A drawing anchor is measured against the workbook's stored/default
|
|
703
|
-
// column geometry. Auto-fitting blank columns to 24px changes that
|
|
704
|
-
// coordinate system and makes two-cell images visibly smaller than Excel.
|
|
705
736
|
if (this.hasAnchoredObjects || this.ws['!fileViewerLayout']) {
|
|
706
737
|
return sourceColumn;
|
|
707
738
|
}
|
|
708
|
-
// 没有显式列宽时,再使用 styled-exceljs 的内容测量兜底,避免报表类标题污染原始宽度。
|
|
709
739
|
return ((_a = this.autoFitColumns) === null || _a === void 0 ? void 0 : _a[colIndex]) || sourceColumn;
|
|
710
740
|
}
|
|
711
741
|
get hasAnchoredObjects() {
|
|
@@ -742,15 +772,76 @@ class SheetJsModel {
|
|
|
742
772
|
});
|
|
743
773
|
}
|
|
744
774
|
getStructure() {
|
|
775
|
+
var _a;
|
|
745
776
|
return {
|
|
746
777
|
merge: this.getAllMerge(),
|
|
747
778
|
colWidths: this.getColWidths(),
|
|
748
779
|
rowHeights: this.getAllRowHeights(),
|
|
780
|
+
rowSizing: (_a = this.ws['!fileViewerLayout']) === null || _a === void 0 ? void 0 : _a.rowSizing,
|
|
749
781
|
columns: this.getColumns(),
|
|
750
782
|
images: this.getImages(),
|
|
751
783
|
charts: this.getCharts()
|
|
752
784
|
};
|
|
753
785
|
}
|
|
786
|
+
toRegionObject(region) {
|
|
787
|
+
var _a, _b;
|
|
788
|
+
assertSheetRegion(region);
|
|
789
|
+
const { '!cols': sourceCols = [], '!rows': sourceRows = [] } = this.ws;
|
|
790
|
+
const layout = this.ws['!fileViewerLayout'];
|
|
791
|
+
const defaults = this.defaults;
|
|
792
|
+
const fixedRows = new Set(((_a = layout === null || layout === void 0 ? void 0 : layout.rowSizing) === null || _a === void 0 ? void 0 : _a.fixedRows) || []);
|
|
793
|
+
const data = [], cell = {};
|
|
794
|
+
const rows = Array.from({ length: region.rowCount }, (_, localRow) => {
|
|
795
|
+
const sourceRow = region.startRow + localRow;
|
|
796
|
+
const values = [];
|
|
797
|
+
for (let localCol = 0; localCol < region.colCount; localCol++) {
|
|
798
|
+
const sourceCol = region.startCol + localCol, value = this.getCellAt(sourceRow, sourceCol);
|
|
799
|
+
values.push(this._cellImageKeys.has(cellKey(sourceRow, sourceCol)) ? '' : formatCellValue(value));
|
|
800
|
+
const metadata = this.getCellMetadata(sourceRow, sourceCol, value);
|
|
801
|
+
if (metadata)
|
|
802
|
+
cell[cellKey(localRow, localCol)] = metadata;
|
|
803
|
+
}
|
|
804
|
+
data.push(values);
|
|
805
|
+
const height = getRowPixelHeight(sourceRows[sourceRow]);
|
|
806
|
+
return { sourceRow, height: height !== null && height !== void 0 ? height : defaults.rowHeight,
|
|
807
|
+
fixed: height !== undefined || fixedRows.has(sourceRow), hidden: height === 0 };
|
|
808
|
+
});
|
|
809
|
+
const columns = Array.from({ length: region.colCount }, (_, localCol) => {
|
|
810
|
+
var _a;
|
|
811
|
+
const sourceCol = region.startCol + localCol, meta = sourceCols[sourceCol];
|
|
812
|
+
return { sourceCol, title: utils.encode_col(sourceCol), hidden: !!(meta === null || meta === void 0 ? void 0 : meta.hidden),
|
|
813
|
+
width: (_a = getColumnPixelWidth(meta, layout === null || layout === void 0 ? void 0 : layout.maximumDigitWidth)) !== null && _a !== void 0 ? _a : defaults.colWidth };
|
|
814
|
+
});
|
|
815
|
+
const merges = this.getAllMerge().filter(merge => regionIntersects(region, merge)).map(source => {
|
|
816
|
+
const anchor = this.getCellAt(source.row, source.col);
|
|
817
|
+
return { source, anchorValue: formatCellValue(anchor),
|
|
818
|
+
anchorMetadata: this.getCellMetadata(source.row, source.col, anchor),
|
|
819
|
+
contained: source.row >= region.startRow && source.col >= region.startCol
|
|
820
|
+
&& source.row + source.rowspan <= region.startRow + region.rowCount
|
|
821
|
+
&& source.col + source.colspan <= region.startCol + region.colCount };
|
|
822
|
+
});
|
|
823
|
+
const drawings = this.ws['!drawings'];
|
|
824
|
+
const sourceImages = (drawings === null || drawings === void 0 ? void 0 : drawings.images) || [], rowAnchors = readImageRowAnchors(drawings === null || drawings === void 0 ? void 0 : drawings.raw, sourceImages);
|
|
825
|
+
const sourceObjects = {
|
|
826
|
+
images: sourceImages.map(image => ({ id: image.id, src: image.dataURI, anchor: image.anchor,
|
|
827
|
+
contentType: image.contentType, rowAnchor: rowAnchors.get(image) })),
|
|
828
|
+
charts: this._charts,
|
|
829
|
+
cellImages: this._cellImages,
|
|
830
|
+
};
|
|
831
|
+
const sourceGeometry = {
|
|
832
|
+
rows: Object.keys(sourceRows).flatMap(key => {
|
|
833
|
+
const index = Number(key), size = getRowPixelHeight(sourceRows[index]);
|
|
834
|
+
return Number.isSafeInteger(index) && index >= 0 && size !== undefined ? [{ index, size }] : [];
|
|
835
|
+
}),
|
|
836
|
+
columns: Object.keys(sourceCols).flatMap(key => {
|
|
837
|
+
const index = Number(key), size = getColumnPixelWidth(sourceCols[index], layout === null || layout === void 0 ? void 0 : layout.maximumDigitWidth);
|
|
838
|
+
return Number.isSafeInteger(index) && index >= 0 && size !== undefined ? [{ index, size }] : [];
|
|
839
|
+
}),
|
|
840
|
+
};
|
|
841
|
+
return { coordinateSpace: 'region-local', region: { ...region }, defaults, data, cell,
|
|
842
|
+
rows, columns, merges, sourceObjects, sourceGeometry,
|
|
843
|
+
autoHeightDisabled: !!((_b = layout === null || layout === void 0 ? void 0 : layout.rowSizing) === null || _b === void 0 ? void 0 : _b.autoHeightDisabled) };
|
|
844
|
+
}
|
|
754
845
|
toObject(options = {}) {
|
|
755
846
|
const { defaults, data, cell, merge, rowHeights, meta } = this;
|
|
756
847
|
return {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type XmlReadBudget } from './xmlBudget.js';
|
|
1
2
|
import { type Document as XmlDocument, type Element as XmlElement, type Node as XmlNode } from '@xmldom/xmldom';
|
|
2
3
|
import JSZip from 'jszip';
|
|
3
4
|
import type { WorkBook } from 'styled-exceljs';
|
|
@@ -11,7 +12,7 @@ export declare const localName: (node: XmlNode) => string;
|
|
|
11
12
|
export declare const childElements: (node: XmlNode | null | undefined) => XmlElement[];
|
|
12
13
|
export declare const elementsByLocal: (node: XmlNode | null | undefined, name: string) => XmlElement[];
|
|
13
14
|
export declare const relationshipId: (element: XmlElement | undefined) => string;
|
|
14
|
-
export declare const loadXml: (zip: JSZip, path: string) => Promise<XmlDocument | null>;
|
|
15
|
-
export declare const loadRelationships: (zip: JSZip, sourcePart: string) => Promise<Relationship[]>;
|
|
15
|
+
export declare const loadXml: (zip: JSZip, path: string, budget?: XmlReadBudget) => Promise<XmlDocument | null>;
|
|
16
|
+
export declare const loadRelationships: (zip: JSZip, sourcePart: string, readPart?: (path: string) => Promise<XmlDocument | null>) => Promise<Relationship[]>;
|
|
16
17
|
export declare const relationById: (relationships: Relationship[], id: string) => Relationship | undefined;
|
|
17
18
|
export declare const parseSpreadsheetCharts: (data: ArrayBuffer, workbook?: WorkBook | null) => Promise<Record<string, SheetChartDefinition[]>>;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { readSourceAnchor } from './sourceAnchor.js';
|
|
2
|
+
import { createDrawingRowAnchor } from './drawingRowAnchor.js';
|
|
3
|
+
import { readStoredRowSizing } from './rowSizing.js';
|
|
4
|
+
import { readBoundedZipText } from './xmlBudget.js';
|
|
1
5
|
import { DOMParser } from '@xmldom/xmldom';
|
|
2
6
|
import JSZip from 'jszip';
|
|
3
7
|
import { readStoredSheetLayout, readWorkbookDigitWidth } from './sheetLayout.js';
|
|
@@ -6,7 +10,6 @@ const CHART_RELATIONSHIP_SUFFIX = '/chart';
|
|
|
6
10
|
const DRAWING_RELATIONSHIP_SUFFIX = '/drawing';
|
|
7
11
|
const WORKSHEET_RELATIONSHIP_SUFFIX = '/worksheet';
|
|
8
12
|
const EMUS_PER_CSS_PIXEL = 9525;
|
|
9
|
-
// Bound cache indices and formula expansion before allocating producer-controlled arrays.
|
|
10
13
|
const MAX_CHART_POINTS = 1048576;
|
|
11
14
|
const CHART_TYPE_MAP = {
|
|
12
15
|
areaChart: 'area',
|
|
@@ -117,20 +120,17 @@ const relationshipPartPath = (sourcePart) => {
|
|
|
117
120
|
return `${directory ? `${directory}/` : ''}_rels/${filename}.rels`;
|
|
118
121
|
};
|
|
119
122
|
const parseXml = (xml) => {
|
|
120
|
-
// Some valid Office producers prefix relationship parts with a UTF-8 BOM.
|
|
121
|
-
// XML declarations must otherwise be the first character, and xmldom reports
|
|
122
|
-
// the BOM as content outside the root element before aborting chart parsing.
|
|
123
123
|
return new DOMParser().parseFromString(xml.replace(/^[\uFEFF\s]+/, ''), 'application/xml');
|
|
124
124
|
};
|
|
125
|
-
export const loadXml = async (zip, path) => {
|
|
125
|
+
export const loadXml = async (zip, path, budget) => {
|
|
126
126
|
const file = zip.file(path);
|
|
127
127
|
if (!file) {
|
|
128
128
|
return null;
|
|
129
129
|
}
|
|
130
|
-
return parseXml(await file.async('text'));
|
|
130
|
+
return parseXml(budget ? await readBoundedZipText(file, budget) : await file.async('text'));
|
|
131
131
|
};
|
|
132
|
-
export const loadRelationships = async (zip, sourcePart) => {
|
|
133
|
-
const document = await
|
|
132
|
+
export const loadRelationships = async (zip, sourcePart, readPart = (path) => loadXml(zip, path)) => {
|
|
133
|
+
const document = await readPart(relationshipPartPath(sourcePart));
|
|
134
134
|
if (!document) {
|
|
135
135
|
return [];
|
|
136
136
|
}
|
|
@@ -251,8 +251,6 @@ const parsePointValues = (element, workbook, formatted = true) => {
|
|
|
251
251
|
if (!element) {
|
|
252
252
|
return [];
|
|
253
253
|
}
|
|
254
|
-
// Cache point idx is a logical source position, not the point's XML order.
|
|
255
|
-
// Select one cache/level; flattening nested caches mixes category hierarchies.
|
|
256
254
|
const literal = firstChildByLocal(element, 'strLit') || firstChildByLocal(element, 'numLit');
|
|
257
255
|
const reference = firstChildByLocal(element, 'strRef') || firstChildByLocal(element, 'numRef');
|
|
258
256
|
const multiLevel = firstChildByLocal(firstChildByLocal(element, 'multiLvlStrRef'), 'multiLvlStrCache');
|
|
@@ -278,9 +276,6 @@ const parsePointValues = (element, workbook, formatted = true) => {
|
|
|
278
276
|
const values = Array(count).fill('');
|
|
279
277
|
for (const point of entries)
|
|
280
278
|
values[point.index] = point.value;
|
|
281
|
-
// A declared domain with missing points is an intentional sparse cache.
|
|
282
|
-
// A zero-length reference cache supplies no domain; Office producers use
|
|
283
|
-
// it as a placeholder until Excel recalculates the worksheet formula.
|
|
284
279
|
if (count || literal || !reference)
|
|
285
280
|
return values;
|
|
286
281
|
}
|
|
@@ -358,8 +353,6 @@ const parseSeries = (chartNode, workbook, blankMode = 'gap') => {
|
|
|
358
353
|
spanBlankIndexes.push(pointIndex);
|
|
359
354
|
return blankMode === 'zero' ? 0 : Number.NaN;
|
|
360
355
|
}
|
|
361
|
-
// Empty cells and error values are not zero. Keep an error as a hard gap,
|
|
362
|
-
// even when blank cells are explicitly spanned or plotted as zero.
|
|
363
356
|
const number = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(raw) ? Number(raw) : NaN;
|
|
364
357
|
return Number.isFinite(number) ? number : Number.NaN;
|
|
365
358
|
});
|
|
@@ -392,7 +385,6 @@ const parseSeries = (chartNode, workbook, blankMode = 'gap') => {
|
|
|
392
385
|
};
|
|
393
386
|
});
|
|
394
387
|
};
|
|
395
|
-
/** DrawingML font sizes are hundredths of a point, not SVG viewport units. */
|
|
396
388
|
const parseAxisFontSize = (axis, chartSpace) => {
|
|
397
389
|
var _a;
|
|
398
390
|
const size = (node) => {
|
|
@@ -457,6 +449,7 @@ const parseDrawingCharts = async (zip, drawingPart, workbook) => {
|
|
|
457
449
|
if (!chart || !chart.series.length || chart.series.every((series) => !series.values.length)) {
|
|
458
450
|
return null;
|
|
459
451
|
}
|
|
452
|
+
const sourceAnchor = readSourceAnchor(anchor, chartReference, 'chart');
|
|
460
453
|
const from = parseMarker(firstChildByLocal(anchor, 'from')) || {
|
|
461
454
|
row: 0,
|
|
462
455
|
col: 0,
|
|
@@ -468,6 +461,8 @@ const parseDrawingCharts = async (zip, drawingPart, workbook) => {
|
|
|
468
461
|
const name = (_a = firstByLocal(anchor, 'cNvPr')) === null || _a === void 0 ? void 0 : _a.getAttribute('name');
|
|
469
462
|
return {
|
|
470
463
|
...chart,
|
|
464
|
+
sourceAnchor,
|
|
465
|
+
rowAnchor: createDrawingRowAnchor(localName(anchor), anchor.getAttribute('editAs'), from, to),
|
|
471
466
|
id: name || chartRelationship.target || `chart-${index + 1}`,
|
|
472
467
|
from,
|
|
473
468
|
to,
|
|
@@ -500,21 +495,15 @@ export const parseSpreadsheetCharts = async (data, workbook) => {
|
|
|
500
495
|
if (!name || !(worksheetRelationship === null || worksheetRelationship === void 0 ? void 0 : worksheetRelationship.type.endsWith(WORKSHEET_RELATIONSHIP_SUFFIX))) {
|
|
501
496
|
continue;
|
|
502
497
|
}
|
|
503
|
-
// A missing <col> uses the worksheet's stored/default geometry, rather
|
|
504
|
-
// than content auto-fit. Keep this metadata even when there are no charts.
|
|
505
498
|
const worksheet = (_a = workbook === null || workbook === void 0 ? void 0 : workbook.Sheets) === null || _a === void 0 ? void 0 : _a[name];
|
|
506
499
|
if (worksheet) {
|
|
507
500
|
worksheet['!fileViewerLayout'] = {};
|
|
508
501
|
worksheet['!fileViewerLayout'] = {
|
|
509
502
|
...await readStoredSheetLayout(zip, worksheetRelationship.target),
|
|
510
|
-
maximumDigitWidth
|
|
503
|
+
maximumDigitWidth,
|
|
504
|
+
rowSizing: await readStoredRowSizing(zip, worksheetRelationship.target)
|
|
511
505
|
};
|
|
512
506
|
}
|
|
513
|
-
// A worksheet can expand to hundreds of megabytes even when the drawing
|
|
514
|
-
// relationship part is only a few hundred bytes. Loading sheetN.xml as a
|
|
515
|
-
// string here duplicates the cell parser's work and can exceed V8's string
|
|
516
|
-
// limit before chart parsing starts. Drawing relationships already carry
|
|
517
|
-
// the typed targets needed by the chart parser, so discover them directly.
|
|
518
507
|
const worksheetRelationships = await loadRelationships(zip, worksheetRelationship.target);
|
|
519
508
|
const drawingParts = Array.from(new Set(worksheetRelationships
|
|
520
509
|
.filter((relationship) => relationship.type.endsWith(DRAWING_RELATIONSHIP_SUFFIX))
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import tinycolor from 'tinycolor2';
|
|
2
2
|
export const indexedColors = [
|
|
3
|
-
'FF000000', 'FFFFFFFF', 'FFFF0000', 'FF00FF00', 'FF0000FF', 'FFFFFF00', 'FFFF00FF', 'FF00FFFF',
|
|
4
|
-
'FF000000', 'FFFFFFFF', 'FFFF0000', 'FF00FF00', 'FF0000FF', 'FFFFFF00', 'FFFF00FF', 'FF00FFFF',
|
|
5
|
-
'FF800000', 'FF008000', 'FF000080', 'FF808000', 'FF800080', 'FF008080', 'FFC0C0C0', 'FF808080',
|
|
6
|
-
'FF9999FF', 'FF993366', 'FFFFFFCC', 'FFCCFFFF', 'FF660066', 'FFFF8080', 'FF0066CC', 'FFCCCCFF',
|
|
7
|
-
'FF000080', 'FFFF00FF', 'FFFFFF00', 'FF00FFFF', 'FF800080', 'FF800000', 'FF008080', 'FF0000FF',
|
|
8
|
-
'FF00CCFF', 'FFCCFFFF', 'FFCCFFCC', 'FFFFFF99', 'FF99CCFF', 'FFFF99CC', 'FFCC99FF', 'FFFFCC99',
|
|
9
|
-
'FF3366FF', 'FF33CCCC', 'FF99CC00', 'FFFFCC00', 'FFFF9900', 'FFFF6600', 'FF666699', 'FF969696',
|
|
10
|
-
'FF003366', 'FF339966', 'FF003300', 'FF333300', 'FF993300', 'FF993366', 'FF333399', 'FF333333'
|
|
3
|
+
'FF000000', 'FFFFFFFF', 'FFFF0000', 'FF00FF00', 'FF0000FF', 'FFFFFF00', 'FFFF00FF', 'FF00FFFF',
|
|
4
|
+
'FF000000', 'FFFFFFFF', 'FFFF0000', 'FF00FF00', 'FF0000FF', 'FFFFFF00', 'FFFF00FF', 'FF00FFFF',
|
|
5
|
+
'FF800000', 'FF008000', 'FF000080', 'FF808000', 'FF800080', 'FF008080', 'FFC0C0C0', 'FF808080',
|
|
6
|
+
'FF9999FF', 'FF993366', 'FFFFFFCC', 'FFCCFFFF', 'FF660066', 'FFFF8080', 'FF0066CC', 'FFCCCCFF',
|
|
7
|
+
'FF000080', 'FFFF00FF', 'FFFFFF00', 'FF00FFFF', 'FF800080', 'FF800000', 'FF008080', 'FF0000FF',
|
|
8
|
+
'FF00CCFF', 'FFCCFFFF', 'FFCCFFCC', 'FFFFFF99', 'FF99CCFF', 'FFFF99CC', 'FFCC99FF', 'FFFFCC99',
|
|
9
|
+
'FF3366FF', 'FF33CCCC', 'FF99CC00', 'FFFFCC00', 'FFFF9900', 'FFFF6600', 'FF666699', 'FF969696',
|
|
10
|
+
'FF003366', 'FF339966', 'FF003300', 'FF333300', 'FF993300', 'FF993366', 'FF333399', 'FF333333'
|
|
11
11
|
];
|
|
12
12
|
const HLSMAX = 240;
|
|
13
13
|
const RGBMAX = 0xFF;
|
|
14
|
-
// Excel 主题色的 tint 计算使用微软 HLS 取值范围,和浏览器 HSL 不是同一套刻度。
|
|
15
14
|
function rgb2hls(r, g, b) {
|
|
16
15
|
const maxc = Math.max(r, g, b);
|
|
17
16
|
const minc = Math.min(r, g, b);
|
|
@@ -63,7 +62,6 @@ function tintLuminance(tint, lum) {
|
|
|
63
62
|
}
|
|
64
63
|
return Math.round(lum * (1.0 - tint) + (HLSMAX - HLSMAX * (1.0 - tint)));
|
|
65
64
|
}
|
|
66
|
-
// 根据主题原始色和 tint 还原 Excel 实际显示色。
|
|
67
65
|
export function getTintColor(hex, tint) {
|
|
68
66
|
if (!hex) {
|
|
69
67
|
return hex;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type WorkBook } from 'styled-exceljs';
|
|
2
|
+
import type { SheetComment } from '../type.js';
|
|
3
|
+
export declare const readWorkbookNotes: (workbook: WorkBook) => Record<string, SheetComment[]>;
|
|
4
|
+
export declare const parseSpreadsheetComments: (data: ArrayBuffer, workbook: WorkBook) => Promise<{
|
|
5
|
+
comments: Record<string, SheetComment[]>;
|
|
6
|
+
hasError: boolean;
|
|
7
|
+
}>;
|