@js-ak/excel-toolbox 1.8.2 → 1.9.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/build/cjs/lib/template/template-fs.js +2 -1
- package/build/cjs/lib/template/template-memory.js +2 -1
- package/build/cjs/lib/template/utils/column-letter-to-index.js +15 -0
- package/build/cjs/lib/template/utils/index.js +1 -1
- package/build/cjs/lib/template/utils/prepare-row-to-cells.js +2 -2
- package/build/cjs/lib/template/utils/validate-worksheet-xml.js +19 -9
- package/build/cjs/lib/utils/index.js +2 -0
- package/build/cjs/lib/utils/trim-and-join-multiline.js +32 -0
- package/build/cjs/lib/workbook-builder/default/border.js +18 -0
- package/build/cjs/lib/workbook-builder/default/cell-xf.js +15 -0
- package/build/cjs/lib/workbook-builder/default/fill.js +18 -0
- package/build/cjs/lib/workbook-builder/default/font.js +19 -0
- package/build/cjs/lib/workbook-builder/default/index.js +21 -0
- package/build/cjs/lib/workbook-builder/default/sheet-name.js +10 -0
- package/build/cjs/lib/workbook-builder/index.js +18 -0
- package/build/cjs/lib/workbook-builder/merge-cells/add.js +72 -0
- package/build/cjs/lib/workbook-builder/merge-cells/helpers/index.js +18 -0
- package/build/cjs/lib/workbook-builder/merge-cells/helpers/ranges-equal.js +17 -0
- package/build/cjs/lib/workbook-builder/merge-cells/helpers/ranges-intersect.js +17 -0
- package/build/cjs/lib/workbook-builder/merge-cells/index.js +18 -0
- package/build/cjs/lib/workbook-builder/merge-cells/remove.js +60 -0
- package/build/cjs/lib/workbook-builder/shared-string-ref/add.js +24 -0
- package/build/cjs/lib/workbook-builder/shared-string-ref/index.js +19 -0
- package/build/cjs/lib/workbook-builder/shared-string-ref/remove-all-from-sheet.js +66 -0
- package/build/cjs/lib/workbook-builder/shared-string-ref/remove.js +66 -0
- package/build/cjs/lib/workbook-builder/style-ref/add-or-get.js +94 -0
- package/build/cjs/lib/workbook-builder/style-ref/helpers/add-num-fmt.js +25 -0
- package/build/cjs/lib/workbook-builder/style-ref/helpers/border-to-xml.js +49 -0
- package/build/cjs/lib/workbook-builder/style-ref/helpers/fill-to-xml.js +51 -0
- package/build/cjs/lib/workbook-builder/style-ref/helpers/font-to-xml.js +112 -0
- package/build/cjs/lib/workbook-builder/style-ref/helpers/index.js +21 -0
- package/build/cjs/lib/workbook-builder/style-ref/helpers/reindex-style-map-after-removal.js +30 -0
- package/build/cjs/lib/workbook-builder/style-ref/index.js +19 -0
- package/build/cjs/lib/workbook-builder/style-ref/remove-all-from-sheet.js +26 -0
- package/build/cjs/lib/workbook-builder/style-ref/remove.js +52 -0
- package/build/cjs/lib/workbook-builder/types/app-xml-options.js +2 -0
- package/build/cjs/lib/workbook-builder/types/border-style.js +2 -0
- package/build/cjs/lib/workbook-builder/types/cell-data.js +2 -0
- package/build/cjs/lib/workbook-builder/types/cell-style.js +2 -0
- package/build/cjs/lib/workbook-builder/types/cell-type.js +2 -0
- package/build/cjs/lib/workbook-builder/types/cell-value.js +2 -0
- package/build/cjs/lib/workbook-builder/types/cell-xf.js +2 -0
- package/build/cjs/lib/workbook-builder/types/index.js +27 -0
- package/build/cjs/lib/workbook-builder/types/merge-cell.js +2 -0
- package/build/cjs/lib/workbook-builder/types/row-data.js +2 -0
- package/build/cjs/lib/workbook-builder/types/sheet-data.js +2 -0
- package/build/cjs/lib/workbook-builder/types/xml-node.js +2 -0
- package/build/cjs/lib/workbook-builder/utils/build-app-xml.js +51 -0
- package/build/cjs/lib/workbook-builder/utils/build-cell-children.js +59 -0
- package/build/cjs/lib/workbook-builder/utils/build-content-types-xml.js +42 -0
- package/build/cjs/lib/workbook-builder/utils/build-core-xml.js +27 -0
- package/build/cjs/lib/workbook-builder/utils/build-rels-xml.js +19 -0
- package/build/cjs/lib/workbook-builder/utils/build-shared-strings-xml.js +39 -0
- package/build/cjs/lib/workbook-builder/utils/build-styles-xml.js +178 -0
- package/build/cjs/lib/workbook-builder/utils/build-theme-xml.js +609 -0
- package/build/cjs/lib/workbook-builder/utils/build-workbook-rels-xml.js +58 -0
- package/build/cjs/lib/workbook-builder/utils/build-workbook-xml.js +26 -0
- package/build/cjs/lib/workbook-builder/utils/build-worksheet-xml.js +66 -0
- package/build/cjs/lib/workbook-builder/utils/build-xml.js +72 -0
- package/build/cjs/lib/workbook-builder/utils/constants.js +55 -0
- package/build/cjs/lib/workbook-builder/utils/date-to-excel-serial.js +16 -0
- package/build/cjs/lib/workbook-builder/utils/index.js +34 -0
- package/build/cjs/lib/workbook-builder/utils/initialize-files.js +40 -0
- package/build/cjs/lib/workbook-builder/utils/sheet.js +144 -0
- package/build/cjs/lib/workbook-builder/utils/write-shared-strings-xml.js +49 -0
- package/build/cjs/lib/workbook-builder/utils/write-styles-xml.js +196 -0
- package/build/cjs/lib/workbook-builder/utils/write-worksheet-xml.js +209 -0
- package/build/cjs/lib/workbook-builder/utils/write-xml.js +37 -0
- package/build/cjs/lib/workbook-builder/workbook-builder.js +414 -0
- package/build/cjs/lib/zip/utils/to-bytes.js +19 -11
- package/build/esm/lib/template/template-fs.js +2 -1
- package/build/esm/lib/template/template-memory.js +2 -1
- package/build/esm/lib/template/utils/column-letter-to-index.js +12 -0
- package/build/esm/lib/template/utils/index.js +1 -1
- package/build/esm/lib/template/utils/prepare-row-to-cells.js +1 -1
- package/build/esm/lib/template/utils/validate-worksheet-xml.js +19 -9
- package/build/esm/lib/utils/index.js +2 -0
- package/build/esm/lib/utils/trim-and-join-multiline.js +29 -0
- package/build/esm/lib/workbook-builder/default/border.js +14 -0
- package/build/esm/lib/workbook-builder/default/cell-xf.js +11 -0
- package/build/esm/lib/workbook-builder/default/fill.js +14 -0
- package/build/esm/lib/workbook-builder/default/font.js +15 -0
- package/build/esm/lib/workbook-builder/default/index.js +5 -0
- package/build/esm/lib/workbook-builder/default/sheet-name.js +6 -0
- package/build/esm/lib/workbook-builder/index.js +2 -0
- package/build/esm/lib/workbook-builder/merge-cells/add.js +36 -0
- package/build/esm/lib/workbook-builder/merge-cells/helpers/index.js +2 -0
- package/build/esm/lib/workbook-builder/merge-cells/helpers/ranges-equal.js +14 -0
- package/build/esm/lib/workbook-builder/merge-cells/helpers/ranges-intersect.js +14 -0
- package/build/esm/lib/workbook-builder/merge-cells/index.js +2 -0
- package/build/esm/lib/workbook-builder/merge-cells/remove.js +24 -0
- package/build/esm/lib/workbook-builder/shared-string-ref/add.js +21 -0
- package/build/esm/lib/workbook-builder/shared-string-ref/index.js +3 -0
- package/build/esm/lib/workbook-builder/shared-string-ref/remove-all-from-sheet.js +63 -0
- package/build/esm/lib/workbook-builder/shared-string-ref/remove.js +63 -0
- package/build/esm/lib/workbook-builder/style-ref/add-or-get.js +58 -0
- package/build/esm/lib/workbook-builder/style-ref/helpers/add-num-fmt.js +21 -0
- package/build/esm/lib/workbook-builder/style-ref/helpers/border-to-xml.js +45 -0
- package/build/esm/lib/workbook-builder/style-ref/helpers/fill-to-xml.js +47 -0
- package/build/esm/lib/workbook-builder/style-ref/helpers/font-to-xml.js +75 -0
- package/build/esm/lib/workbook-builder/style-ref/helpers/index.js +5 -0
- package/build/esm/lib/workbook-builder/style-ref/helpers/reindex-style-map-after-removal.js +26 -0
- package/build/esm/lib/workbook-builder/style-ref/index.js +3 -0
- package/build/esm/lib/workbook-builder/style-ref/remove-all-from-sheet.js +23 -0
- package/build/esm/lib/workbook-builder/style-ref/remove.js +49 -0
- package/build/esm/lib/workbook-builder/types/app-xml-options.js +1 -0
- package/build/esm/lib/workbook-builder/types/border-style.js +1 -0
- package/build/esm/lib/workbook-builder/types/cell-data.js +1 -0
- package/build/esm/lib/workbook-builder/types/cell-style.js +1 -0
- package/build/esm/lib/workbook-builder/types/cell-type.js +1 -0
- package/build/esm/lib/workbook-builder/types/cell-value.js +1 -0
- package/build/esm/lib/workbook-builder/types/cell-xf.js +1 -0
- package/build/esm/lib/workbook-builder/types/index.js +11 -0
- package/build/esm/lib/workbook-builder/types/merge-cell.js +1 -0
- package/build/esm/lib/workbook-builder/types/row-data.js +1 -0
- package/build/esm/lib/workbook-builder/types/sheet-data.js +1 -0
- package/build/esm/lib/workbook-builder/types/xml-node.js +1 -0
- package/build/esm/lib/workbook-builder/utils/build-app-xml.js +48 -0
- package/build/esm/lib/workbook-builder/utils/build-cell-children.js +56 -0
- package/build/esm/lib/workbook-builder/utils/build-content-types-xml.js +39 -0
- package/build/esm/lib/workbook-builder/utils/build-core-xml.js +24 -0
- package/build/esm/lib/workbook-builder/utils/build-rels-xml.js +16 -0
- package/build/esm/lib/workbook-builder/utils/build-shared-strings-xml.js +36 -0
- package/build/esm/lib/workbook-builder/utils/build-styles-xml.js +142 -0
- package/build/esm/lib/workbook-builder/utils/build-theme-xml.js +606 -0
- package/build/esm/lib/workbook-builder/utils/build-workbook-rels-xml.js +55 -0
- package/build/esm/lib/workbook-builder/utils/build-workbook-xml.js +23 -0
- package/build/esm/lib/workbook-builder/utils/build-worksheet-xml.js +63 -0
- package/build/esm/lib/workbook-builder/utils/build-xml.js +69 -0
- package/build/esm/lib/workbook-builder/utils/constants.js +52 -0
- package/build/esm/lib/workbook-builder/utils/date-to-excel-serial.js +13 -0
- package/build/esm/lib/workbook-builder/utils/index.js +18 -0
- package/build/esm/lib/workbook-builder/utils/initialize-files.js +36 -0
- package/build/esm/lib/workbook-builder/utils/sheet.js +141 -0
- package/build/esm/lib/workbook-builder/utils/write-shared-strings-xml.js +43 -0
- package/build/esm/lib/workbook-builder/utils/write-styles-xml.js +157 -0
- package/build/esm/lib/workbook-builder/utils/write-worksheet-xml.js +203 -0
- package/build/esm/lib/workbook-builder/utils/write-xml.js +34 -0
- package/build/esm/lib/workbook-builder/workbook-builder.js +374 -0
- package/build/esm/lib/zip/utils/to-bytes.js +19 -11
- package/build/types/lib/template/utils/column-letter-to-index.d.ts +1 -0
- package/build/types/lib/template/utils/index.d.ts +1 -1
- package/build/types/lib/utils/index.d.ts +2 -0
- package/build/types/lib/utils/trim-and-join-multiline.d.ts +23 -0
- package/build/types/lib/workbook-builder/default/border.d.ts +7 -0
- package/build/types/lib/workbook-builder/default/cell-xf.d.ts +7 -0
- package/build/types/lib/workbook-builder/default/fill.d.ts +7 -0
- package/build/types/lib/workbook-builder/default/font.d.ts +21 -0
- package/build/types/lib/workbook-builder/default/index.d.ts +5 -0
- package/build/types/lib/workbook-builder/default/sheet-name.d.ts +6 -0
- package/build/types/lib/workbook-builder/index.d.ts +2 -0
- package/build/types/lib/workbook-builder/merge-cells/add.d.ts +15 -0
- package/build/types/lib/workbook-builder/merge-cells/helpers/index.d.ts +2 -0
- package/build/types/lib/workbook-builder/merge-cells/helpers/ranges-equal.d.ts +10 -0
- package/build/types/lib/workbook-builder/merge-cells/helpers/ranges-intersect.d.ts +10 -0
- package/build/types/lib/workbook-builder/merge-cells/index.d.ts +2 -0
- package/build/types/lib/workbook-builder/merge-cells/remove.d.ts +15 -0
- package/build/types/lib/workbook-builder/shared-string-ref/add.d.ts +13 -0
- package/build/types/lib/workbook-builder/shared-string-ref/index.d.ts +3 -0
- package/build/types/lib/workbook-builder/shared-string-ref/remove-all-from-sheet.d.ts +10 -0
- package/build/types/lib/workbook-builder/shared-string-ref/remove.d.ts +13 -0
- package/build/types/lib/workbook-builder/style-ref/add-or-get.d.ts +16 -0
- package/build/types/lib/workbook-builder/style-ref/helpers/add-num-fmt.d.ts +17 -0
- package/build/types/lib/workbook-builder/style-ref/helpers/border-to-xml.d.ts +16 -0
- package/build/types/lib/workbook-builder/style-ref/helpers/fill-to-xml.d.ts +17 -0
- package/build/types/lib/workbook-builder/style-ref/helpers/font-to-xml.d.ts +18 -0
- package/build/types/lib/workbook-builder/style-ref/helpers/index.d.ts +5 -0
- package/build/types/lib/workbook-builder/style-ref/helpers/reindex-style-map-after-removal.d.ts +15 -0
- package/build/types/lib/workbook-builder/style-ref/index.d.ts +3 -0
- package/build/types/lib/workbook-builder/style-ref/remove-all-from-sheet.d.ts +4 -0
- package/build/types/lib/workbook-builder/style-ref/remove.d.ts +18 -0
- package/build/types/lib/workbook-builder/types/app-xml-options.d.ts +9 -0
- package/build/types/lib/workbook-builder/types/border-style.d.ts +5 -0
- package/build/types/lib/workbook-builder/types/cell-data.d.ts +10 -0
- package/build/types/lib/workbook-builder/types/cell-style.d.ts +32 -0
- package/build/types/lib/workbook-builder/types/cell-type.d.ts +11 -0
- package/build/types/lib/workbook-builder/types/cell-value.d.ts +2 -0
- package/build/types/lib/workbook-builder/types/cell-xf.d.ts +13 -0
- package/build/types/lib/workbook-builder/types/index.d.ts +11 -0
- package/build/types/lib/workbook-builder/types/merge-cell.d.ts +6 -0
- package/build/types/lib/workbook-builder/types/row-data.d.ts +5 -0
- package/build/types/lib/workbook-builder/types/sheet-data.d.ts +13 -0
- package/build/types/lib/workbook-builder/types/xml-node.d.ts +11 -0
- package/build/types/lib/workbook-builder/utils/build-app-xml.d.ts +2 -0
- package/build/types/lib/workbook-builder/utils/build-cell-children.d.ts +9 -0
- package/build/types/lib/workbook-builder/utils/build-content-types-xml.d.ts +1 -0
- package/build/types/lib/workbook-builder/utils/build-core-xml.d.ts +1 -0
- package/build/types/lib/workbook-builder/utils/build-rels-xml.d.ts +1 -0
- package/build/types/lib/workbook-builder/utils/build-shared-strings-xml.d.ts +10 -0
- package/build/types/lib/workbook-builder/utils/build-styles-xml.d.ts +23 -0
- package/build/types/lib/workbook-builder/utils/build-theme-xml.d.ts +1 -0
- package/build/types/lib/workbook-builder/utils/build-workbook-rels-xml.d.ts +9 -0
- package/build/types/lib/workbook-builder/utils/build-workbook-xml.d.ts +3 -0
- package/build/types/lib/workbook-builder/utils/build-worksheet-xml.d.ts +2 -0
- package/build/types/lib/workbook-builder/utils/build-xml.d.ts +50 -0
- package/build/types/lib/workbook-builder/utils/constants.d.ts +47 -0
- package/build/types/lib/workbook-builder/utils/date-to-excel-serial.d.ts +9 -0
- package/build/types/lib/workbook-builder/utils/index.d.ts +18 -0
- package/build/types/lib/workbook-builder/utils/initialize-files.d.ts +13 -0
- package/build/types/lib/workbook-builder/utils/sheet.d.ts +21 -0
- package/build/types/lib/workbook-builder/utils/write-shared-strings-xml.d.ts +11 -0
- package/build/types/lib/workbook-builder/utils/write-styles-xml.d.ts +24 -0
- package/build/types/lib/workbook-builder/utils/write-worksheet-xml.d.ts +14 -0
- package/build/types/lib/workbook-builder/utils/write-xml.d.ts +3 -0
- package/build/types/lib/workbook-builder/workbook-builder.d.ts +110 -0
- package/build/types/lib/zip/utils/to-bytes.d.ts +2 -2
- package/package.json +4 -2
- /package/build/cjs/lib/{template/utils → utils}/escape-xml.js +0 -0
- /package/build/esm/lib/{template/utils → utils}/escape-xml.js +0 -0
- /package/build/types/lib/{template/utils → utils}/escape-xml.d.ts +0 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
export declare const CONTENT_TYPES: {
|
2
|
+
readonly APP: "application/vnd.openxmlformats-officedocument.extended-properties+xml";
|
3
|
+
readonly CORE: "application/vnd.openxmlformats-package.core-properties+xml";
|
4
|
+
readonly RELATIONSHIPS: "application/vnd.openxmlformats-package.relationships+xml";
|
5
|
+
readonly SHARED_STRINGS: "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml";
|
6
|
+
readonly STYLES: "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml";
|
7
|
+
readonly THEME: "application/vnd.openxmlformats-officedocument.theme+xml";
|
8
|
+
readonly WORKBOOK: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
|
9
|
+
readonly WORKSHEET: "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
|
10
|
+
readonly XML: "application/xml";
|
11
|
+
};
|
12
|
+
export declare const FILE_PATHS: {
|
13
|
+
readonly APP: "docProps/app.xml";
|
14
|
+
readonly CONTENT_TYPES: "[Content_Types].xml";
|
15
|
+
readonly CORE: "docProps/core.xml";
|
16
|
+
readonly RELS: "_rels/.rels";
|
17
|
+
readonly SHARED_STRINGS: "xl/sharedStrings.xml";
|
18
|
+
readonly STYLES: "xl/styles.xml";
|
19
|
+
readonly THEME: "xl/theme/theme1.xml";
|
20
|
+
readonly WORKBOOK: "xl/workbook.xml";
|
21
|
+
readonly WORKBOOK_RELS: "xl/_rels/workbook.xml.rels";
|
22
|
+
readonly WORKSHEET: "xl/worksheets/sheet1.xml";
|
23
|
+
};
|
24
|
+
export declare const RELATIONSHIP_TYPES: {
|
25
|
+
readonly APP: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
|
26
|
+
readonly CORE: "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
|
27
|
+
readonly OFFICE_DOCUMENT: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
|
28
|
+
readonly SHARED_STRINGS: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings";
|
29
|
+
readonly STYLES: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
|
30
|
+
readonly THEME: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
|
31
|
+
readonly WORKSHEET: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet";
|
32
|
+
};
|
33
|
+
export declare const XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
|
34
|
+
export declare const XML_NAMESPACES: {
|
35
|
+
readonly CONTENT_TYPES: "http://schemas.openxmlformats.org/package/2006/content-types";
|
36
|
+
readonly CORE_PROPERTIES: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
|
37
|
+
readonly DC: "http://purl.org/dc/elements/1.1/";
|
38
|
+
readonly DCMITYPE: "http://purl.org/dc/dcmitype/";
|
39
|
+
readonly DCTERMS: "http://purl.org/dc/terms/";
|
40
|
+
readonly DOC_PROPS_VTYPES: "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes";
|
41
|
+
readonly DRAWINGML: "http://schemas.openxmlformats.org/drawingml/2006/main";
|
42
|
+
readonly EXTENDED_PROPERTIES: "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
|
43
|
+
readonly OFFICE_DOCUMENT: "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
44
|
+
readonly PACKAGE_RELATIONSHIPS: "http://schemas.openxmlformats.org/package/2006/relationships";
|
45
|
+
readonly SPREADSHEET_ML: "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
46
|
+
readonly XSI: "http://www.w3.org/2001/XMLSchema-instance";
|
47
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* Converts a JavaScript Date object to Excel serial number format.
|
3
|
+
* Excel stores dates as serial numbers where 1 represents January 1, 1900.
|
4
|
+
*
|
5
|
+
* @param date - The JavaScript Date object to convert
|
6
|
+
*
|
7
|
+
* @returns The Excel serial number as a floating-point number
|
8
|
+
*/
|
9
|
+
export declare function dateToExcelSerial(date: Date): number;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export * from "./build-app-xml.js";
|
2
|
+
export * from "./build-cell-children.js";
|
3
|
+
export * from "./build-content-types-xml.js";
|
4
|
+
export * from "./build-shared-strings-xml.js";
|
5
|
+
export * from "./build-styles-xml.js";
|
6
|
+
export * from "./build-theme-xml.js";
|
7
|
+
export * from "./build-workbook-rels-xml.js";
|
8
|
+
export * from "./build-workbook-xml.js";
|
9
|
+
export * from "./build-worksheet-xml.js";
|
10
|
+
export * from "./build-xml.js";
|
11
|
+
export * from "./constants.js";
|
12
|
+
export * from "./date-to-excel-serial.js";
|
13
|
+
export * from "./initialize-files.js";
|
14
|
+
export * from "./sheet.js";
|
15
|
+
export * from "./write-shared-strings-xml.js";
|
16
|
+
export * from "./write-styles-xml.js";
|
17
|
+
export * from "./write-worksheet-xml.js";
|
18
|
+
export * from "./write-xml.js";
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { FILE_PATHS } from "./constants.js";
|
2
|
+
export type ExcelFileContent = Buffer | string;
|
3
|
+
export type ExcelFiles = {
|
4
|
+
[FILE_PATHS.CONTENT_TYPES]: ExcelFileContent;
|
5
|
+
[FILE_PATHS.RELS]: ExcelFileContent;
|
6
|
+
[FILE_PATHS.WORKBOOK_RELS]: ExcelFileContent;
|
7
|
+
[FILE_PATHS.STYLES]: ExcelFileContent;
|
8
|
+
[FILE_PATHS.SHARED_STRINGS]: ExcelFileContent;
|
9
|
+
[FILE_PATHS.WORKBOOK]: ExcelFileContent;
|
10
|
+
[FILE_PATHS.WORKSHEET]: ExcelFileContent;
|
11
|
+
[key: string]: ExcelFileContent;
|
12
|
+
};
|
13
|
+
export declare const initializeFiles: (sheetName: string) => ExcelFiles;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { CellStyle, MergeCell, SheetData } from "../types/index.js";
|
2
|
+
/**
|
3
|
+
* Factory for creating a new sheet with bound helpers.
|
4
|
+
*
|
5
|
+
* @param name - Sheet name
|
6
|
+
* @param fn.addMerge - Function to add a merge range (bound to workbook)
|
7
|
+
* @param fn.removeMerge - Function to remove a merge range (bound to workbook)
|
8
|
+
* @param fn.addOrGetStyle - Function to add or get a style index
|
9
|
+
* @param fn.addSharedString - Function to add a shared string and return its index
|
10
|
+
* @returns SheetData instance with helpers
|
11
|
+
*/
|
12
|
+
export declare function createSheet(name: string, fn: {
|
13
|
+
addMerge: (mergeCell: MergeCell & {
|
14
|
+
sheetName: string;
|
15
|
+
}) => MergeCell;
|
16
|
+
removeMerge: (mergeCell: MergeCell & {
|
17
|
+
sheetName: string;
|
18
|
+
}) => boolean;
|
19
|
+
addOrGetStyle: (style: CellStyle, sheetName: string) => number;
|
20
|
+
addSharedString: (str: string, sheetName: string) => number;
|
21
|
+
}): SheetData;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* Writes the `sharedStrings.xml` content to a file at the given destination.
|
3
|
+
*
|
4
|
+
* Uses a file write stream with backpressure control to avoid buffering large
|
5
|
+
* content in memory.
|
6
|
+
*
|
7
|
+
* @param destination - Absolute or relative file path to write
|
8
|
+
* @param strings - Array of unique strings used in the workbook
|
9
|
+
* @returns Promise that resolves when the write stream finishes
|
10
|
+
*/
|
11
|
+
export declare function writeSharedStringsXml(destination: string, strings?: string[]): Promise<void>;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import type { CellXf, XmlNode } from "../types/index.js";
|
2
|
+
/**
|
3
|
+
* Writes the `styles.xml` part to a file at the given destination using a write stream.
|
4
|
+
* Falls back to default font/fill/border collections when none are provided.
|
5
|
+
*
|
6
|
+
* @param destination - Absolute or relative file path to write
|
7
|
+
* @param data - Style collections used to construct the stylesheet
|
8
|
+
* @param data.borders - Array of border XmlNodes
|
9
|
+
* @param data.cellXfs - Array of cell format records
|
10
|
+
* @param data.fills - Array of fill XmlNodes
|
11
|
+
* @param data.fonts - Array of font XmlNodes
|
12
|
+
* @param data.numFmts - Array of custom number formats (formatCode and id)
|
13
|
+
* @returns Promise that resolves when the write stream finishes
|
14
|
+
*/
|
15
|
+
export declare function writeStylesXml(destination: string, data?: {
|
16
|
+
borders: XmlNode["children"];
|
17
|
+
cellXfs: CellXf[];
|
18
|
+
fills: XmlNode["children"];
|
19
|
+
fonts: XmlNode["children"];
|
20
|
+
numFmts: {
|
21
|
+
formatCode: string;
|
22
|
+
id: number;
|
23
|
+
}[];
|
24
|
+
}): Promise<void>;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { MergeCell, SheetData } from "../types/index.js";
|
2
|
+
/**
|
3
|
+
* Writes a worksheet XML file to the given destination using a streaming approach.
|
4
|
+
*
|
5
|
+
* - Streams rows and cells to minimize memory usage
|
6
|
+
* - Tracks the worksheet dimension (min/max rows/cols) while streaming
|
7
|
+
* - Updates the <dimension> ref at the end by rewriting the file in a buffered pass
|
8
|
+
*
|
9
|
+
* @param destination - Absolute or relative file path for the worksheet XML
|
10
|
+
* @param rows - Map of rowIndex -> RowData with cells
|
11
|
+
* @param merges - Merge ranges to append after <sheetData>
|
12
|
+
* @returns Promise that resolves when the file is fully written and dimension updated
|
13
|
+
*/
|
14
|
+
export declare function writeWorksheetXml(destination: string, rows?: SheetData["rows"], merges?: MergeCell[]): Promise<void>;
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import type { Writable } from "node:stream";
|
2
|
+
import * as Types from "./types/index.js";
|
3
|
+
/**
|
4
|
+
* Builds Excel workbooks by composing sheets, styles, shared strings and merges,
|
5
|
+
* and provides methods to save to file or stream.
|
6
|
+
*
|
7
|
+
* @experimental This API is experimental and might change in future versions.
|
8
|
+
*/
|
9
|
+
export declare class WorkbookBuilder {
|
10
|
+
#private;
|
11
|
+
/**
|
12
|
+
* Creates a new workbook with a default sheet and initial style collections.
|
13
|
+
*
|
14
|
+
* @param options.defaultSheetName - The name for the initial sheet
|
15
|
+
*/
|
16
|
+
constructor({ defaultSheetName, }?: {
|
17
|
+
defaultSheetName?: string | undefined;
|
18
|
+
});
|
19
|
+
/** Returns the internal sheets map. */
|
20
|
+
protected get sheets(): Map<string, Types.SheetData>;
|
21
|
+
/** Returns the shared strings array. */
|
22
|
+
protected get sharedStrings(): string[];
|
23
|
+
/** Replaces the shared strings array. */
|
24
|
+
protected set sharedStrings(sharedStrings: string[]);
|
25
|
+
/** Returns the shared string index map. */
|
26
|
+
protected get sharedStringMap(): Map<string, number>;
|
27
|
+
/** Returns the borders collection. */
|
28
|
+
protected get borders(): (string | Types.XmlNode)[];
|
29
|
+
/** Returns the border cache map (serialized xml -> index). */
|
30
|
+
protected get bordersMap(): Map<string, number>;
|
31
|
+
/** Returns the cellXfs (style records). */
|
32
|
+
protected get cellXfs(): Types.CellXf[];
|
33
|
+
/** Returns the fills collection. */
|
34
|
+
protected get fills(): (string | Types.XmlNode)[];
|
35
|
+
/** Returns the fill cache map (serialized xml -> index). */
|
36
|
+
protected get fillsMap(): Map<string, number>;
|
37
|
+
/** Returns the fonts collection. */
|
38
|
+
protected get fonts(): (string | Types.XmlNode)[];
|
39
|
+
/** Returns the font cache map (serialized xml -> index). */
|
40
|
+
protected get fontsMap(): Map<string, number>;
|
41
|
+
/** Returns the number formats collection. */
|
42
|
+
protected get numFmts(): {
|
43
|
+
formatCode: string;
|
44
|
+
id: number;
|
45
|
+
}[];
|
46
|
+
/** Returns the mapping from serialized style JSON to style index. */
|
47
|
+
protected get styleMap(): Map<string, number>;
|
48
|
+
/** Returns the merge ranges, grouped by sheet name. */
|
49
|
+
protected get mergeCells(): Map<string, Types.MergeCell[]>;
|
50
|
+
/** Public methods */
|
51
|
+
/**
|
52
|
+
* Adds a new sheet to the workbook.
|
53
|
+
*
|
54
|
+
* @throws Error if a sheet with the same name already exists
|
55
|
+
* @param sheetName - Sheet name to add
|
56
|
+
* @returns The created sheet data
|
57
|
+
*/
|
58
|
+
addSheet(sheetName: string): Types.SheetData;
|
59
|
+
/** Returns a sheet by name if it exists. */
|
60
|
+
getSheet(sheetName: string): Types.SheetData | undefined;
|
61
|
+
/**
|
62
|
+
* Removes a sheet by name.
|
63
|
+
* If cleanup is enabled, also removes associated shared strings and styles.
|
64
|
+
*
|
65
|
+
* @param sheetName - Sheet name to remove
|
66
|
+
* @returns True if the sheet existed and was removed
|
67
|
+
*/
|
68
|
+
removeSheet(sheetName: string): true;
|
69
|
+
/**
|
70
|
+
* Returns a snapshot of the workbook internals for inspection and tests.
|
71
|
+
* The returned structure is deeply frozen to avoid accidental mutations.
|
72
|
+
*/
|
73
|
+
getInfo(): {
|
74
|
+
mergeCells: Map<string, Types.MergeCell[]>;
|
75
|
+
sheetsNames: string[];
|
76
|
+
sharedStringMap: Map<string, number>;
|
77
|
+
sharedStrings: string[];
|
78
|
+
styles: {
|
79
|
+
borders: NonNullable<Types.XmlNode["children"]>;
|
80
|
+
cellXfs: Types.CellXf[];
|
81
|
+
fills: NonNullable<Types.XmlNode["children"]>;
|
82
|
+
fonts: NonNullable<Types.XmlNode["children"]>;
|
83
|
+
numFmts: {
|
84
|
+
formatCode: string;
|
85
|
+
id: number;
|
86
|
+
}[];
|
87
|
+
styleMap: Map<string, number>;
|
88
|
+
};
|
89
|
+
};
|
90
|
+
/**
|
91
|
+
* Generates workbook XML parts in-memory and writes a .xlsx zip to disk.
|
92
|
+
*
|
93
|
+
* @param path - Absolute or relative file path to write
|
94
|
+
*/
|
95
|
+
saveToFile(path: string): Promise<void>;
|
96
|
+
/**
|
97
|
+
* Saves the workbook to a writable stream using temporary files.
|
98
|
+
* This method creates temporary files from the in-memory data and streams them
|
99
|
+
* to the output stream, avoiding loading the entire file into memory.
|
100
|
+
*
|
101
|
+
* @param output - Writable stream to receive the Excel file
|
102
|
+
* @param options.destination - Optional existing directory to use instead of a system temp directory
|
103
|
+
* @param options.cleanup - Optional flag to cleanup the temporary directory after saving (default: true)
|
104
|
+
* @returns Promise that resolves when the file has been fully written
|
105
|
+
*/
|
106
|
+
saveToStream(output: Writable, options?: {
|
107
|
+
destination?: string;
|
108
|
+
cleanup?: boolean;
|
109
|
+
}): Promise<void>;
|
110
|
+
}
|
@@ -14,7 +14,7 @@ import { Buffer } from "node:buffer";
|
|
14
14
|
* @returns {Buffer} - A new Buffer of exactly `len` bytes containing:
|
15
15
|
* 1. The value's bytes in little-endian order (least significant byte first)
|
16
16
|
* 2. Zero padding in any remaining higher-order bytes
|
17
|
-
*
|
18
|
-
*
|
17
|
+
*
|
18
|
+
* @throws {RangeError} - If the length is not positive or the value is negative.
|
19
19
|
*/
|
20
20
|
export declare function toBytes(value: number, len: number): Buffer;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@js-ak/excel-toolbox",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.9.0",
|
4
4
|
"description": "excel-toolbox",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public",
|
@@ -44,7 +44,9 @@
|
|
44
44
|
"lint": "eslint . --ext .ts",
|
45
45
|
"postbuild:esm": "node scripts/write-esm-package.js",
|
46
46
|
"postbuild:cjs": "node scripts/write-cjs-package.js",
|
47
|
-
"test": "vitest run",
|
47
|
+
"test:unit": "vitest run --config vitest.unit.config.js",
|
48
|
+
"test:integration": "vitest run --config vitest.integration.config.js",
|
49
|
+
"test": "npm run test:unit && npm run test:integration",
|
48
50
|
"test:watch": "vitest",
|
49
51
|
"test:coverage": "vitest run --coverage"
|
50
52
|
},
|
File without changes
|
File without changes
|
File without changes
|