@libregrid/excel-export 1.1.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/LICENSE +21 -0
- package/NOTICE +6 -0
- package/README.md +71 -0
- package/dist/download.d.ts +2 -0
- package/dist/download.js +13 -0
- package/dist/download.js.map +1 -0
- package/dist/excelCreator.d.ts +14 -0
- package/dist/excelCreator.js +102 -0
- package/dist/excelCreator.js.map +1 -0
- package/dist/excelExportModule.d.ts +3 -0
- package/dist/excelExportModule.js +63 -0
- package/dist/excelExportModule.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/ooxml/cellRef.d.ts +4 -0
- package/dist/ooxml/cellRef.js +15 -0
- package/dist/ooxml/cellRef.js.map +1 -0
- package/dist/ooxml/dateSerial.d.ts +13 -0
- package/dist/ooxml/dateSerial.js +30 -0
- package/dist/ooxml/dateSerial.js.map +1 -0
- package/dist/ooxml/parts/contentTypesPart.d.ts +17 -0
- package/dist/ooxml/parts/contentTypesPart.js +62 -0
- package/dist/ooxml/parts/contentTypesPart.js.map +1 -0
- package/dist/ooxml/parts/docPropsPart.d.ts +5 -0
- package/dist/ooxml/parts/docPropsPart.js +37 -0
- package/dist/ooxml/parts/docPropsPart.js.map +1 -0
- package/dist/ooxml/parts/rootRelsPart.d.ts +7 -0
- package/dist/ooxml/parts/rootRelsPart.js +18 -0
- package/dist/ooxml/parts/rootRelsPart.js.map +1 -0
- package/dist/ooxml/parts/sharedStringsPart.d.ts +3 -0
- package/dist/ooxml/parts/sharedStringsPart.js +18 -0
- package/dist/ooxml/parts/sharedStringsPart.js.map +1 -0
- package/dist/ooxml/parts/stylesPart.d.ts +3 -0
- package/dist/ooxml/parts/stylesPart.js +147 -0
- package/dist/ooxml/parts/stylesPart.js.map +1 -0
- package/dist/ooxml/parts/workbookPart.d.ts +8 -0
- package/dist/ooxml/parts/workbookPart.js +21 -0
- package/dist/ooxml/parts/workbookPart.js.map +1 -0
- package/dist/ooxml/parts/workbookRelsPart.d.ts +14 -0
- package/dist/ooxml/parts/workbookRelsPart.js +20 -0
- package/dist/ooxml/parts/workbookRelsPart.js.map +1 -0
- package/dist/ooxml/parts/worksheetPart.d.ts +79 -0
- package/dist/ooxml/parts/worksheetPart.js +439 -0
- package/dist/ooxml/parts/worksheetPart.js.map +1 -0
- package/dist/ooxml/sharedStringTable.d.ts +17 -0
- package/dist/ooxml/sharedStringTable.js +38 -0
- package/dist/ooxml/sharedStringTable.js.map +1 -0
- package/dist/ooxml/styles/colorMaps.d.ts +4 -0
- package/dist/ooxml/styles/colorMaps.js +52 -0
- package/dist/ooxml/styles/colorMaps.js.map +1 -0
- package/dist/ooxml/styles/styleRegistry.d.ts +108 -0
- package/dist/ooxml/styles/styleRegistry.js +323 -0
- package/dist/ooxml/styles/styleRegistry.js.map +1 -0
- package/dist/ooxml/styles/styleResolver.d.ts +17 -0
- package/dist/ooxml/styles/styleResolver.js +54 -0
- package/dist/ooxml/styles/styleResolver.js.map +1 -0
- package/dist/ooxml/xlsxBuilder.d.ts +25 -0
- package/dist/ooxml/xlsxBuilder.js +110 -0
- package/dist/ooxml/xlsxBuilder.js.map +1 -0
- package/dist/ooxml/xml/xmlElement.d.ts +15 -0
- package/dist/ooxml/xml/xmlElement.js +2 -0
- package/dist/ooxml/xml/xmlElement.js.map +1 -0
- package/dist/ooxml/xml/xmlSerializer.d.ts +12 -0
- package/dist/ooxml/xml/xmlSerializer.js +54 -0
- package/dist/ooxml/xml/xmlSerializer.js.map +1 -0
- package/dist/ooxml/zip/zipAssembler.d.ts +2 -0
- package/dist/ooxml/zip/zipAssembler.js +10 -0
- package/dist/ooxml/zip/zipAssembler.js.map +1 -0
- package/dist/sheetExtractor.d.ts +14 -0
- package/dist/sheetExtractor.js +567 -0
- package/dist/sheetExtractor.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LibreGrid contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
LibreGrid
|
|
2
|
+
Copyright (c) 2026 LibreGrid contributors
|
|
3
|
+
|
|
4
|
+
This package depends on and builds against software developed by AG Grid Ltd, made available under the MIT License. See the repository-level NOTICE for the full attribution and license text.
|
|
5
|
+
|
|
6
|
+
This package includes fflate (MIT License, Copyright (c) 2020 Arjun Barrett), a ZIP/Deflate implementation used to assemble .xlsx archives.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @libregrid/excel-export
|
|
2
|
+
|
|
3
|
+
Exports grid data to `.xlsx` files. The writer builds OOXML SpreadsheetML
|
|
4
|
+
inside the browser. It uses `fflate` to assemble the ZIP archive. No server is
|
|
5
|
+
required.
|
|
6
|
+
|
|
7
|
+
Replaces AG Grid Enterprise's `ExcelExport` module.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install ag-grid-community @libregrid/excel-export
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires `ag-grid-community >=36.1.0 <37` as a peer dependency.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { ModuleRegistry, AllCommunityModule, createGrid } from 'ag-grid-community';
|
|
21
|
+
import { ExcelExportModule } from '@libregrid/excel-export';
|
|
22
|
+
|
|
23
|
+
ModuleRegistry.registerModules([AllCommunityModule, ExcelExportModule]);
|
|
24
|
+
|
|
25
|
+
const api = createGrid(document.querySelector('#grid')!, {
|
|
26
|
+
columnDefs: [{ field: 'name' }, { field: 'value' }],
|
|
27
|
+
rowData: [{ name: 'Widget', value: 42 }],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
api.exportDataAsExcel();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
| Method | Purpose |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `exportDataAsExcel(params?)` | Downloads the grid data as an `.xlsx` file. |
|
|
38
|
+
| `getDataAsExcel(params?)` | Returns the `.xlsx` bytes as a Blob. |
|
|
39
|
+
| `getSheetDataForExcel(params?)` | Returns the data for one worksheet as an opaque string. |
|
|
40
|
+
| `exportMultipleSheetsAsExcel(params)` | Downloads several worksheets in one file. |
|
|
41
|
+
| `getMultipleSheetsAsExcel(params)` | Returns several worksheets in one Blob. |
|
|
42
|
+
|
|
43
|
+
Pass `ExcelExportParams` to control the file name, the sheet name, styling,
|
|
44
|
+
freeze panes, row-group outlines, page setup, and protection.
|
|
45
|
+
|
|
46
|
+
Date cells export as 1900-system serials and display with the built-in
|
|
47
|
+
`mm-dd-yy` format unless the cell's style sets a `numberFormat`.
|
|
48
|
+
|
|
49
|
+
## Not included
|
|
50
|
+
|
|
51
|
+
Cell images (`addImageToCell`), Excel tables (`exportAsExcelTable`) and cell
|
|
52
|
+
notes are not included. The decisions are recorded in the
|
|
53
|
+
[gap list](https://github.com/libregrid/libregrid/blob/main/docs/parity/gap-list.md).
|
|
54
|
+
|
|
55
|
+
With `@libregrid/menu` also registered, the Export item (with CSV and Excel
|
|
56
|
+
entries) appears in the context menu. Exporting several sheets uses the data
|
|
57
|
+
strings from `getSheetDataForExcel`:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const sheets = [
|
|
61
|
+
firstApi.getSheetDataForExcel({ sheetName: 'First' }),
|
|
62
|
+
secondApi.getSheetDataForExcel({ sheetName: 'Second' }),
|
|
63
|
+
];
|
|
64
|
+
firstApi.exportMultipleSheetsAsExcel({ data: sheets, fileName: 'multi.xlsx' });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT — see [LICENSE](./LICENSE). LibreGrid is an independent open-source
|
|
70
|
+
project and is not affiliated with, endorsed by, or sponsored by AG Grid Ltd.
|
|
71
|
+
See [NOTICE](./NOTICE) for third-party attribution.
|
package/dist/download.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Trigger a browser download of a Blob under the given file name. */
|
|
2
|
+
export function downloadFile(fileName, blob) {
|
|
3
|
+
const url = URL.createObjectURL(blob);
|
|
4
|
+
const anchor = document.createElement('a');
|
|
5
|
+
anchor.href = url;
|
|
6
|
+
anchor.download = fileName;
|
|
7
|
+
anchor.style.display = 'none';
|
|
8
|
+
document.body.appendChild(anchor);
|
|
9
|
+
anchor.click();
|
|
10
|
+
document.body.removeChild(anchor);
|
|
11
|
+
URL.revokeObjectURL(url);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,IAAU;IACvD,MAAM,GAAG,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,KAAK,EAAE,CAAC;IACf,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAClC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BeanStub, type ExcelExportMultipleSheetParams, type ExcelExportParams, type ExcelFactoryMode, type IExcelCreator, type NamedBean } from 'ag-grid-community';
|
|
2
|
+
/** Grid-backed Excel export implementation. @feature Excel Export */
|
|
3
|
+
export declare class ExcelCreator extends BeanStub implements NamedBean, IExcelCreator {
|
|
4
|
+
beanName: "excelCreator";
|
|
5
|
+
private factoryMode;
|
|
6
|
+
setFactoryMode(factoryMode: ExcelFactoryMode): void;
|
|
7
|
+
getFactoryMode(): ExcelFactoryMode;
|
|
8
|
+
getDataAsExcel(params?: ExcelExportParams): Blob | undefined;
|
|
9
|
+
exportDataAsExcel(params?: ExcelExportParams): void;
|
|
10
|
+
getSheetDataForExcel(params?: ExcelExportParams): string;
|
|
11
|
+
getMultipleSheetsAsExcel(params: ExcelExportMultipleSheetParams): Blob | undefined;
|
|
12
|
+
exportMultipleSheetsAsExcel(params: ExcelExportMultipleSheetParams): void;
|
|
13
|
+
private extract;
|
|
14
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { BeanStub, } from 'ag-grid-community';
|
|
2
|
+
import { buildXlsx } from './ooxml/xlsxBuilder';
|
|
3
|
+
import { extractSheet } from './sheetExtractor';
|
|
4
|
+
import { downloadFile } from './download';
|
|
5
|
+
const DEFAULT_FILE_NAME = 'export.xlsx';
|
|
6
|
+
const DEFAULT_MIME_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
7
|
+
const ENVELOPE_VERSION = 1;
|
|
8
|
+
/** Grid-backed Excel export implementation. @feature Excel Export */
|
|
9
|
+
export class ExcelCreator extends BeanStub {
|
|
10
|
+
beanName = 'excelCreator';
|
|
11
|
+
factoryMode = 'SINGLE_SHEET';
|
|
12
|
+
setFactoryMode(factoryMode) {
|
|
13
|
+
this.factoryMode = factoryMode;
|
|
14
|
+
}
|
|
15
|
+
getFactoryMode() {
|
|
16
|
+
return this.factoryMode;
|
|
17
|
+
}
|
|
18
|
+
getDataAsExcel(params) {
|
|
19
|
+
const sheet = this.extract(params ?? {});
|
|
20
|
+
const { bytes } = buildXlsx([sheet.worksheet], {
|
|
21
|
+
styles: sheet.styles,
|
|
22
|
+
worksheets: [sheet.layout],
|
|
23
|
+
...(params?.author !== undefined ? { author: params.author } : {}),
|
|
24
|
+
...(params?.customMetadata !== undefined ? { customMetadata: params.customMetadata } : {}),
|
|
25
|
+
...(params?.fontSize !== undefined ? { fontSize: params.fontSize } : {}),
|
|
26
|
+
});
|
|
27
|
+
// fflate returns a fresh Uint8Array over a plain ArrayBuffer.
|
|
28
|
+
return new Blob([bytes.buffer], { type: params?.mimeType ?? DEFAULT_MIME_TYPE });
|
|
29
|
+
}
|
|
30
|
+
exportDataAsExcel(params) {
|
|
31
|
+
const blob = this.getDataAsExcel(params);
|
|
32
|
+
if (!blob)
|
|
33
|
+
return;
|
|
34
|
+
downloadFile(resolveFileName(params?.fileName, this.beans.gridApi), blob);
|
|
35
|
+
}
|
|
36
|
+
getSheetDataForExcel(params) {
|
|
37
|
+
const sheet = this.extract(params ?? {});
|
|
38
|
+
const envelope = {
|
|
39
|
+
v: ENVELOPE_VERSION,
|
|
40
|
+
name: sheet.worksheet.name,
|
|
41
|
+
styles: sheet.styles,
|
|
42
|
+
table: sheet.worksheet.table,
|
|
43
|
+
layout: sheet.layout,
|
|
44
|
+
};
|
|
45
|
+
return JSON.stringify(envelope);
|
|
46
|
+
}
|
|
47
|
+
getMultipleSheetsAsExcel(params) {
|
|
48
|
+
const sheets = params.data.map((entry) => parseEnvelope(entry));
|
|
49
|
+
const { bytes } = buildXlsx(sheets.map((sheet) => sheet.worksheet), {
|
|
50
|
+
styles: sheets.flatMap((sheet) => sheet.styles),
|
|
51
|
+
worksheets: sheets.map((sheet) => sheet.layout),
|
|
52
|
+
...(params.activeSheetIndex !== undefined
|
|
53
|
+
? { activeSheetIndex: params.activeSheetIndex }
|
|
54
|
+
: {}),
|
|
55
|
+
...(params.author !== undefined ? { author: params.author } : {}),
|
|
56
|
+
...(params.customMetadata !== undefined ? { customMetadata: params.customMetadata } : {}),
|
|
57
|
+
...(params.fontSize !== undefined ? { fontSize: params.fontSize } : {}),
|
|
58
|
+
});
|
|
59
|
+
return new Blob([bytes.buffer], { type: params.mimeType ?? DEFAULT_MIME_TYPE });
|
|
60
|
+
}
|
|
61
|
+
exportMultipleSheetsAsExcel(params) {
|
|
62
|
+
const blob = this.getMultipleSheetsAsExcel(params);
|
|
63
|
+
if (!blob)
|
|
64
|
+
return;
|
|
65
|
+
downloadFile(resolveFileName(params.fileName, this.beans.gridApi), blob);
|
|
66
|
+
}
|
|
67
|
+
extract(params) {
|
|
68
|
+
const styles = this.gos.get('excelStyles');
|
|
69
|
+
const colModel = this.beans.colModel;
|
|
70
|
+
return extractSheet(this.beans.gridApi, params, styles, this.beans.showValuesAsSvc, colModel.colsTree ?? []);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function parseEnvelope(entry) {
|
|
74
|
+
let parsed;
|
|
75
|
+
try {
|
|
76
|
+
parsed = JSON.parse(entry);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
throw new Error('Invalid sheet data. Create each sheet with getSheetDataForExcel().');
|
|
80
|
+
}
|
|
81
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
82
|
+
throw new Error('Invalid sheet data. Create each sheet with getSheetDataForExcel().');
|
|
83
|
+
}
|
|
84
|
+
const envelope = parsed;
|
|
85
|
+
if (envelope.v !== ENVELOPE_VERSION || typeof envelope.name !== 'string' || !envelope.table) {
|
|
86
|
+
throw new Error('Invalid sheet data. Create each sheet with getSheetDataForExcel().');
|
|
87
|
+
}
|
|
88
|
+
const worksheet = { name: envelope.name, table: envelope.table };
|
|
89
|
+
return {
|
|
90
|
+
worksheet,
|
|
91
|
+
styles: envelope.styles ?? [],
|
|
92
|
+
layout: envelope.layout ?? {},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function resolveFileName(fileName, api) {
|
|
96
|
+
if (typeof fileName === 'function') {
|
|
97
|
+
const resolved = fileName({ api, context: api.getGridOption('context') });
|
|
98
|
+
return resolved ?? DEFAULT_FILE_NAME;
|
|
99
|
+
}
|
|
100
|
+
return fileName ?? DEFAULT_FILE_NAME;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=excelCreator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excelCreator.js","sourceRoot":"","sources":["../src/excelCreator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,GAYT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAuB,MAAM,kBAAkB,CAAC;AACrE,OAAO,EA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,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { EnterpriseCoreModule } from '@libregrid/core';
|
|
2
|
+
import { registerMenuItems } from '@libregrid/menu';
|
|
3
|
+
import { VERSION } from './version';
|
|
4
|
+
import { ExcelCreator } from './excelCreator';
|
|
5
|
+
function excel(beans) {
|
|
6
|
+
return beans.excelCreator;
|
|
7
|
+
}
|
|
8
|
+
function getDataAsExcel(beans, params) {
|
|
9
|
+
return excel(beans)?.getDataAsExcel(params);
|
|
10
|
+
}
|
|
11
|
+
function exportDataAsExcel(beans, params) {
|
|
12
|
+
excel(beans)?.exportDataAsExcel(params);
|
|
13
|
+
}
|
|
14
|
+
function getSheetDataForExcel(beans, params) {
|
|
15
|
+
return excel(beans)?.getSheetDataForExcel(params);
|
|
16
|
+
}
|
|
17
|
+
function getMultipleSheetsAsExcel(beans, params) {
|
|
18
|
+
return excel(beans)?.getMultipleSheetsAsExcel(params);
|
|
19
|
+
}
|
|
20
|
+
function exportMultipleSheetsAsExcel(beans, params) {
|
|
21
|
+
excel(beans)?.exportMultipleSheetsAsExcel(params);
|
|
22
|
+
}
|
|
23
|
+
/** Registers the Excel export feature and its context-menu contributions. @feature Excel Export */
|
|
24
|
+
export const ExcelExportModule = {
|
|
25
|
+
moduleName: 'ExcelExport',
|
|
26
|
+
version: VERSION,
|
|
27
|
+
enterprise: true,
|
|
28
|
+
dependsOn: [EnterpriseCoreModule],
|
|
29
|
+
beans: [ExcelCreator],
|
|
30
|
+
apiFunctions: {
|
|
31
|
+
getDataAsExcel,
|
|
32
|
+
exportDataAsExcel,
|
|
33
|
+
getSheetDataForExcel,
|
|
34
|
+
getMultipleSheetsAsExcel,
|
|
35
|
+
exportMultipleSheetsAsExcel,
|
|
36
|
+
},
|
|
37
|
+
onRegister: () => registerMenuItems([
|
|
38
|
+
{
|
|
39
|
+
name: 'export',
|
|
40
|
+
order: 10,
|
|
41
|
+
factory: () => ({ name: 'Export', subMenu: ['csvExport', 'excelExport'] }),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'csvExport',
|
|
45
|
+
order: 11,
|
|
46
|
+
factory: (params) => ({
|
|
47
|
+
name: 'CSV Export',
|
|
48
|
+
icon: 'csvExport',
|
|
49
|
+
action: () => params.api.exportDataAsCsv?.(),
|
|
50
|
+
}),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'excelExport',
|
|
54
|
+
order: 12,
|
|
55
|
+
factory: (params) => ({
|
|
56
|
+
name: 'Excel Export (.xlsx)',
|
|
57
|
+
icon: 'excelExport',
|
|
58
|
+
action: () => params.api.exportDataAsExcel?.(),
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
]),
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=excelExportModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excelExportModule.js","sourceRoot":"","sources":["../src/excelExportModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,SAAS,KAAK,CAAC,KAAqB;IAClC,OAAO,KAAK,CAAC,YAAwC,CAAC;AACxD,CAAC;AAED,SAAS,cAAc,CACrB,KAAqB,EACrB,MAAsD;IAEtD,OAAO,KAAK,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,iBAAiB,CACxB,KAAqB,EACrB,MAAyD;IAEzD,KAAK,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,oBAAoB,CAC3B,KAAqB,EACrB,MAA4D;IAE5D,OAAO,KAAK,CAAC,KAAK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AC5B,IAAI,EAAE,aAAa;gBACnB,MAAM,EAAE,GAAG,EAAE,CAET,MAAM,CAAC,GAGR,CAAC,iBAAiB,EAAE,EAAE;aAC1B,CAAC;SACH;KACF,CAAC;CACL,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @libregrid/excel-export — Excel (xlsx) export for AG Grid Community.
|
|
3
|
+
*
|
|
4
|
+
* Barrel: flat re-exports only. No logic, no side effects, no registration.
|
|
5
|
+
*/
|
|
6
|
+
export { ExcelExportModule } from './excelExportModule';
|
|
7
|
+
export { VERSION } from './version';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Spreadsheet column letter for a zero-based column index (0 → 'A', 25 → 'Z', 26 → 'AA'). */
|
|
2
|
+
export declare function columnLetter(index: number): string;
|
|
3
|
+
/** A1-style cell reference for zero-based column and row indexes. */
|
|
4
|
+
export declare function cellRef(columnIndex: number, rowIndex: number): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Spreadsheet column letter for a zero-based column index (0 → 'A', 25 → 'Z', 26 → 'AA'). */
|
|
2
|
+
export function columnLetter(index) {
|
|
3
|
+
let n = index;
|
|
4
|
+
let letters = '';
|
|
5
|
+
while (n >= 0) {
|
|
6
|
+
letters = String.fromCharCode(65 + (n % 26)) + letters;
|
|
7
|
+
n = Math.floor(n / 26) - 1;
|
|
8
|
+
}
|
|
9
|
+
return letters;
|
|
10
|
+
}
|
|
11
|
+
/** A1-style cell reference for zero-based column and row indexes. */
|
|
12
|
+
export function cellRef(columnIndex, rowIndex) {
|
|
13
|
+
return columnLetter(columnIndex) + String(rowIndex + 1);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=cellRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cellRef.js","sourceRoot":"","sources":["../../src/ooxml/cellRef.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,IAAI,CAAC,GAAG,KAAK,CAAC;IACd,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACd,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC;QACvD,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,OAAO,CAAC,WAAmB,EAAE,QAAgB;IAC3D,OAAO,YAAY,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a Date to an Excel 1900-system serial number, reproducing the
|
|
3
|
+
* intentional leap-year bug: day 60 is the phantom 1900-02-29, so every
|
|
4
|
+
* date from 1900-03-01 counts one extra day.
|
|
5
|
+
*
|
|
6
|
+
* Returns null when the date cannot be represented: invalid dates and
|
|
7
|
+
* dates before 1900-01-01 (the 1900 system has no serial for them).
|
|
8
|
+
*/
|
|
9
|
+
export declare function dateToExcelSerial(date: Date): number | null;
|
|
10
|
+
/** Parse an ISO 8601 string and convert it to an Excel 1900 serial number. */
|
|
11
|
+
export declare function isoToExcelSerial(value: string): number | null;
|
|
12
|
+
/** Serialise a serial number without binary floating-point noise. */
|
|
13
|
+
export declare function formatExcelSerial(serial: number): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const MS_PER_DAY = 86_400_000;
|
|
2
|
+
/** 1900-01-01T00:00:00Z — serial 1 in the Excel 1900 date system. */
|
|
3
|
+
const EPOCH_1900 = Date.UTC(1900, 0, 1);
|
|
4
|
+
/** 1900-03-01T00:00:00Z — the first real date after the phantom 1900-02-29. */
|
|
5
|
+
const LEAP_BUG_START = Date.UTC(1900, 2, 1);
|
|
6
|
+
/**
|
|
7
|
+
* Convert a Date to an Excel 1900-system serial number, reproducing the
|
|
8
|
+
* intentional leap-year bug: day 60 is the phantom 1900-02-29, so every
|
|
9
|
+
* date from 1900-03-01 counts one extra day.
|
|
10
|
+
*
|
|
11
|
+
* Returns null when the date cannot be represented: invalid dates and
|
|
12
|
+
* dates before 1900-01-01 (the 1900 system has no serial for them).
|
|
13
|
+
*/
|
|
14
|
+
export function dateToExcelSerial(date) {
|
|
15
|
+
const time = date.getTime();
|
|
16
|
+
if (Number.isNaN(time) || time < EPOCH_1900)
|
|
17
|
+
return null;
|
|
18
|
+
const days = (time - EPOCH_1900) / MS_PER_DAY;
|
|
19
|
+
const serial = days + 1;
|
|
20
|
+
return time >= LEAP_BUG_START ? serial + 1 : serial;
|
|
21
|
+
}
|
|
22
|
+
/** Parse an ISO 8601 string and convert it to an Excel 1900 serial number. */
|
|
23
|
+
export function isoToExcelSerial(value) {
|
|
24
|
+
return dateToExcelSerial(new Date(value));
|
|
25
|
+
}
|
|
26
|
+
/** Serialise a serial number without binary floating-point noise. */
|
|
27
|
+
export function formatExcelSerial(serial) {
|
|
28
|
+
return String(Math.round(serial * 1e9) / 1e9);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=dateSerial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateSerial.js","sourceRoot":"","sources":["../../src/ooxml/dateSerial.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,UAAU,CAAC;AAC9B,qEAAqE;AACrE,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACxC,+EAA+E;AAC/E,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAU;IAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC5B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,UAAU;QAAE,OAAO,IAAI,CAAC;IACzD,MAAM,IAAI,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC;IAC9C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC;IACxB,OAAO,IAAI,IAAI,cAAc,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AACtD,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,iBAAiB,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Content types for the fixed part kinds of a workbook. */
|
|
2
|
+
export declare const PART_CONTENT_TYPES: {
|
|
3
|
+
readonly workbook: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
|
|
4
|
+
readonly worksheet: "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
|
|
5
|
+
readonly sharedStrings: "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml";
|
|
6
|
+
readonly styles: "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml";
|
|
7
|
+
};
|
|
8
|
+
/** Which optional parts the [Content_Types].xml part must declare. */
|
|
9
|
+
export interface ContentTypesConfig {
|
|
10
|
+
sheets: number;
|
|
11
|
+
sharedStrings: boolean;
|
|
12
|
+
styles: boolean;
|
|
13
|
+
coreProps?: boolean;
|
|
14
|
+
customProps?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Build the [Content_Types].xml part. */
|
|
17
|
+
export declare function buildContentTypesXml(config: ContentTypesConfig): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { serializeXml } from '../xml/xmlSerializer';
|
|
2
|
+
const CONTENT_TYPES_NS = 'http://schemas.openxmlformats.org/package/2006/content-types';
|
|
3
|
+
const RELS_CONTENT_TYPE = 'application/vnd.openxmlformats-package.relationships+xml';
|
|
4
|
+
/** Content types for the fixed part kinds of a workbook. */
|
|
5
|
+
export const PART_CONTENT_TYPES = {
|
|
6
|
+
workbook: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml',
|
|
7
|
+
worksheet: 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml',
|
|
8
|
+
sharedStrings: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml',
|
|
9
|
+
styles: 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml',
|
|
10
|
+
};
|
|
11
|
+
/** Build the [Content_Types].xml part. */
|
|
12
|
+
export function buildContentTypesXml(config) {
|
|
13
|
+
const children = [
|
|
14
|
+
{ name: 'Default', attrs: { Extension: 'rels', ContentType: RELS_CONTENT_TYPE } },
|
|
15
|
+
{ name: 'Default', attrs: { Extension: 'xml', ContentType: 'application/xml' } },
|
|
16
|
+
{
|
|
17
|
+
name: 'Override',
|
|
18
|
+
attrs: { PartName: '/xl/workbook.xml', ContentType: PART_CONTENT_TYPES.workbook },
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
for (let index = 0; index < config.sheets; index++) {
|
|
22
|
+
children.push({
|
|
23
|
+
name: 'Override',
|
|
24
|
+
attrs: {
|
|
25
|
+
PartName: '/xl/worksheets/sheet' + (index + 1) + '.xml',
|
|
26
|
+
ContentType: PART_CONTENT_TYPES.worksheet,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (config.sharedStrings) {
|
|
31
|
+
children.push({
|
|
32
|
+
name: 'Override',
|
|
33
|
+
attrs: { PartName: '/xl/sharedStrings.xml', ContentType: PART_CONTENT_TYPES.sharedStrings },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (config.styles) {
|
|
37
|
+
children.push({
|
|
38
|
+
name: 'Override',
|
|
39
|
+
attrs: { PartName: '/xl/styles.xml', ContentType: PART_CONTENT_TYPES.styles },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (config.coreProps) {
|
|
43
|
+
children.push({
|
|
44
|
+
name: 'Override',
|
|
45
|
+
attrs: {
|
|
46
|
+
PartName: '/docProps/core.xml',
|
|
47
|
+
ContentType: 'application/vnd.openxmlformats-package.core-properties+xml',
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (config.customProps) {
|
|
52
|
+
children.push({
|
|
53
|
+
name: 'Override',
|
|
54
|
+
attrs: {
|
|
55
|
+
PartName: '/docProps/custom.xml',
|
|
56
|
+
ContentType: 'application/vnd.openxmlformats-officedocument.custom-properties+xml',
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return serializeXml({ name: 'Types', attrs: { xmlns: CONTENT_TYPES_NS }, children });
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=contentTypesPart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentTypesPart.js","sourceRoot":"","sources":["../../../src/oox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AQ,EAAE,uBAAuB,EAAE,WAAW,EAAE,kBAAkB,CAAC,aAAa,EAAE;SAC5F,CAAC,CAAC;IACL,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAAE,kBAAkB,CAAC,MAAM,EAAE;SAC9E,CAAC,CAAC;IACL,CAAC;IACD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE;gBACL,QAAQ,EAAE,oBAAoB;gBAC9B,WAAW,EAAE,4DAA4D;aAC1E;SACF,CAAC,CAAC;IACL,CAAC;IACD,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE;gBACL,QAAQ,EAAE,sBAAsB;gBAChC,WAAW,EAAE,qEAAqE;aACnF;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,YAAY,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExcelCustomMetadata } from 'ag-grid-community';
|
|
2
|
+
/** Build the docProps/core.xml part (author metadata). */
|
|
3
|
+
export declare function buildCorePropsXml(author: string): string;
|
|
4
|
+
/** Build the docProps/custom.xml part from the customMetadata map. */
|
|
5
|
+
export declare function buildCustomPropsXml(metadata: ExcelCustomMetadata): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { serializeXml } from '../xml/xmlSerializer';
|
|
2
|
+
/** Build the docProps/core.xml part (author metadata). */
|
|
3
|
+
export function buildCorePropsXml(author) {
|
|
4
|
+
return serializeXml({
|
|
5
|
+
name: 'cp:coreProperties',
|
|
6
|
+
attrs: {
|
|
7
|
+
'xmlns:cp': 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties',
|
|
8
|
+
'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
|
|
9
|
+
'xmlns:dcterms': 'http://purl.org/dc/terms/',
|
|
10
|
+
'xmlns:dcmitype': 'http://purl.org/dc/dcmitype/',
|
|
11
|
+
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
|
12
|
+
},
|
|
13
|
+
children: [{ name: 'dc:creator', text: author }],
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
const CUSTOM_PROPS_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties';
|
|
17
|
+
const VTYPES_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes';
|
|
18
|
+
const PROPERTY_FMTID = '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}';
|
|
19
|
+
/** Build the docProps/custom.xml part from the customMetadata map. */
|
|
20
|
+
export function buildCustomPropsXml(metadata) {
|
|
21
|
+
const children = [];
|
|
22
|
+
let pid = 2;
|
|
23
|
+
for (const [name, value] of Object.entries(metadata)) {
|
|
24
|
+
children.push({
|
|
25
|
+
name: 'property',
|
|
26
|
+
attrs: { fmtid: PROPERTY_FMTID, pid, name },
|
|
27
|
+
children: [{ name: 'vt:lpwstr', text: String(value) }],
|
|
28
|
+
});
|
|
29
|
+
pid++;
|
|
30
|
+
}
|
|
31
|
+
return serializeXml({
|
|
32
|
+
name: 'Properties',
|
|
33
|
+
attrs: { xmlns: CUSTOM_PROPS_NS, 'xmlns:vt': VTYPES_NS },
|
|
34
|
+
children,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=docPropsPart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docPropsPart.js","sourceRoot":"","sources":["../../../src/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ACT,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { serializeXml } from '../xml/xmlSerializer';
|
|
2
|
+
const RELS_NS = 'http://schemas.openxmlformats.org/package/2006/relationships';
|
|
3
|
+
const OFFICE_DOCUMENT_REL = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument';
|
|
4
|
+
/** Build the package-level `_rels/.rels` part pointing at the workbook. */
|
|
5
|
+
export function buildRootRelsXml(extra = []) {
|
|
6
|
+
return serializeXml({
|
|
7
|
+
name: 'Relationships',
|
|
8
|
+
attrs: { xmlns: RELS_NS },
|
|
9
|
+
children: [
|
|
10
|
+
{ name: 'Relationship', attrs: { Id: 'rId1', Type: OFFICE_DOCUMENT_REL, Target: 'xl/workbook.xml' } },
|
|
11
|
+
...extra.map((rel) => ({
|
|
12
|
+
name: 'Relationship',
|
|
13
|
+
attrs: { Id: rel.id, Type: rel.type, Target: rel.target },
|
|
14
|
+
})),
|
|
15
|
+
],
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=rootRelsPart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rootRelsPart.js","sourceRoot":"","sources":["../../../src/ooxml/parts/rootRelsPart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,OAAO,GAAG,8DAA8D,CAAC;AAC/E,MAAM,mBAAmB,GACvB,oFAAoF,CAAC;AAQvF,2EAA2E;AAC3E,MAAM,UAAU,gBAAgB,CAAC,QAA4B,EAAE;IAC7D,OAAO,YAAY,CAAC;QAClB,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;QACzB,QAAQ,EAAE;YACR,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAAE;YACrG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBACrB,IAAI,EAAE,cAAc;gBACpB,KAAK,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE;aAC1D,CAAC,CAAC;SACJ;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { serializeXml } from '../xml/xmlSerializer';
|
|
2
|
+
const SHEET_NS = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main';
|
|
3
|
+
/** Build the xl/sharedStrings.xml part from the deduplicated string table. */
|
|
4
|
+
export function buildSharedStringsXml(table) {
|
|
5
|
+
return serializeXml({
|
|
6
|
+
name: 'sst',
|
|
7
|
+
attrs: {
|
|
8
|
+
xmlns: SHEET_NS,
|
|
9
|
+
count: table.count,
|
|
10
|
+
uniqueCount: table.uniqueCount,
|
|
11
|
+
},
|
|
12
|
+
children: table.values().map((value) => ({
|
|
13
|
+
name: 'si',
|
|
14
|
+
children: [{ name: 't', attrs: { 'xml:space': 'preserve' }, text: value }],
|
|
15
|
+
})),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=sharedStringsPart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharedStringsPart.js","sourceRoot":"","sources":["../../../src/ooxml/parts/sharedStringsPart.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,QAAQ,GAAG,2DAA2D,CAAC;AAE7E,8EAA8E;AAC9E,MAAM,UAAU,qBAAqB,CAAC,KAAwB;IAC5D,OAAO,YAAY,CAAC;QAClB,IAAI,EAAE,KAAK;QACX,KAAK,EAAE;YACL,KAAK,EAAE,QAAQ;YACf,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,WAAW,EAAE,KAAK,CAAC,WAAW;SAC/B;QACD,QAAQ,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACvC,IAAI,EAAE,IAAI;YACV,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;SAC3E,CAAC,CAAC;KACJ,CAAC,CAAC;AACL,CAAC"}
|