@bilig/excel-import 0.14.14
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/LICENSE +1 -0
- package/README.md +165 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +748 -0
- package/dist/index.js.map +1 -0
- package/dist/workbook-import-content-types.d.ts +10 -0
- package/dist/workbook-import-content-types.js +30 -0
- package/dist/workbook-import-content-types.js.map +1 -0
- package/dist/workbook-import-helpers.d.ts +21 -0
- package/dist/workbook-import-helpers.js +77 -0
- package/dist/workbook-import-helpers.js.map +1 -0
- package/dist/workbook-import-preview.d.ts +19 -0
- package/dist/workbook-import-preview.js +12 -0
- package/dist/workbook-import-preview.js.map +1 -0
- package/dist/xlsx-array-formulas.d.ts +6 -0
- package/dist/xlsx-array-formulas.js +186 -0
- package/dist/xlsx-array-formulas.js.map +1 -0
- package/dist/xlsx-axis-entries.d.ts +3 -0
- package/dist/xlsx-axis-entries.js +90 -0
- package/dist/xlsx-axis-entries.js.map +1 -0
- package/dist/xlsx-calculation-settings.d.ts +9 -0
- package/dist/xlsx-calculation-settings.js +198 -0
- package/dist/xlsx-calculation-settings.js.map +1 -0
- package/dist/xlsx-cell-insertion.d.ts +11 -0
- package/dist/xlsx-cell-insertion.js +164 -0
- package/dist/xlsx-cell-insertion.js.map +1 -0
- package/dist/xlsx-cell-metadata.d.ts +15 -0
- package/dist/xlsx-cell-metadata.js +380 -0
- package/dist/xlsx-cell-metadata.js.map +1 -0
- package/dist/xlsx-chart-artifacts.d.ts +7 -0
- package/dist/xlsx-chart-artifacts.js +327 -0
- package/dist/xlsx-chart-artifacts.js.map +1 -0
- package/dist/xlsx-charts.d.ts +4 -0
- package/dist/xlsx-charts.js +671 -0
- package/dist/xlsx-charts.js.map +1 -0
- package/dist/xlsx-comment-vml.d.ts +11 -0
- package/dist/xlsx-comment-vml.js +292 -0
- package/dist/xlsx-comment-vml.js.map +1 -0
- package/dist/xlsx-comments.d.ts +7 -0
- package/dist/xlsx-comments.js +120 -0
- package/dist/xlsx-comments.js.map +1 -0
- package/dist/xlsx-conditional-formats.d.ts +5 -0
- package/dist/xlsx-conditional-formats.js +513 -0
- package/dist/xlsx-conditional-formats.js.map +1 -0
- package/dist/xlsx-control-artifacts.d.ts +7 -0
- package/dist/xlsx-control-artifacts.js +404 -0
- package/dist/xlsx-control-artifacts.js.map +1 -0
- package/dist/xlsx-data-model-artifacts.d.ts +4 -0
- package/dist/xlsx-data-model-artifacts.js +240 -0
- package/dist/xlsx-data-model-artifacts.js.map +1 -0
- package/dist/xlsx-data-table-formulas.d.ts +4 -0
- package/dist/xlsx-data-table-formulas.js +138 -0
- package/dist/xlsx-data-table-formulas.js.map +1 -0
- package/dist/xlsx-defined-names.d.ts +7 -0
- package/dist/xlsx-defined-names.js +292 -0
- package/dist/xlsx-defined-names.js.map +1 -0
- package/dist/xlsx-dimensions.d.ts +4 -0
- package/dist/xlsx-dimensions.js +495 -0
- package/dist/xlsx-dimensions.js.map +1 -0
- package/dist/xlsx-drawing-artifacts.d.ts +7 -0
- package/dist/xlsx-drawing-artifacts.js +477 -0
- package/dist/xlsx-drawing-artifacts.js.map +1 -0
- package/dist/xlsx-escaped-text.d.ts +2 -0
- package/dist/xlsx-escaped-text.js +22 -0
- package/dist/xlsx-escaped-text.js.map +1 -0
- package/dist/xlsx-export-xml.d.ts +8 -0
- package/dist/xlsx-export-xml.js +99 -0
- package/dist/xlsx-export-xml.js.map +1 -0
- package/dist/xlsx-export.d.ts +2 -0
- package/dist/xlsx-export.js +800 -0
- package/dist/xlsx-export.js.map +1 -0
- package/dist/xlsx-external-link-artifacts.d.ts +4 -0
- package/dist/xlsx-external-link-artifacts.js +317 -0
- package/dist/xlsx-external-link-artifacts.js.map +1 -0
- package/dist/xlsx-external-references.d.ts +29 -0
- package/dist/xlsx-external-references.js +356 -0
- package/dist/xlsx-external-references.js.map +1 -0
- package/dist/xlsx-filters.d.ts +4 -0
- package/dist/xlsx-filters.js +273 -0
- package/dist/xlsx-filters.js.map +1 -0
- package/dist/xlsx-formula-translation.d.ts +10 -0
- package/dist/xlsx-formula-translation.js +391 -0
- package/dist/xlsx-formula-translation.js.map +1 -0
- package/dist/xlsx-formulas.d.ts +2 -0
- package/dist/xlsx-formulas.js +136 -0
- package/dist/xlsx-formulas.js.map +1 -0
- package/dist/xlsx-freeze-panes.d.ts +4 -0
- package/dist/xlsx-freeze-panes.js +206 -0
- package/dist/xlsx-freeze-panes.js.map +1 -0
- package/dist/xlsx-hyperlinks.d.ts +5 -0
- package/dist/xlsx-hyperlinks.js +64 -0
- package/dist/xlsx-hyperlinks.js.map +1 -0
- package/dist/xlsx-ignored-errors.d.ts +4 -0
- package/dist/xlsx-ignored-errors.js +106 -0
- package/dist/xlsx-ignored-errors.js.map +1 -0
- package/dist/xlsx-import-cell-styles.d.ts +8 -0
- package/dist/xlsx-import-cell-styles.js +255 -0
- package/dist/xlsx-import-cell-styles.js.map +1 -0
- package/dist/xlsx-import-sheet-metadata.d.ts +40 -0
- package/dist/xlsx-import-sheet-metadata.js +41 -0
- package/dist/xlsx-import-sheet-metadata.js.map +1 -0
- package/dist/xlsx-import-warnings.d.ts +8 -0
- package/dist/xlsx-import-warnings.js +44 -0
- package/dist/xlsx-import-warnings.js.map +1 -0
- package/dist/xlsx-import-workbook-metadata.d.ts +28 -0
- package/dist/xlsx-import-workbook-metadata.js +29 -0
- package/dist/xlsx-import-workbook-metadata.js.map +1 -0
- package/dist/xlsx-macros.d.ts +10 -0
- package/dist/xlsx-macros.js +63 -0
- package/dist/xlsx-macros.js.map +1 -0
- package/dist/xlsx-merge-entries.d.ts +3 -0
- package/dist/xlsx-merge-entries.js +17 -0
- package/dist/xlsx-merge-entries.js.map +1 -0
- package/dist/xlsx-number-formats.d.ts +7 -0
- package/dist/xlsx-number-formats.js +222 -0
- package/dist/xlsx-number-formats.js.map +1 -0
- package/dist/xlsx-pivot-artifacts.d.ts +29 -0
- package/dist/xlsx-pivot-artifacts.js +292 -0
- package/dist/xlsx-pivot-artifacts.js.map +1 -0
- package/dist/xlsx-pivots.d.ts +10 -0
- package/dist/xlsx-pivots.js +589 -0
- package/dist/xlsx-pivots.js.map +1 -0
- package/dist/xlsx-print-page-setup.d.ts +6 -0
- package/dist/xlsx-print-page-setup.js +224 -0
- package/dist/xlsx-print-page-setup.js.map +1 -0
- package/dist/xlsx-printer-settings.d.ts +4 -0
- package/dist/xlsx-printer-settings.js +279 -0
- package/dist/xlsx-printer-settings.js.map +1 -0
- package/dist/xlsx-protected-ranges.d.ts +4 -0
- package/dist/xlsx-protected-ranges.js +183 -0
- package/dist/xlsx-protected-ranges.js.map +1 -0
- package/dist/xlsx-rich-text-artifacts.d.ts +4 -0
- package/dist/xlsx-rich-text-artifacts.js +303 -0
- package/dist/xlsx-rich-text-artifacts.js.map +1 -0
- package/dist/xlsx-sheet-properties.d.ts +4 -0
- package/dist/xlsx-sheet-properties.js +89 -0
- package/dist/xlsx-sheet-properties.js.map +1 -0
- package/dist/xlsx-sheet-protection.d.ts +4 -0
- package/dist/xlsx-sheet-protection.js +153 -0
- package/dist/xlsx-sheet-protection.js.map +1 -0
- package/dist/xlsx-sheet-visibility.d.ts +4 -0
- package/dist/xlsx-sheet-visibility.js +53 -0
- package/dist/xlsx-sheet-visibility.js.map +1 -0
- package/dist/xlsx-slicer-connection-artifacts.d.ts +4 -0
- package/dist/xlsx-slicer-connection-artifacts.js +426 -0
- package/dist/xlsx-slicer-connection-artifacts.js.map +1 -0
- package/dist/xlsx-sorts.d.ts +5 -0
- package/dist/xlsx-sorts.js +216 -0
- package/dist/xlsx-sorts.js.map +1 -0
- package/dist/xlsx-sparklines.d.ts +4 -0
- package/dist/xlsx-sparklines.js +115 -0
- package/dist/xlsx-sparklines.js.map +1 -0
- package/dist/xlsx-style-only-blank-cells.d.ts +3 -0
- package/dist/xlsx-style-only-blank-cells.js +96 -0
- package/dist/xlsx-style-only-blank-cells.js.map +1 -0
- package/dist/xlsx-style-runs.d.ts +12 -0
- package/dist/xlsx-style-runs.js +35 -0
- package/dist/xlsx-style-runs.js.map +1 -0
- package/dist/xlsx-styles.d.ts +25 -0
- package/dist/xlsx-styles.js +857 -0
- package/dist/xlsx-styles.js.map +1 -0
- package/dist/xlsx-tab-colors.d.ts +4 -0
- package/dist/xlsx-tab-colors.js +166 -0
- package/dist/xlsx-tab-colors.js.map +1 -0
- package/dist/xlsx-tables.d.ts +4 -0
- package/dist/xlsx-tables.js +371 -0
- package/dist/xlsx-tables.js.map +1 -0
- package/dist/xlsx-theme-artifacts.d.ts +6 -0
- package/dist/xlsx-theme-artifacts.js +126 -0
- package/dist/xlsx-theme-artifacts.js.map +1 -0
- package/dist/xlsx-threaded-comment-artifacts.d.ts +8 -0
- package/dist/xlsx-threaded-comment-artifacts.js +329 -0
- package/dist/xlsx-threaded-comment-artifacts.js.map +1 -0
- package/dist/xlsx-validations.d.ts +4 -0
- package/dist/xlsx-validations.js +542 -0
- package/dist/xlsx-validations.js.map +1 -0
- package/dist/xlsx-view-state.d.ts +8 -0
- package/dist/xlsx-view-state.js +144 -0
- package/dist/xlsx-view-state.js.map +1 -0
- package/dist/xlsx-workbook-properties.d.ts +5 -0
- package/dist/xlsx-workbook-properties.js +388 -0
- package/dist/xlsx-workbook-properties.js.map +1 -0
- package/dist/xlsx-workbook-protection.d.ts +4 -0
- package/dist/xlsx-workbook-protection.js +147 -0
- package/dist/xlsx-workbook-protection.js.map +1 -0
- package/dist/xlsx-workbook-sheet-paths.d.ts +4 -0
- package/dist/xlsx-workbook-sheet-paths.js +96 -0
- package/dist/xlsx-workbook-sheet-paths.js.map +1 -0
- package/dist/xlsx-worksheet-cells.d.ts +16 -0
- package/dist/xlsx-worksheet-cells.js +104 -0
- package/dist/xlsx-worksheet-cells.js.map +1 -0
- package/dist/xlsx-worksheet-text-values.d.ts +2 -0
- package/dist/xlsx-worksheet-text-values.js +136 -0
- package/dist/xlsx-worksheet-text-values.js.map +1 -0
- package/dist/xlsx-zip.d.ts +6 -0
- package/dist/xlsx-zip.js +12 -0
- package/dist/xlsx-zip.js.map +1 -0
- package/package.json +56 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
import * as XLSX from 'xlsx';
|
|
2
|
+
import { unzipSync } from 'fflate';
|
|
3
|
+
import { parseCsv, parseCsvCellInput, resolveCsvParseOptions } from '@bilig/core';
|
|
4
|
+
import { readImportedArrayFormulaSpills, readImportedWorkbookArrayFormulas } from './xlsx-array-formulas.js';
|
|
5
|
+
import { buildColumnEntries, buildRowEntries } from './xlsx-axis-entries.js';
|
|
6
|
+
import { readImportedWorkbookCalculationSettings, readImportedWorkbookCalculationWarnings } from './xlsx-calculation-settings.js';
|
|
7
|
+
import { buildImportedCellMetadataReferenceSnapshots, readImportedWorkbookCellMetadata } from './xlsx-cell-metadata.js';
|
|
8
|
+
import { readImportedWorkbookChartArtifacts } from './xlsx-chart-artifacts.js';
|
|
9
|
+
import { readImportedWorkbookCharts } from './xlsx-charts.js';
|
|
10
|
+
import { legacyCommentThreadSignature, readImportedWorkbookLegacyCommentVml } from './xlsx-comment-vml.js';
|
|
11
|
+
import { readImportedSheetComments } from './xlsx-comments.js';
|
|
12
|
+
import { readImportedWorkbookConditionalFormatArtifacts, readImportedWorkbookConditionalFormats } from './xlsx-conditional-formats.js';
|
|
13
|
+
import { readImportedWorkbookControlArtifacts } from './xlsx-control-artifacts.js';
|
|
14
|
+
import { readImportedWorkbookDataModelArtifacts } from './xlsx-data-model-artifacts.js';
|
|
15
|
+
import { readImportedWorkbookDataTableFormulas } from './xlsx-data-table-formulas.js';
|
|
16
|
+
import { readImportedDefinedNames } from './xlsx-defined-names.js';
|
|
17
|
+
import { readImportedWorkbookDrawingArtifacts } from './xlsx-drawing-artifacts.js';
|
|
18
|
+
import { readImportedWorkbookExternalLinkArtifacts } from './xlsx-external-link-artifacts.js';
|
|
19
|
+
import { readImportedWorkbookFilters } from './xlsx-filters.js';
|
|
20
|
+
import { readImportedWorksheetFormulas } from './xlsx-formulas.js';
|
|
21
|
+
import { readImportedWorkbookFreezePanes } from './xlsx-freeze-panes.js';
|
|
22
|
+
import { readImportedWorkbookIgnoredErrors } from './xlsx-ignored-errors.js';
|
|
23
|
+
import { buildMergeEntries } from './xlsx-merge-entries.js';
|
|
24
|
+
import { readImportedWorkbookPivots } from './xlsx-pivots.js';
|
|
25
|
+
import { readImportedWorkbookPrintPageSetup } from './xlsx-print-page-setup.js';
|
|
26
|
+
import { readImportedWorkbookPrinterSettings } from './xlsx-printer-settings.js';
|
|
27
|
+
import { readImportedWorkbookProtectedRanges } from './xlsx-protected-ranges.js';
|
|
28
|
+
import { readImportedWorkbookRichTextArtifacts } from './xlsx-rich-text-artifacts.js';
|
|
29
|
+
import { readImportedWorkbookFileNumberFormats } from './xlsx-number-formats.js';
|
|
30
|
+
import { readImportedWorkbookSheetProperties } from './xlsx-sheet-properties.js';
|
|
31
|
+
import { readImportedWorkbookSheetProtections } from './xlsx-sheet-protection.js';
|
|
32
|
+
import { readImportedWorkbookSheetVisibilities } from './xlsx-sheet-visibility.js';
|
|
33
|
+
import { readImportedWorkbookSlicerConnectionArtifacts } from './xlsx-slicer-connection-artifacts.js';
|
|
34
|
+
import { readImportedWorkbookSorts } from './xlsx-sorts.js';
|
|
35
|
+
import { readImportedWorkbookSparklines } from './xlsx-sparklines.js';
|
|
36
|
+
import { stripNoOpEmptyRowsFromXlsx, stripStyleOnlyBlankCellsForSheetJs } from './xlsx-style-only-blank-cells.js';
|
|
37
|
+
import { mergeStyleRuns, styleRunsToRanges } from './xlsx-style-runs.js';
|
|
38
|
+
import { readImportedWorkbookFileStyles, readImportedWorkbookSheetDimensions, readImportedWorkbookStyleArtifacts } from './xlsx-styles.js';
|
|
39
|
+
import { readImportedWorkbookSheetTabColors } from './xlsx-tab-colors.js';
|
|
40
|
+
import { readImportedWorkbookTables } from './xlsx-tables.js';
|
|
41
|
+
import { readImportedWorkbookThreadedCommentArtifacts } from './xlsx-threaded-comment-artifacts.js';
|
|
42
|
+
import { readImportedWorkbookDataValidations } from './xlsx-validations.js';
|
|
43
|
+
import { readImportedWorkbookViewState } from './xlsx-view-state.js';
|
|
44
|
+
import { readImportedWorkbookProtection } from './xlsx-workbook-protection.js';
|
|
45
|
+
import { workbookDirectorySheetPaths, workbookSheetPathsByName } from './xlsx-workbook-sheet-paths.js';
|
|
46
|
+
import { readImportedWorkbookDocumentPropertiesArtifacts, readImportedWorkbookProperties } from './xlsx-workbook-properties.js';
|
|
47
|
+
import { createSheetPreview, normalizeCsvSheetName, normalizeWorkbookName, toDisplayText, toLiteralInput, } from './workbook-import-helpers.js';
|
|
48
|
+
import { CSV_CONTENT_TYPE, LEGACY_XLS_CONTENT_TYPE, XLSB_CONTENT_TYPE, XLSM_CONTENT_TYPE, XLSX_CONTENT_TYPE, normalizeWorkbookImportContentType, } from './workbook-import-content-types.js';
|
|
49
|
+
import { createWorkbookPreview } from './workbook-import-preview.js';
|
|
50
|
+
import { readImportedExternalLinkCaches, translateImportedFormulaExternalReferences } from './xlsx-external-references.js';
|
|
51
|
+
import { normalizeImportedFormulaSource, translateImportedFormulaStructuredReferences } from './xlsx-formula-translation.js';
|
|
52
|
+
import { readImportedSheetHyperlinks } from './xlsx-hyperlinks.js';
|
|
53
|
+
import { collectStyleCandidateAddresses, internImportedStyle, readImportedXlsxCellStyle } from './xlsx-import-cell-styles.js';
|
|
54
|
+
import { buildImportedSheetMetadata } from './xlsx-import-sheet-metadata.js';
|
|
55
|
+
import { buildImportedWorkbookMetadata } from './xlsx-import-workbook-metadata.js';
|
|
56
|
+
import { externalPivotCachesWarning, externalWorkbookReferencesWarning, formulaReferencesExternalWorkbook, formulaReferencesVolatileFunction, macroExecutionDeclinedWarning, volatileFormulasWarning, workbookDefinedNamesReferenceExternalWorkbook, } from './xlsx-import-warnings.js';
|
|
57
|
+
import { createPreservedVbaProjectPayload } from './xlsx-macros.js';
|
|
58
|
+
import { worksheetCellAt, worksheetCellEntries, worksheetCellEntriesAtAddresses } from './xlsx-worksheet-cells.js';
|
|
59
|
+
import { readImportedWorksheetTextValues } from './xlsx-worksheet-text-values.js';
|
|
60
|
+
export { exportXlsx } from './xlsx-export.js';
|
|
61
|
+
export { manualCalculationModeWarning, precisionAsDisplayedCalculationWarning } from './xlsx-calculation-settings.js';
|
|
62
|
+
export { externalPivotCachesWarning, externalWorkbookReferencesWarning, macroExecutionDeclinedWarning, volatileFormulasWarning, } from './xlsx-import-warnings.js';
|
|
63
|
+
export { readImportedXlsxCellStyle } from './xlsx-import-cell-styles.js';
|
|
64
|
+
export { CSV_CONTENT_TYPE, EXCEL_WORKBOOK_IMPORT_CONTENT_TYPES, LEGACY_XLS_CONTENT_TYPE, WORKBOOK_IMPORT_CONTENT_TYPES, XLSB_CONTENT_TYPE, XLSM_CONTENT_TYPE, XLSX_CONTENT_TYPE, normalizeWorkbookImportContentType, } from './workbook-import-content-types.js';
|
|
65
|
+
const largeWorkbookStyleCandidateThreshold = 100_000;
|
|
66
|
+
const legacyExcelErrorTextByCode = new Map([
|
|
67
|
+
[0, '#NULL!'],
|
|
68
|
+
[7, '#DIV/0!'],
|
|
69
|
+
[15, '#VALUE!'],
|
|
70
|
+
[23, '#REF!'],
|
|
71
|
+
[29, '#NAME?'],
|
|
72
|
+
[36, '#NUM!'],
|
|
73
|
+
[42, '#N/A'],
|
|
74
|
+
[43, '#GETTING_DATA'],
|
|
75
|
+
]);
|
|
76
|
+
export class InvalidXlsxZipContainerError extends Error {
|
|
77
|
+
constructor() {
|
|
78
|
+
super('Invalid or corrupt XLSX zip container');
|
|
79
|
+
this.name = 'InvalidXlsxZipContainerError';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function isRecord(value) {
|
|
83
|
+
return typeof value === 'object' && value !== null;
|
|
84
|
+
}
|
|
85
|
+
function readImportedNumberFormat(value) {
|
|
86
|
+
if (typeof value !== 'string') {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
const trimmed = value.trim();
|
|
90
|
+
if (trimmed.length === 0 || trimmed === 'General') {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
return trimmed;
|
|
94
|
+
}
|
|
95
|
+
function toUint8Array(value) {
|
|
96
|
+
if (value instanceof Uint8Array) {
|
|
97
|
+
return new Uint8Array(value);
|
|
98
|
+
}
|
|
99
|
+
if (value instanceof ArrayBuffer) {
|
|
100
|
+
return new Uint8Array(value);
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
function readNonEmptyString(value) {
|
|
105
|
+
if (typeof value !== 'string') {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
const trimmed = value.trim();
|
|
109
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
110
|
+
}
|
|
111
|
+
function readImportedLiteralCellValue(cell) {
|
|
112
|
+
if (cell['t'] === 'e') {
|
|
113
|
+
if (Object.hasOwn(cell, 'w')) {
|
|
114
|
+
const displayText = toLiteralInput(cell['w']);
|
|
115
|
+
if (typeof displayText === 'string' && displayText.startsWith('#')) {
|
|
116
|
+
return displayText;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!Object.hasOwn(cell, 'v')) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
const errorCode = cell['v'];
|
|
123
|
+
if (errorCode === undefined || errorCode === null) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
if (typeof errorCode === 'number') {
|
|
127
|
+
return legacyExcelErrorTextByCode.get(errorCode) ?? '#ERROR!';
|
|
128
|
+
}
|
|
129
|
+
if (typeof errorCode === 'string' && errorCode.startsWith('#')) {
|
|
130
|
+
return errorCode;
|
|
131
|
+
}
|
|
132
|
+
return '#ERROR!';
|
|
133
|
+
}
|
|
134
|
+
return toLiteralInput(cell['v']);
|
|
135
|
+
}
|
|
136
|
+
function compareCellAddresses(left, right) {
|
|
137
|
+
const leftCell = XLSX.utils.decode_cell(left);
|
|
138
|
+
const rightCell = XLSX.utils.decode_cell(right);
|
|
139
|
+
return leftCell.r - rightCell.r || leftCell.c - rightCell.c;
|
|
140
|
+
}
|
|
141
|
+
function addCandidateAddress(addressesBySheet, sheetName, address) {
|
|
142
|
+
const addresses = addressesBySheet.get(sheetName) ?? new Set();
|
|
143
|
+
const previousSize = addresses.size;
|
|
144
|
+
addresses.add(address);
|
|
145
|
+
if (addresses.size > previousSize) {
|
|
146
|
+
addressesBySheet.set(sheetName, addresses);
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
function addStyleArtifactCandidateAddresses(candidates, importedStyleArtifacts, maxCandidateCount) {
|
|
152
|
+
let count = candidates.count;
|
|
153
|
+
const addressesBySheet = new Map([...candidates.addressesBySheet].map(([sheetName, addresses]) => [sheetName, new Set(addresses)]));
|
|
154
|
+
for (const [sheetName, artifacts] of importedStyleArtifacts.sheetArtifactsByName) {
|
|
155
|
+
for (const entry of artifacts.cellStyleIndexes) {
|
|
156
|
+
if (addCandidateAddress(addressesBySheet, sheetName, entry.address)) {
|
|
157
|
+
count += 1;
|
|
158
|
+
}
|
|
159
|
+
if (count > maxCandidateCount) {
|
|
160
|
+
return candidates;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
for (const address of artifacts.blankCellAddresses ?? []) {
|
|
164
|
+
if (addCandidateAddress(addressesBySheet, sheetName, address)) {
|
|
165
|
+
count += 1;
|
|
166
|
+
}
|
|
167
|
+
if (count > maxCandidateCount) {
|
|
168
|
+
return candidates;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { addressesBySheet, count };
|
|
173
|
+
}
|
|
174
|
+
function readImportedMacroCodeNames(workbook) {
|
|
175
|
+
const workbookMetadata = isRecord(workbook.Workbook) ? workbook.Workbook : undefined;
|
|
176
|
+
const workbookProperties = isRecord(workbookMetadata?.['WBProps']) ? workbookMetadata['WBProps'] : undefined;
|
|
177
|
+
const workbookCodeName = readNonEmptyString(workbookProperties?.['CodeName']);
|
|
178
|
+
const workbookSheets = workbookMetadata?.['Sheets'];
|
|
179
|
+
const sheetCodeNames = Array.isArray(workbookSheets)
|
|
180
|
+
? workbookSheets.flatMap((entry) => {
|
|
181
|
+
if (!isRecord(entry)) {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
const sheetName = readNonEmptyString(entry['name']);
|
|
185
|
+
const codeName = readNonEmptyString(entry['CodeName']);
|
|
186
|
+
return sheetName && codeName ? [{ sheetName, codeName }] : [];
|
|
187
|
+
})
|
|
188
|
+
: [];
|
|
189
|
+
return {
|
|
190
|
+
...(workbookCodeName ? { workbookCodeName } : {}),
|
|
191
|
+
...(sheetCodeNames.length > 0 ? { sheetCodeNames } : {}),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function buildImportedLegacyCommentVmlSnapshot(imported, commentThreads) {
|
|
195
|
+
if (!imported) {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
...imported,
|
|
200
|
+
commentSignature: legacyCommentThreadSignature(commentThreads),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function addWorkbookWarnings(workbook, warnings, ignoredDefinedNameCount) {
|
|
204
|
+
if (workbook.vbaraw) {
|
|
205
|
+
warnings.push(macroExecutionDeclinedWarning);
|
|
206
|
+
}
|
|
207
|
+
if (ignoredDefinedNameCount > 0) {
|
|
208
|
+
warnings.push('Some defined names were ignored during XLSX import.');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function readValidXlsxZipContainer(bytes) {
|
|
212
|
+
try {
|
|
213
|
+
return unzipSync(bytes);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
throw new InvalidXlsxZipContainerError();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function importSheetJsWorkbook(data, fileName, contentType, workbookZip) {
|
|
220
|
+
const styleArtifactData = workbookZip ? stripNoOpEmptyRowsFromXlsx(data, workbookZip) : data;
|
|
221
|
+
const parserData = workbookZip ? stripStyleOnlyBlankCellsForSheetJs(styleArtifactData, workbookZip) : data;
|
|
222
|
+
const workbook = XLSX.read(parserData, {
|
|
223
|
+
type: 'array',
|
|
224
|
+
cellFormula: true,
|
|
225
|
+
cellNF: true,
|
|
226
|
+
cellStyles: false,
|
|
227
|
+
cellText: false,
|
|
228
|
+
cellDates: false,
|
|
229
|
+
bookFiles: true,
|
|
230
|
+
bookVBA: true,
|
|
231
|
+
dense: false,
|
|
232
|
+
});
|
|
233
|
+
const workbookName = normalizeWorkbookName(fileName);
|
|
234
|
+
const sheetPathsByName = workbookSheetPathsByName(workbook);
|
|
235
|
+
const fallbackSheetPaths = workbookDirectorySheetPaths(workbook);
|
|
236
|
+
const warnings = [];
|
|
237
|
+
const importedDefinedNames = readImportedDefinedNames(workbook);
|
|
238
|
+
addWorkbookWarnings(workbook, warnings, importedDefinedNames.ignoredCount);
|
|
239
|
+
if (workbookDefinedNamesReferenceExternalWorkbook(workbook)) {
|
|
240
|
+
warnings.push(externalWorkbookReferencesWarning);
|
|
241
|
+
}
|
|
242
|
+
const styleArtifactSource = contentType === XLSX_CONTENT_TYPE || contentType === XLSM_CONTENT_TYPE ? styleArtifactData : undefined;
|
|
243
|
+
const importedStyleArtifacts = readImportedWorkbookStyleArtifacts(workbook, workbook.SheetNames, styleArtifactSource);
|
|
244
|
+
const baseStyleCandidates = collectStyleCandidateAddresses(workbook, workbook.SheetNames, largeWorkbookStyleCandidateThreshold);
|
|
245
|
+
const styleCandidates = addStyleArtifactCandidateAddresses(baseStyleCandidates, importedStyleArtifacts, largeWorkbookStyleCandidateThreshold);
|
|
246
|
+
const importedWorkbookStyles = styleCandidates.count === 0 || styleCandidates.count > largeWorkbookStyleCandidateThreshold
|
|
247
|
+
? new Map()
|
|
248
|
+
: readImportedWorkbookFileStyles(workbook, workbook.SheetNames, {
|
|
249
|
+
styleCandidateAddressesBySheet: styleCandidates.addressesBySheet,
|
|
250
|
+
}, styleArtifactSource);
|
|
251
|
+
const importedWorkbookNumberFormats = styleCandidates.count === 0 || styleCandidates.count > largeWorkbookStyleCandidateThreshold
|
|
252
|
+
? new Map()
|
|
253
|
+
: readImportedWorkbookFileNumberFormats(workbook, workbook.SheetNames, {
|
|
254
|
+
formatCandidateAddressesBySheet: styleCandidates.addressesBySheet,
|
|
255
|
+
}, styleArtifactSource);
|
|
256
|
+
const importedWorkbookSheetDimensions = readImportedWorkbookSheetDimensions(workbook, workbook.SheetNames);
|
|
257
|
+
const importedWorkbookProperties = workbookZip ? readImportedWorkbookProperties(workbookZip) : undefined;
|
|
258
|
+
const importedWorkbookDocumentProperties = workbookZip ? readImportedWorkbookDocumentPropertiesArtifacts(workbookZip) : undefined;
|
|
259
|
+
const importedWorkbookProtection = workbookZip ? readImportedWorkbookProtection(workbookZip) : undefined;
|
|
260
|
+
const importedCalculationSettings = workbookZip ? readImportedWorkbookCalculationSettings(workbookZip) : undefined;
|
|
261
|
+
const importedMacroPayload = toUint8Array(workbook.vbaraw);
|
|
262
|
+
const importedMacroCodeNames = importedMacroPayload ? readImportedMacroCodeNames(workbook) : undefined;
|
|
263
|
+
const importedCellMetadata = workbookZip ? readImportedWorkbookCellMetadata(workbookZip, workbook.SheetNames) : undefined;
|
|
264
|
+
const importedChartArtifacts = workbookZip ? readImportedWorkbookChartArtifacts(workbookZip) : undefined;
|
|
265
|
+
const importedCharts = workbookZip ? readImportedWorkbookCharts(workbookZip, workbook.SheetNames) : undefined;
|
|
266
|
+
const importedTables = workbookZip ? readImportedWorkbookTables(workbookZip, workbook.SheetNames) : undefined;
|
|
267
|
+
const importedDrawingArtifacts = workbookZip ? readImportedWorkbookDrawingArtifacts(workbookZip, workbook.SheetNames) : undefined;
|
|
268
|
+
const importedControlArtifacts = workbookZip ? readImportedWorkbookControlArtifacts(workbookZip, workbook.SheetNames) : undefined;
|
|
269
|
+
const importedDataModelArtifacts = workbookZip ? readImportedWorkbookDataModelArtifacts(workbookZip) : undefined;
|
|
270
|
+
const importedExternalLinkArtifacts = workbookZip ? readImportedWorkbookExternalLinkArtifacts(workbookZip) : undefined;
|
|
271
|
+
const importedSlicerConnectionArtifacts = workbookZip
|
|
272
|
+
? readImportedWorkbookSlicerConnectionArtifacts(workbookZip, workbook.SheetNames)
|
|
273
|
+
: undefined;
|
|
274
|
+
const importedArrayFormulasBySheet = workbookZip ? readImportedWorkbookArrayFormulas(workbookZip, workbook.SheetNames) : new Map();
|
|
275
|
+
const importedDataTableFormulasBySheet = workbookZip ? readImportedWorkbookDataTableFormulas(workbookZip, workbook.SheetNames) : new Map();
|
|
276
|
+
const importedPivots = workbookZip
|
|
277
|
+
? readImportedWorkbookPivots(workbookZip, workbook.SheetNames, importedTables, importedDefinedNames.definedNames)
|
|
278
|
+
: undefined;
|
|
279
|
+
if (importedPivots?.hasExternalPivotCaches) {
|
|
280
|
+
warnings.push(externalPivotCachesWarning);
|
|
281
|
+
}
|
|
282
|
+
const importedLegacyCommentVmlBySheet = workbookZip ? readImportedWorkbookLegacyCommentVml(workbookZip, workbook.SheetNames) : new Map();
|
|
283
|
+
const importedPrinterSettingsBySheet = workbookZip ? readImportedWorkbookPrinterSettings(workbookZip, workbook.SheetNames) : new Map();
|
|
284
|
+
const importedPrintPageSetupBySheet = workbookZip ? readImportedWorkbookPrintPageSetup(workbookZip, workbook.SheetNames) : new Map();
|
|
285
|
+
const importedFiltersBySheet = workbookZip ? readImportedWorkbookFilters(workbookZip, workbook.SheetNames) : new Map();
|
|
286
|
+
const importedFreezePanesBySheet = workbookZip ? readImportedWorkbookFreezePanes(workbookZip, workbook.SheetNames) : new Map();
|
|
287
|
+
const importedSheetTabColorsBySheet = workbookZip ? readImportedWorkbookSheetTabColors(workbookZip, workbook.SheetNames) : new Map();
|
|
288
|
+
const importedSheetPropertiesBySheet = workbookZip ? readImportedWorkbookSheetProperties(workbookZip, workbook.SheetNames) : new Map();
|
|
289
|
+
const importedIgnoredErrorsBySheet = workbookZip ? readImportedWorkbookIgnoredErrors(workbookZip, workbook.SheetNames) : new Map();
|
|
290
|
+
const importedSparklinesBySheet = workbookZip ? readImportedWorkbookSparklines(workbookZip, workbook.SheetNames) : new Map();
|
|
291
|
+
const importedSheetVisibilitiesBySheet = readImportedWorkbookSheetVisibilities(workbook, workbook.SheetNames);
|
|
292
|
+
const importedSheetProtectionsBySheet = workbookZip ? readImportedWorkbookSheetProtections(workbookZip, workbook.SheetNames) : new Map();
|
|
293
|
+
const importedProtectedRangesBySheet = workbookZip ? readImportedWorkbookProtectedRanges(workbookZip, workbook.SheetNames) : new Map();
|
|
294
|
+
const importedSortsBySheet = workbookZip ? readImportedWorkbookSorts(workbookZip, workbook.SheetNames) : new Map();
|
|
295
|
+
const importedValidationsBySheet = workbookZip ? readImportedWorkbookDataValidations(workbookZip, workbook.SheetNames) : new Map();
|
|
296
|
+
const conditionalFormatArtifactSource = contentType === XLSX_CONTENT_TYPE || contentType === XLSM_CONTENT_TYPE ? data : workbookZip;
|
|
297
|
+
const importedConditionalFormatsBySheet = conditionalFormatArtifactSource
|
|
298
|
+
? readImportedWorkbookConditionalFormats(conditionalFormatArtifactSource, workbook.SheetNames)
|
|
299
|
+
: new Map();
|
|
300
|
+
const importedConditionalFormatArtifactsBySheet = conditionalFormatArtifactSource
|
|
301
|
+
? readImportedWorkbookConditionalFormatArtifacts(conditionalFormatArtifactSource, workbook.SheetNames)
|
|
302
|
+
: new Map();
|
|
303
|
+
const importedExternalLinkCaches = workbookZip ? readImportedExternalLinkCaches(workbookZip) : new Map();
|
|
304
|
+
const importedRichTextArtifactsBySheet = workbookZip ? readImportedWorkbookRichTextArtifacts(workbookZip, workbook.SheetNames) : new Map();
|
|
305
|
+
const importedWorksheetTextValuesBySheet = workbookZip
|
|
306
|
+
? readImportedWorksheetTextValues(workbookZip, workbook.SheetNames, sheetPathsByName, fallbackSheetPaths)
|
|
307
|
+
: new Map();
|
|
308
|
+
const importedWorksheetFormulasBySheet = workbookZip
|
|
309
|
+
? readImportedWorksheetFormulas(workbookZip, workbook.SheetNames, sheetPathsByName, fallbackSheetPaths)
|
|
310
|
+
: new Map();
|
|
311
|
+
const importedThreadedCommentArtifacts = workbookZip
|
|
312
|
+
? readImportedWorkbookThreadedCommentArtifacts(workbookZip, workbook.SheetNames)
|
|
313
|
+
: undefined;
|
|
314
|
+
const importedViewState = workbookZip ? readImportedWorkbookViewState(workbookZip, workbook.SheetNames) : undefined;
|
|
315
|
+
const chartSheetNames = new Set((importedChartArtifacts?.chartSheetArtifacts ?? []).map((artifact) => artifact.name));
|
|
316
|
+
let ignoredCommentsSeen = false;
|
|
317
|
+
let externalWorkbookReferenceWarningSeen = warnings.includes(externalWorkbookReferencesWarning);
|
|
318
|
+
let volatileFormulaWarningSeen = false;
|
|
319
|
+
let formulaCellSeen = false;
|
|
320
|
+
const styleCatalog = new Map();
|
|
321
|
+
const importedArrayFormulaSpills = [];
|
|
322
|
+
const previewSheets = [];
|
|
323
|
+
const sheets = workbook.SheetNames.map((sheetName, order) => {
|
|
324
|
+
const sheet = chartSheetNames.has(sheetName) ? undefined : workbook.Sheets[sheetName];
|
|
325
|
+
if (!sheet) {
|
|
326
|
+
previewSheets.push(createSheetPreview({
|
|
327
|
+
name: sheetName,
|
|
328
|
+
rowCount: 0,
|
|
329
|
+
columnCount: 0,
|
|
330
|
+
nonEmptyCellCount: 0,
|
|
331
|
+
readCellText: () => '',
|
|
332
|
+
}));
|
|
333
|
+
return {
|
|
334
|
+
id: order + 1,
|
|
335
|
+
name: sheetName,
|
|
336
|
+
order,
|
|
337
|
+
cells: [],
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
const importedComments = readImportedSheetComments(sheetName, sheet);
|
|
341
|
+
const importedWorksheetTextValues = importedWorksheetTextValuesBySheet.get(sheetName);
|
|
342
|
+
const importedWorksheetFormulas = importedWorksheetFormulasBySheet.get(sheetName);
|
|
343
|
+
const importedHyperlinks = readImportedSheetHyperlinks(sheetName, sheet);
|
|
344
|
+
if (importedComments.ignoredCount > 0 && !ignoredCommentsSeen) {
|
|
345
|
+
ignoredCommentsSeen = true;
|
|
346
|
+
warnings.push('Some cell comments were ignored during XLSX import.');
|
|
347
|
+
}
|
|
348
|
+
const importedLegacyCommentVml = importedComments.commentThreads
|
|
349
|
+
? buildImportedLegacyCommentVmlSnapshot(importedLegacyCommentVmlBySheet.get(sheetName), importedComments.commentThreads)
|
|
350
|
+
: undefined;
|
|
351
|
+
const importedArrayFormulaSheetSpills = readImportedArrayFormulaSpills(sheetName, sheet);
|
|
352
|
+
if (importedArrayFormulaSheetSpills) {
|
|
353
|
+
importedArrayFormulaSpills.push(...importedArrayFormulaSheetSpills);
|
|
354
|
+
}
|
|
355
|
+
const range = sheet['!ref'] ? XLSX.utils.decode_range(sheet['!ref']) : null;
|
|
356
|
+
const cells = [];
|
|
357
|
+
const styleRuns = [];
|
|
358
|
+
let openStyleRunsByKey = new Map();
|
|
359
|
+
let activeStyleRow = null;
|
|
360
|
+
let activeStyleRun = null;
|
|
361
|
+
let activeStyleRowRuns = [];
|
|
362
|
+
const importedStylesByAddress = importedWorkbookStyles.get(sheetName);
|
|
363
|
+
const importedFormatsByAddress = importedWorkbookNumberFormats.get(sheetName);
|
|
364
|
+
const flushActiveStyleRun = () => {
|
|
365
|
+
if (activeStyleRun) {
|
|
366
|
+
activeStyleRowRuns.push(activeStyleRun);
|
|
367
|
+
activeStyleRun = null;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
const flushActiveStyleRow = () => {
|
|
371
|
+
if (activeStyleRow === null) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
flushActiveStyleRun();
|
|
375
|
+
openStyleRunsByKey = mergeStyleRuns(activeStyleRow, activeStyleRowRuns, openStyleRunsByKey, styleRuns);
|
|
376
|
+
activeStyleRowRuns = [];
|
|
377
|
+
activeStyleRow = null;
|
|
378
|
+
};
|
|
379
|
+
const addStyleCell = (row, column, styleId) => {
|
|
380
|
+
if (activeStyleRow === null) {
|
|
381
|
+
activeStyleRow = row;
|
|
382
|
+
}
|
|
383
|
+
else if (activeStyleRow !== row) {
|
|
384
|
+
flushActiveStyleRow();
|
|
385
|
+
activeStyleRow = row;
|
|
386
|
+
}
|
|
387
|
+
if (activeStyleRun && activeStyleRun.styleId === styleId && activeStyleRun.endColumn + 1 === column) {
|
|
388
|
+
activeStyleRun.endColumn = column;
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
flushActiveStyleRun();
|
|
392
|
+
activeStyleRun = {
|
|
393
|
+
styleId,
|
|
394
|
+
startColumn: column,
|
|
395
|
+
endColumn: column,
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
const rowCount = range ? range.e.r + 1 : 0;
|
|
399
|
+
const columnCount = range ? range.e.c + 1 : 0;
|
|
400
|
+
const importableAddresses = styleCandidates.count <= largeWorkbookStyleCandidateThreshold ? styleCandidates.addressesBySheet.get(sheetName) : undefined;
|
|
401
|
+
const sheetCellEntries = range
|
|
402
|
+
? importableAddresses
|
|
403
|
+
? worksheetCellEntriesAtAddresses(sheet, importableAddresses)
|
|
404
|
+
: worksheetCellEntries(sheet)
|
|
405
|
+
: [];
|
|
406
|
+
const seenCellAddresses = new Set();
|
|
407
|
+
for (const { address, cell, row, column } of sheetCellEntries) {
|
|
408
|
+
seenCellAddresses.add(address);
|
|
409
|
+
const nextCell = { address };
|
|
410
|
+
const formula = importedWorksheetFormulas?.get(address) ?? cell['f'];
|
|
411
|
+
const xmlTextValue = importedWorksheetTextValues?.get(address);
|
|
412
|
+
if (typeof formula === 'string' && formula.trim().length > 0) {
|
|
413
|
+
const normalizedFormula = normalizeImportedFormulaSource(formula);
|
|
414
|
+
formulaCellSeen = true;
|
|
415
|
+
const externalReferenceTranslation = translateImportedFormulaExternalReferences(normalizedFormula, importedExternalLinkCaches);
|
|
416
|
+
if (!externalWorkbookReferenceWarningSeen &&
|
|
417
|
+
(externalReferenceTranslation.unresolvedCount > 0 || formulaReferencesExternalWorkbook(externalReferenceTranslation.formula))) {
|
|
418
|
+
externalWorkbookReferenceWarningSeen = true;
|
|
419
|
+
warnings.push(externalWorkbookReferencesWarning);
|
|
420
|
+
}
|
|
421
|
+
if (!volatileFormulaWarningSeen && formulaReferencesVolatileFunction(normalizedFormula)) {
|
|
422
|
+
volatileFormulaWarningSeen = true;
|
|
423
|
+
warnings.push(volatileFormulasWarning);
|
|
424
|
+
}
|
|
425
|
+
nextCell.formula = translateImportedFormulaStructuredReferences({
|
|
426
|
+
formula: externalReferenceTranslation.formula,
|
|
427
|
+
ownerSheetName: sheetName,
|
|
428
|
+
ownerAddress: address,
|
|
429
|
+
tables: importedTables,
|
|
430
|
+
});
|
|
431
|
+
const cachedLiteral = xmlTextValue ?? readImportedLiteralCellValue(cell);
|
|
432
|
+
if (cachedLiteral !== undefined) {
|
|
433
|
+
nextCell.value = cachedLiteral;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
const literal = xmlTextValue ?? readImportedLiteralCellValue(cell);
|
|
438
|
+
if (literal !== undefined) {
|
|
439
|
+
nextCell.value = literal;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
const importedFormat = readImportedNumberFormat(cell['z']) ?? importedFormatsByAddress?.get(address);
|
|
443
|
+
if (importedFormat !== undefined) {
|
|
444
|
+
nextCell.format = importedFormat;
|
|
445
|
+
}
|
|
446
|
+
const importedStyle = importedStylesByAddress?.get(address) ?? readImportedXlsxCellStyle(cell['s']);
|
|
447
|
+
if (importedStyle) {
|
|
448
|
+
addStyleCell(row, column, internImportedStyle(importedStyle, styleCatalog));
|
|
449
|
+
}
|
|
450
|
+
else if (activeStyleRow === row) {
|
|
451
|
+
flushActiveStyleRun();
|
|
452
|
+
}
|
|
453
|
+
if (nextCell.value !== undefined || nextCell.formula !== undefined || nextCell.format !== undefined) {
|
|
454
|
+
cells.push(nextCell);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
const missingStyledAddresses = new Set([...(importedStylesByAddress?.keys() ?? []), ...(importedFormatsByAddress?.keys() ?? [])]);
|
|
458
|
+
for (const missingAddress of [...missingStyledAddresses]
|
|
459
|
+
.filter((candidateAddress) => !seenCellAddresses.has(candidateAddress))
|
|
460
|
+
.toSorted(compareCellAddresses)) {
|
|
461
|
+
const decoded = XLSX.utils.decode_cell(missingAddress);
|
|
462
|
+
seenCellAddresses.add(missingAddress);
|
|
463
|
+
const importedStyle = importedStylesByAddress?.get(missingAddress);
|
|
464
|
+
if (importedStyle) {
|
|
465
|
+
addStyleCell(decoded.r, decoded.c, internImportedStyle(importedStyle, styleCatalog));
|
|
466
|
+
}
|
|
467
|
+
else if (activeStyleRow === decoded.r) {
|
|
468
|
+
flushActiveStyleRun();
|
|
469
|
+
}
|
|
470
|
+
const importedFormat = importedFormatsByAddress?.get(missingAddress);
|
|
471
|
+
if (importedFormat !== undefined) {
|
|
472
|
+
cells.push({ address: missingAddress, format: importedFormat });
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
for (const [address, value] of importedWorksheetTextValues ?? []) {
|
|
476
|
+
if (!seenCellAddresses.has(address)) {
|
|
477
|
+
cells.push({ address, value });
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
flushActiveStyleRow();
|
|
481
|
+
const styleRanges = styleRunsToRanges(sheetName, styleRuns);
|
|
482
|
+
previewSheets.push(createSheetPreview({
|
|
483
|
+
name: sheetName,
|
|
484
|
+
rowCount,
|
|
485
|
+
columnCount,
|
|
486
|
+
nonEmptyCellCount: cells.length,
|
|
487
|
+
readCellText: (row, col) => {
|
|
488
|
+
const cell = worksheetCellAt(sheet, row, col);
|
|
489
|
+
if (!cell) {
|
|
490
|
+
return '';
|
|
491
|
+
}
|
|
492
|
+
const address = XLSX.utils.encode_cell({ r: row, c: col });
|
|
493
|
+
const formula = importedWorksheetFormulas?.get(address) ?? cell['f'];
|
|
494
|
+
if (typeof formula === 'string' && formula.trim().length > 0) {
|
|
495
|
+
return `=${normalizeImportedFormulaSource(formula)}`;
|
|
496
|
+
}
|
|
497
|
+
return toDisplayText(readImportedLiteralCellValue(cell) ?? importedWorksheetTextValues?.get(address));
|
|
498
|
+
},
|
|
499
|
+
}));
|
|
500
|
+
const importedSheetDimensions = importedWorkbookSheetDimensions.get(sheetName);
|
|
501
|
+
const rows = importedSheetDimensions?.rows ?? buildRowEntries(sheet['!rows']);
|
|
502
|
+
const columns = importedSheetDimensions ? importedSheetDimensions.columns : buildColumnEntries(sheet['!cols']);
|
|
503
|
+
const rowMetadata = importedSheetDimensions?.rowMetadata;
|
|
504
|
+
const columnMetadata = importedSheetDimensions?.columnMetadata;
|
|
505
|
+
const sheetFormatPr = importedSheetDimensions?.sheetFormatPr;
|
|
506
|
+
const importedFreezePane = importedFreezePanesBySheet.get(sheetName);
|
|
507
|
+
const importedSheetTabColor = importedSheetTabColorsBySheet.get(sheetName);
|
|
508
|
+
const importedSheetPr = importedSheetPropertiesBySheet.get(sheetName);
|
|
509
|
+
const importedIgnoredErrors = importedIgnoredErrorsBySheet.get(sheetName);
|
|
510
|
+
const importedSparklines = importedSparklinesBySheet.get(sheetName);
|
|
511
|
+
const importedStyleArtifactsForSheet = importedStyleArtifacts.sheetArtifactsByName.get(sheetName);
|
|
512
|
+
const importedPivotArtifacts = importedPivots?.sheetArtifactsByName.get(sheetName);
|
|
513
|
+
const importedDrawingArtifactsForSheet = importedDrawingArtifacts?.sheetArtifactsByName.get(sheetName);
|
|
514
|
+
const importedControlArtifactsForSheet = importedControlArtifacts?.sheetArtifactsByName.get(sheetName);
|
|
515
|
+
const importedArrayFormulasForSheet = importedArrayFormulasBySheet.get(sheetName);
|
|
516
|
+
const importedDataTableFormulasForSheet = importedDataTableFormulasBySheet.get(sheetName);
|
|
517
|
+
const importedSheetVisibility = importedSheetVisibilitiesBySheet.get(sheetName);
|
|
518
|
+
const merges = buildMergeEntries(sheetName, sheet['!merges']);
|
|
519
|
+
const importedSheetProtection = importedSheetProtectionsBySheet.get(sheetName);
|
|
520
|
+
const importedProtectedRanges = importedProtectedRangesBySheet.get(sheetName);
|
|
521
|
+
const importedSorts = importedSortsBySheet.get(sheetName);
|
|
522
|
+
const importedFilters = importedFiltersBySheet.get(sheetName);
|
|
523
|
+
const importedValidations = importedValidationsBySheet.get(sheetName);
|
|
524
|
+
const importedConditionalFormats = importedConditionalFormatsBySheet.get(sheetName);
|
|
525
|
+
const importedConditionalFormatArtifacts = importedConditionalFormatArtifactsBySheet.get(sheetName);
|
|
526
|
+
const importedPrinterSettings = importedPrinterSettingsBySheet.get(sheetName);
|
|
527
|
+
const importedPrintPageSetup = importedPrintPageSetupBySheet.get(sheetName);
|
|
528
|
+
const importedCellMetadataRefs = buildImportedCellMetadataReferenceSnapshots(importedCellMetadata?.refsBySheet.get(sheetName), cells);
|
|
529
|
+
const importedRichTextArtifacts = importedRichTextArtifactsBySheet.get(sheetName);
|
|
530
|
+
const importedThreadedCommentArtifactsForSheet = importedThreadedCommentArtifacts?.sheetArtifactsByName.get(sheetName);
|
|
531
|
+
const importedViewStateForSheet = importedViewState?.sheetViewStateByName.get(sheetName);
|
|
532
|
+
const metadata = buildImportedSheetMetadata({
|
|
533
|
+
rows,
|
|
534
|
+
columns,
|
|
535
|
+
rowMetadata,
|
|
536
|
+
columnMetadata,
|
|
537
|
+
sheetFormatPr,
|
|
538
|
+
...(styleRanges.length > 0 ? { styleRanges } : {}),
|
|
539
|
+
freezePane: importedFreezePane,
|
|
540
|
+
tabColor: importedSheetTabColor,
|
|
541
|
+
sheetPr: importedSheetPr,
|
|
542
|
+
ignoredErrors: importedIgnoredErrors,
|
|
543
|
+
sparklines: importedSparklines,
|
|
544
|
+
styleArtifacts: importedStyleArtifactsForSheet,
|
|
545
|
+
pivotArtifacts: importedPivotArtifacts,
|
|
546
|
+
drawingArtifacts: importedDrawingArtifactsForSheet,
|
|
547
|
+
controlArtifacts: importedControlArtifactsForSheet,
|
|
548
|
+
arrayFormulas: importedArrayFormulasForSheet,
|
|
549
|
+
dataTableFormulas: importedDataTableFormulasForSheet,
|
|
550
|
+
visibility: importedSheetVisibility,
|
|
551
|
+
merges,
|
|
552
|
+
sheetProtection: importedSheetProtection,
|
|
553
|
+
protectedRanges: importedProtectedRanges,
|
|
554
|
+
sorts: importedSorts,
|
|
555
|
+
filters: importedFilters,
|
|
556
|
+
validations: importedValidations,
|
|
557
|
+
conditionalFormats: importedConditionalFormats,
|
|
558
|
+
conditionalFormatArtifacts: importedConditionalFormatArtifacts,
|
|
559
|
+
commentThreads: importedComments.commentThreads,
|
|
560
|
+
legacyCommentVml: importedLegacyCommentVml,
|
|
561
|
+
hyperlinks: importedHyperlinks,
|
|
562
|
+
printerSettings: importedPrinterSettings,
|
|
563
|
+
printPageSetup: importedPrintPageSetup,
|
|
564
|
+
cellMetadataRefs: importedCellMetadataRefs,
|
|
565
|
+
richTextArtifacts: importedRichTextArtifacts,
|
|
566
|
+
threadedCommentArtifacts: importedThreadedCommentArtifactsForSheet,
|
|
567
|
+
viewState: importedViewStateForSheet,
|
|
568
|
+
});
|
|
569
|
+
return {
|
|
570
|
+
id: order + 1,
|
|
571
|
+
name: sheetName,
|
|
572
|
+
order,
|
|
573
|
+
...(metadata ? { metadata } : {}),
|
|
574
|
+
cells,
|
|
575
|
+
};
|
|
576
|
+
});
|
|
577
|
+
if (workbookZip) {
|
|
578
|
+
warnings.push(...readImportedWorkbookCalculationWarnings(workbookZip, { hasFormulaCells: formulaCellSeen }));
|
|
579
|
+
}
|
|
580
|
+
const workbookMetadata = buildImportedWorkbookMetadata({
|
|
581
|
+
properties: importedWorkbookProperties,
|
|
582
|
+
documentPropertyArtifacts: importedWorkbookDocumentProperties,
|
|
583
|
+
workbookProtection: importedWorkbookProtection,
|
|
584
|
+
calculationSettings: importedCalculationSettings,
|
|
585
|
+
macroPayloads: importedMacroPayload ? [createPreservedVbaProjectPayload(importedMacroPayload, importedMacroCodeNames)] : undefined,
|
|
586
|
+
styles: styleCatalog.size > 0 ? [...styleCatalog.values()] : undefined,
|
|
587
|
+
definedNames: importedDefinedNames.definedNames,
|
|
588
|
+
tables: importedTables,
|
|
589
|
+
spills: importedArrayFormulaSpills.length > 0 ? importedArrayFormulaSpills : undefined,
|
|
590
|
+
pivots: importedPivots?.pivots,
|
|
591
|
+
pivotArtifacts: importedPivots?.artifacts,
|
|
592
|
+
drawingArtifacts: importedDrawingArtifacts?.artifacts,
|
|
593
|
+
chartArtifacts: importedChartArtifacts?.artifacts,
|
|
594
|
+
chartSheetArtifacts: importedChartArtifacts?.chartSheetArtifacts,
|
|
595
|
+
controlArtifacts: importedControlArtifacts?.artifacts,
|
|
596
|
+
dataModelArtifacts: importedDataModelArtifacts,
|
|
597
|
+
externalLinkArtifacts: importedExternalLinkArtifacts,
|
|
598
|
+
slicerConnectionArtifacts: importedSlicerConnectionArtifacts,
|
|
599
|
+
threadedCommentArtifacts: importedThreadedCommentArtifacts?.artifacts,
|
|
600
|
+
viewState: importedViewState?.workbookViewState,
|
|
601
|
+
charts: importedCharts,
|
|
602
|
+
styleArtifacts: importedStyleArtifacts.workbookArtifacts,
|
|
603
|
+
cellMetadata: importedCellMetadata?.workbookMetadata,
|
|
604
|
+
});
|
|
605
|
+
return {
|
|
606
|
+
snapshot: {
|
|
607
|
+
version: 1,
|
|
608
|
+
workbook: {
|
|
609
|
+
name: workbookName,
|
|
610
|
+
...(workbookMetadata ? { metadata: workbookMetadata } : {}),
|
|
611
|
+
},
|
|
612
|
+
sheets,
|
|
613
|
+
},
|
|
614
|
+
workbookName,
|
|
615
|
+
sheetNames: workbook.SheetNames,
|
|
616
|
+
warnings,
|
|
617
|
+
preview: createWorkbookPreview({
|
|
618
|
+
contentType,
|
|
619
|
+
fileName,
|
|
620
|
+
fileSizeBytes: data.byteLength,
|
|
621
|
+
workbookName,
|
|
622
|
+
sheets: previewSheets,
|
|
623
|
+
warnings,
|
|
624
|
+
}),
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
export function importXlsx(bytes, fileName) {
|
|
628
|
+
const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
629
|
+
const workbookZip = readValidXlsxZipContainer(data);
|
|
630
|
+
return importSheetJsWorkbook(data, fileName, XLSX_CONTENT_TYPE, workbookZip);
|
|
631
|
+
}
|
|
632
|
+
export function importXlsm(bytes, fileName) {
|
|
633
|
+
const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
634
|
+
const workbookZip = readValidXlsxZipContainer(data);
|
|
635
|
+
return importSheetJsWorkbook(data, fileName, XLSM_CONTENT_TYPE, workbookZip);
|
|
636
|
+
}
|
|
637
|
+
export function importXlsb(bytes, fileName) {
|
|
638
|
+
const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
639
|
+
return importSheetJsWorkbook(data, fileName, XLSB_CONTENT_TYPE, null);
|
|
640
|
+
}
|
|
641
|
+
export function importXls(bytes, fileName) {
|
|
642
|
+
const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
643
|
+
return importSheetJsWorkbook(data, fileName, LEGACY_XLS_CONTENT_TYPE, null);
|
|
644
|
+
}
|
|
645
|
+
export function importCsv(text, fileName, options = {}) {
|
|
646
|
+
const workbookName = normalizeWorkbookName(fileName);
|
|
647
|
+
const sheetName = normalizeCsvSheetName(workbookName);
|
|
648
|
+
const csvOptions = resolveCsvParseOptions(text, options);
|
|
649
|
+
const rows = parseCsv(text, csvOptions);
|
|
650
|
+
const textColumnIndexes = inferCsvTextColumnIndexes(rows);
|
|
651
|
+
const cells = [];
|
|
652
|
+
let nonEmptyCellCount = 0;
|
|
653
|
+
let hasRaggedRows = false;
|
|
654
|
+
const columnCount = rows.reduce((max, row) => Math.max(max, row.length), 0);
|
|
655
|
+
rows.forEach((row, rowIndex) => {
|
|
656
|
+
if (row.length !== columnCount) {
|
|
657
|
+
hasRaggedRows = true;
|
|
658
|
+
}
|
|
659
|
+
row.forEach((raw, colIndex) => {
|
|
660
|
+
const parsed = textColumnIndexes.has(colIndex) && rowIndex > 0 && raw.trim() !== '' ? { value: raw } : parseCsvCellInput(raw, csvOptions);
|
|
661
|
+
if (!parsed) {
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
nonEmptyCellCount += 1;
|
|
665
|
+
const address = XLSX.utils.encode_cell({ r: rowIndex, c: colIndex });
|
|
666
|
+
if (parsed.formula !== undefined) {
|
|
667
|
+
cells.push({ address, formula: parsed.formula });
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
if (parsed.value !== undefined) {
|
|
671
|
+
cells.push({ address, value: parsed.value });
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
const warnings = hasRaggedRows ? ['CSV rows had inconsistent column counts. Missing cells were treated as blanks.'] : [];
|
|
676
|
+
const previewSheet = createSheetPreview({
|
|
677
|
+
name: sheetName,
|
|
678
|
+
rowCount: rows.length,
|
|
679
|
+
columnCount,
|
|
680
|
+
nonEmptyCellCount,
|
|
681
|
+
readCellText: (row, col) => rows[row]?.[col] ?? '',
|
|
682
|
+
});
|
|
683
|
+
return {
|
|
684
|
+
snapshot: {
|
|
685
|
+
version: 1,
|
|
686
|
+
workbook: {
|
|
687
|
+
name: workbookName,
|
|
688
|
+
},
|
|
689
|
+
sheets: [
|
|
690
|
+
{
|
|
691
|
+
id: 1,
|
|
692
|
+
name: sheetName,
|
|
693
|
+
order: 0,
|
|
694
|
+
cells,
|
|
695
|
+
},
|
|
696
|
+
],
|
|
697
|
+
},
|
|
698
|
+
workbookName,
|
|
699
|
+
sheetNames: [sheetName],
|
|
700
|
+
warnings,
|
|
701
|
+
preview: createWorkbookPreview({
|
|
702
|
+
contentType: CSV_CONTENT_TYPE,
|
|
703
|
+
fileName,
|
|
704
|
+
fileSizeBytes: new TextEncoder().encode(text).byteLength,
|
|
705
|
+
workbookName,
|
|
706
|
+
sheets: [previewSheet],
|
|
707
|
+
warnings,
|
|
708
|
+
}),
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
export function importWorkbookFile(bytes, fileName, contentType, options = {}) {
|
|
712
|
+
const normalizedContentType = normalizeWorkbookImportContentType(contentType);
|
|
713
|
+
if (normalizedContentType === XLSX_CONTENT_TYPE) {
|
|
714
|
+
return importXlsx(bytes, fileName);
|
|
715
|
+
}
|
|
716
|
+
if (normalizedContentType === XLSM_CONTENT_TYPE) {
|
|
717
|
+
return importXlsm(bytes, fileName);
|
|
718
|
+
}
|
|
719
|
+
if (normalizedContentType === XLSB_CONTENT_TYPE) {
|
|
720
|
+
return importXlsb(bytes, fileName);
|
|
721
|
+
}
|
|
722
|
+
if (normalizedContentType === LEGACY_XLS_CONTENT_TYPE) {
|
|
723
|
+
return importXls(bytes, fileName);
|
|
724
|
+
}
|
|
725
|
+
if (normalizedContentType === CSV_CONTENT_TYPE) {
|
|
726
|
+
const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
727
|
+
return importCsv(new TextDecoder().decode(data), fileName, options.csv);
|
|
728
|
+
}
|
|
729
|
+
throw new Error('Unsupported workbook import content type');
|
|
730
|
+
}
|
|
731
|
+
function inferCsvTextColumnIndexes(rows) {
|
|
732
|
+
const header = rows[0];
|
|
733
|
+
const textColumnIndexes = new Set();
|
|
734
|
+
if (!header) {
|
|
735
|
+
return textColumnIndexes;
|
|
736
|
+
}
|
|
737
|
+
header.forEach((rawHeader, colIndex) => {
|
|
738
|
+
const headerText = rawHeader.trim().toLowerCase().replaceAll('_', ' ').replaceAll('-', ' ');
|
|
739
|
+
if (isIdentifierLikeCsvHeader(headerText)) {
|
|
740
|
+
textColumnIndexes.add(colIndex);
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
return textColumnIndexes;
|
|
744
|
+
}
|
|
745
|
+
function isIdentifierLikeCsvHeader(headerText) {
|
|
746
|
+
return /^(?:account|acct|id|code|sku)(?: (?:id|number|no|code))?$/u.test(headerText);
|
|
747
|
+
}
|
|
748
|
+
//# sourceMappingURL=index.js.map
|