@js-ak/excel-toolbox 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -0
- package/build/cjs/index.js +17 -0
- package/build/cjs/lib/index.js +18 -0
- package/build/cjs/lib/merge-sheets-to-base-file-process.js +96 -0
- package/build/cjs/lib/merge-sheets-to-base-file-sync.js +68 -0
- package/build/cjs/lib/merge-sheets-to-base-file.js +68 -0
- package/build/cjs/lib/utils/get-max-row-number.js +23 -0
- package/build/cjs/lib/utils/index.js +23 -0
- package/build/cjs/lib/utils/is-same-buffer.js +13 -0
- package/build/cjs/lib/utils/remove-sheet-by-name.js +45 -0
- package/build/cjs/lib/utils/remove-sheet-from-content-types.js +13 -0
- package/build/cjs/lib/utils/remove-sheet-from-rels.js +13 -0
- package/build/cjs/lib/utils/remove-sheet-from-workbook.js +13 -0
- package/build/cjs/lib/utils/shift-cell-ref.js +26 -0
- package/build/cjs/lib/xml/build-merged-sheet.js +32 -0
- package/build/cjs/lib/xml/extract-rows-from-sheet.js +65 -0
- package/build/cjs/lib/xml/extract-xml-from-sheet.js +49 -0
- package/build/cjs/lib/xml/extract-xml-from-system-content.js +53 -0
- package/build/cjs/lib/xml/index.js +21 -0
- package/build/cjs/lib/xml/shift-row-indices.js +36 -0
- package/build/cjs/lib/zip/constants.js +32 -0
- package/build/cjs/lib/zip/create-sync.js +84 -0
- package/build/cjs/lib/zip/create.js +89 -0
- package/build/cjs/lib/zip/index.js +20 -0
- package/build/cjs/lib/zip/read-sync.js +57 -0
- package/build/cjs/lib/zip/read.js +62 -0
- package/build/cjs/lib/zip/utils.js +158 -0
- package/build/esm/lib/index.js +2 -0
- package/build/esm/lib/merge-sheets-to-base-file-process.js +69 -0
- package/build/esm/lib/merge-sheets-to-base-file-sync.js +41 -0
- package/build/esm/lib/merge-sheets-to-base-file.js +41 -0
- package/build/esm/lib/utils/get-max-row-number.js +19 -0
- package/build/esm/lib/utils/index.js +7 -0
- package/build/esm/lib/utils/is-same-buffer.js +9 -0
- package/build/esm/lib/utils/remove-sheet-by-name.js +41 -0
- package/build/esm/lib/utils/remove-sheet-from-content-types.js +9 -0
- package/build/esm/lib/utils/remove-sheet-from-rels.js +9 -0
- package/build/esm/lib/utils/remove-sheet-from-workbook.js +9 -0
- package/build/esm/lib/utils/shift-cell-ref.js +22 -0
- package/build/esm/lib/xml/build-merged-sheet.js +28 -0
- package/build/{lib → esm/lib}/xml/extract-rows-from-sheet.js +1 -1
- package/build/esm/lib/xml/index.js +5 -0
- package/build/{lib/zip/create.js → esm/lib/zip/create-sync.js} +1 -1
- package/build/esm/lib/zip/create.js +82 -0
- package/build/esm/lib/zip/index.js +4 -0
- package/build/{lib/zip/read.js → esm/lib/zip/read-sync.js} +1 -1
- package/build/esm/lib/zip/read.js +55 -0
- package/build/{lib → esm/lib}/zip/utils.js +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/lib/index.d.ts +2 -0
- package/build/types/lib/merge-sheets-to-base-file-process.d.ts +27 -0
- package/build/{lib/merge-sheets-to-base-file.d.ts → types/lib/merge-sheets-to-base-file-sync.d.ts} +5 -5
- package/build/types/lib/merge-sheets-to-base-file.d.ts +29 -0
- package/build/types/lib/utils/get-max-row-number.d.ts +6 -0
- package/build/types/lib/utils/index.d.ts +7 -0
- package/build/types/lib/utils/is-same-buffer.d.ts +9 -0
- package/build/types/lib/utils/remove-sheet-by-name.d.ts +7 -0
- package/build/types/lib/utils/remove-sheet-from-content-types.d.ts +7 -0
- package/build/types/lib/utils/remove-sheet-from-rels.d.ts +7 -0
- package/build/types/lib/utils/remove-sheet-from-workbook.d.ts +7 -0
- package/build/types/lib/utils/shift-cell-ref.d.ts +13 -0
- package/build/{lib → types/lib}/xml/build-merged-sheet.d.ts +7 -8
- package/build/{lib → types/lib}/xml/extract-rows-from-sheet.d.ts +0 -1
- package/build/{lib → types/lib}/xml/extract-xml-from-sheet.d.ts +0 -1
- package/build/{lib → types/lib}/xml/extract-xml-from-system-content.d.ts +0 -1
- package/build/types/lib/xml/index.d.ts +5 -0
- package/build/{lib → types/lib}/xml/shift-row-indices.d.ts +0 -1
- package/build/{lib → types/lib}/zip/constants.d.ts +0 -1
- package/build/types/lib/zip/create-sync.d.ts +12 -0
- package/build/{lib → types/lib}/zip/create.d.ts +1 -2
- package/build/types/lib/zip/index.d.ts +4 -0
- package/build/types/lib/zip/read-sync.d.ts +10 -0
- package/build/{lib → types/lib}/zip/read.d.ts +1 -4
- package/build/{lib → types/lib}/zip/utils.d.ts +1 -2
- package/package.json +22 -8
- package/build/index.d.ts +0 -2
- package/build/lib/index.d.ts +0 -2
- package/build/lib/index.d.ts.map +0 -1
- package/build/lib/index.js +0 -1
- package/build/lib/merge-sheets-to-base-file.d.ts.map +0 -1
- package/build/lib/merge-sheets-to-base-file.js +0 -190
- package/build/lib/xml/build-merged-sheet.d.ts.map +0 -1
- package/build/lib/xml/build-merged-sheet.js +0 -32
- package/build/lib/xml/extract-rows-from-sheet.d.ts.map +0 -1
- package/build/lib/xml/extract-xml-from-sheet.d.ts.map +0 -1
- package/build/lib/xml/extract-xml-from-system-content.d.ts.map +0 -1
- package/build/lib/xml/shift-row-indices.d.ts.map +0 -1
- package/build/lib/zip/constants.d.ts.map +0 -1
- package/build/lib/zip/create.d.ts.map +0 -1
- package/build/lib/zip/index.d.ts +0 -3
- package/build/lib/zip/index.d.ts.map +0 -1
- package/build/lib/zip/index.js +0 -2
- package/build/lib/zip/read.d.ts.map +0 -1
- package/build/lib/zip/utils.d.ts.map +0 -1
- /package/build/{index.js → esm/index.js} +0 -0
- /package/build/{lib → esm/lib}/xml/extract-xml-from-sheet.js +0 -0
- /package/build/{lib → esm/lib}/xml/extract-xml-from-system-content.js +0 -0
- /package/build/{lib → esm/lib}/xml/shift-row-indices.js +0 -0
- /package/build/{lib → esm/lib}/zip/constants.js +0 -0
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* Removes the specified sheet from the Content_Types.xml file.
|
3
|
+
* @param {string} xml - The Content_Types.xml file contents as a string
|
4
|
+
* @param {number} sheetIndex - The 1-based index of the sheet to remove
|
5
|
+
* @returns {string} - The modified Content_Types.xml file contents
|
6
|
+
*/
|
7
|
+
export declare function removeSheetFromContentTypes(xml: string, sheetIndex: number): string;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* Removes the specified sheet from the workbook relationships file (xl/_rels/workbook.xml.rels).
|
3
|
+
* @param {string} xml - The workbook relationships file contents as a string
|
4
|
+
* @param {number} sheetIndex - The 1-based index of the sheet to remove
|
5
|
+
* @returns {string} - The modified workbook relationships file contents
|
6
|
+
*/
|
7
|
+
export declare function removeSheetFromRels(xml: string, sheetIndex: number): string;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* Removes the specified sheet from the workbook (xl/workbook.xml).
|
3
|
+
* @param {string} xml - The workbook file contents as a string
|
4
|
+
* @param {number} sheetIndex - The 1-based index of the sheet to remove
|
5
|
+
* @returns {string} - The modified workbook file contents
|
6
|
+
*/
|
7
|
+
export declare function removeSheetFromWorkbook(xml: string, sheetIndex: number): string;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* Shifts the row number in a cell reference by the specified number of rows.
|
3
|
+
* The function takes a cell reference string in the format "A1" and a row shift value.
|
4
|
+
* It returns the shifted cell reference string.
|
5
|
+
*
|
6
|
+
* @example
|
7
|
+
* // Shifts the cell reference "A1" down by 2 rows, resulting in "A3"
|
8
|
+
* shiftCellRef('A1', 2);
|
9
|
+
* @param {string} cellRef - The cell reference string to be shifted
|
10
|
+
* @param {number} rowShift - The number of rows to shift the reference by
|
11
|
+
* @returns {string} - The shifted cell reference string
|
12
|
+
*/
|
13
|
+
export declare function shiftCellRef(cellRef: string, rowShift: number): string;
|
@@ -2,16 +2,15 @@
|
|
2
2
|
* Builds a new XML string for a merged Excel sheet by combining the original XML
|
3
3
|
* with merged rows and optional cell merge information.
|
4
4
|
*
|
5
|
-
* This function replaces the
|
6
|
-
* and optionally adds
|
5
|
+
* This function replaces the <sheetData> section in the original XML with the provided merged rows,
|
6
|
+
* and optionally adds <mergeCells> definitions after the </sheetData> tag.
|
7
7
|
*
|
8
|
-
* @param {string} originalXml - The original XML string of the Excel worksheet
|
9
|
-
* @param {string[]} mergedRows - Array of XML strings representing each row in the merged sheet
|
10
|
-
* @param {Object[]} [mergeCells] - Optional array of merge cell definitions
|
11
|
-
* Each object should have a 'ref' property specifying the merge range (e.g., "A1:B2")
|
12
|
-
* @returns {string} - The reconstructed XML string with merged content
|
8
|
+
* @param {string} originalXml - The original XML string of the Excel worksheet.
|
9
|
+
* @param {string[]} mergedRows - Array of XML strings representing each row in the merged sheet.
|
10
|
+
* @param {Object[]} [mergeCells] - Optional array of merge cell definitions.
|
11
|
+
* Each object should have a 'ref' property specifying the merge range (e.g., "A1:B2").
|
12
|
+
* @returns {string} - The reconstructed XML string with merged content.
|
13
13
|
*/
|
14
14
|
export declare function buildMergedSheet(originalXml: string, mergedRows: string[], mergeCells?: {
|
15
15
|
ref: string;
|
16
16
|
}[]): string;
|
17
|
-
//# sourceMappingURL=build-merged-sheet.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import { Buffer } from "node:buffer";
|
4
|
+
/**
|
5
|
+
* Creates a ZIP archive from a collection of files.
|
6
|
+
*
|
7
|
+
* @param {Object.<string, Buffer|string>} files - An object with file paths as keys and either Buffer or string content as values.
|
8
|
+
* @returns {Buffer} - The ZIP archive as a Buffer.
|
9
|
+
*/
|
10
|
+
export declare function createSync(files: {
|
11
|
+
[path: string]: Buffer | string;
|
12
|
+
}): Buffer;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
/**
|
4
|
+
* Parses a ZIP archive from a buffer and extracts the files within.
|
5
|
+
*
|
6
|
+
* @param {Buffer} buffer - The buffer containing the ZIP archive data.
|
7
|
+
* @returns {Object.<string, string>} - An object where keys are file names and values are file contents.
|
8
|
+
* @throws {Error} - Throws an error if an unsupported compression method is encountered or if decompression fails.
|
9
|
+
*/
|
10
|
+
export declare function readSync(buffer: Buffer): Record<string, string>;
|
@@ -7,7 +7,4 @@
|
|
7
7
|
* @returns {Object.<string, string>} - An object where keys are file names and values are file contents.
|
8
8
|
* @throws {Error} - Throws an error if an unsupported compression method is encountered or if decompression fails.
|
9
9
|
*/
|
10
|
-
export declare function read(buffer: Buffer):
|
11
|
-
[s: string]: string;
|
12
|
-
};
|
13
|
-
//# sourceMappingURL=read.d.ts.map
|
10
|
+
export declare function read(buffer: Buffer): Promise<Record<string, string>>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
/// <reference types="node" />
|
3
|
-
import { Buffer } from "buffer";
|
3
|
+
import { Buffer } from "node:buffer";
|
4
4
|
/**
|
5
5
|
* Computes a CRC-32 checksum for the given Buffer using the standard IEEE 802.3 polynomial.
|
6
6
|
* This implementation uses a precomputed lookup table for optimal performance.
|
@@ -58,4 +58,3 @@ export declare function dosTime(date: Date): Buffer;
|
|
58
58
|
* (though this is currently not explicitly checked)
|
59
59
|
*/
|
60
60
|
export declare function toBytes(value: number, len: number): Buffer;
|
61
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/package.json
CHANGED
@@ -1,26 +1,40 @@
|
|
1
1
|
{
|
2
2
|
"name": "@js-ak/excel-toolbox",
|
3
|
-
"version": "1.1
|
3
|
+
"version": "1.2.1",
|
4
4
|
"description": "excel-toolbox",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public",
|
7
7
|
"registry": "https://registry.npmjs.org/"
|
8
8
|
},
|
9
9
|
"type": "module",
|
10
|
-
"main": "build/index.js",
|
11
|
-
"
|
10
|
+
"main": "build/cjs/index.js",
|
11
|
+
"module": "build/esm/index.js",
|
12
|
+
"types": "build/types/index.d.ts",
|
13
|
+
"exports": {
|
14
|
+
".": {
|
15
|
+
"default": "./build/esm/index.js",
|
16
|
+
"require": "./build/cjs/index.js",
|
17
|
+
"import": "./build/esm/index.js",
|
18
|
+
"types": "./build/types/index.d.ts"
|
19
|
+
}
|
20
|
+
},
|
12
21
|
"files": [
|
13
|
-
"build/lib",
|
14
|
-
"build/index.js",
|
15
|
-
"build/
|
22
|
+
"build/esm/lib",
|
23
|
+
"build/esm/index.js",
|
24
|
+
"build/cjs/lib",
|
25
|
+
"build/cjs/index.js",
|
26
|
+
"build/types/lib",
|
27
|
+
"build/types/index.d.ts",
|
16
28
|
"LICENSE",
|
17
29
|
"README.md",
|
18
30
|
"package.json"
|
19
31
|
],
|
20
32
|
"scripts": {
|
21
|
-
"build": "
|
33
|
+
"build": "npm run build:esm && npm run build:cjs",
|
34
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
35
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
22
36
|
"lint": "eslint . --ext .ts",
|
23
|
-
"test": "npm run build && node ./build/test/index.js"
|
37
|
+
"test": "npm run build && node ./build/esm/test/index.js"
|
24
38
|
},
|
25
39
|
"repository": {
|
26
40
|
"type": "git",
|
package/build/index.d.ts
DELETED
package/build/lib/index.d.ts
DELETED
package/build/lib/index.d.ts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC"}
|
package/build/lib/index.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from "./merge-sheets-to-base-file.js";
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"merge-sheets-to-base-file.d.ts","sourceRoot":"","sources":["../../src/lib/merge-sheets-to-base-file.ts"],"names":[],"mappings":";;AAMA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC3C,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B,GAAG,MAAM,CAgGT"}
|
@@ -1,190 +0,0 @@
|
|
1
|
-
import { buildMergedSheet } from "./xml/build-merged-sheet.js";
|
2
|
-
import { extractRowsFromSheet } from "./xml/extract-rows-from-sheet.js";
|
3
|
-
import { shiftRowIndices } from "./xml/shift-row-indices.js";
|
4
|
-
import * as Zip from "./zip/index.js";
|
5
|
-
/**
|
6
|
-
* Merge rows from other Excel files into a base Excel file.
|
7
|
-
* The output is a new Excel file with the merged content.
|
8
|
-
*
|
9
|
-
* @param {Object} data
|
10
|
-
* @param {Object[]} data.additions
|
11
|
-
* @param {Buffer} data.additions.file - The file to extract rows from
|
12
|
-
* @param {number} data.additions.sheetIndex - The 1-based index of the sheet to extract rows from
|
13
|
-
* @param {Buffer} data.baseFile - The base file to add rows to
|
14
|
-
* @param {number} [data.baseSheetIndex=1] - The 1-based index of the sheet in the base file to add rows to
|
15
|
-
* @param {number} [data.gap=1] - The number of empty rows to insert between each added section
|
16
|
-
* @param {string[]} [data.sheetNamesToRemove=[]] - The names of sheets to remove from the output file
|
17
|
-
* @param {number[]} [data.sheetsToRemove=[]] - The 1-based indices of sheets to remove from the output file
|
18
|
-
* @returns {Buffer} - The merged Excel file
|
19
|
-
*/
|
20
|
-
export function mergeSheetsToBaseFile(data) {
|
21
|
-
const { additions = [], baseFile, baseSheetIndex = 1, gap = 1, sheetNamesToRemove = [], sheetsToRemove = [], } = data;
|
22
|
-
const baseFiles = Zip.read(baseFile);
|
23
|
-
const basePath = `xl/worksheets/sheet${baseSheetIndex}.xml`;
|
24
|
-
if (!baseFiles[basePath]) {
|
25
|
-
throw new Error(`Base file does not contain ${basePath}`);
|
26
|
-
}
|
27
|
-
const { lastRowNumber, mergeCells: baseMergeCells, rows: baseRows, } = extractRowsFromSheet(baseFiles[basePath]);
|
28
|
-
const allRows = [...baseRows];
|
29
|
-
const allMergeCells = [...(baseMergeCells || [])];
|
30
|
-
let currentRowOffset = lastRowNumber + gap;
|
31
|
-
for (const { file, sheetIndex } of additions) {
|
32
|
-
const files = isSameBuffer(file, baseFile) ? baseFiles : Zip.read(file);
|
33
|
-
const sheetPath = `xl/worksheets/sheet${sheetIndex}.xml`;
|
34
|
-
if (!files[sheetPath]) {
|
35
|
-
throw new Error(`File does not contain ${sheetPath}`);
|
36
|
-
}
|
37
|
-
const { mergeCells, rows } = extractRowsFromSheet(files[sheetPath]);
|
38
|
-
const shiftedRows = shiftRowIndices(rows, currentRowOffset);
|
39
|
-
const shiftedMergeCells = (mergeCells || []).map(cell => {
|
40
|
-
const [start, end] = cell.ref.split(":");
|
41
|
-
if (!start || !end) {
|
42
|
-
return cell;
|
43
|
-
}
|
44
|
-
const shiftedStart = shiftCellRef(start, currentRowOffset);
|
45
|
-
const shiftedEnd = shiftCellRef(end, currentRowOffset);
|
46
|
-
return { ...cell, ref: `${shiftedStart}:${shiftedEnd}` };
|
47
|
-
});
|
48
|
-
allRows.push(...shiftedRows);
|
49
|
-
allMergeCells.push(...shiftedMergeCells);
|
50
|
-
currentRowOffset += getMaxRowNumber(rows) + gap;
|
51
|
-
}
|
52
|
-
const mergedXml = buildMergedSheet(baseFiles[basePath], allRows, allMergeCells);
|
53
|
-
baseFiles[basePath] = mergedXml;
|
54
|
-
for (const sheetIndex of sheetsToRemove) {
|
55
|
-
const sheetPath = `xl/worksheets/sheet${sheetIndex}.xml`;
|
56
|
-
delete baseFiles[sheetPath];
|
57
|
-
if (baseFiles["xl/workbook.xml"]) {
|
58
|
-
baseFiles["xl/workbook.xml"] = removeSheetFromWorkbook(baseFiles["xl/workbook.xml"], sheetIndex);
|
59
|
-
}
|
60
|
-
if (baseFiles["xl/_rels/workbook.xml.rels"]) {
|
61
|
-
baseFiles["xl/_rels/workbook.xml.rels"] = removeSheetFromRels(baseFiles["xl/_rels/workbook.xml.rels"], sheetIndex);
|
62
|
-
}
|
63
|
-
if (baseFiles["[Content_Types].xml"]) {
|
64
|
-
baseFiles["[Content_Types].xml"] = removeSheetFromContentTypes(baseFiles["[Content_Types].xml"], sheetIndex);
|
65
|
-
}
|
66
|
-
}
|
67
|
-
for (const sheetName of sheetNamesToRemove) {
|
68
|
-
removeSheetByName(baseFiles, sheetName);
|
69
|
-
}
|
70
|
-
const zip = Zip.create(baseFiles);
|
71
|
-
return zip;
|
72
|
-
}
|
73
|
-
/**
|
74
|
-
* Shifts the row number in a cell reference by the specified number of rows.
|
75
|
-
* The function takes a cell reference string in the format "A1" and a row shift value.
|
76
|
-
* It returns the shifted cell reference string.
|
77
|
-
*
|
78
|
-
* @example
|
79
|
-
* // Shifts the cell reference "A1" down by 2 rows, resulting in "A3"
|
80
|
-
* shiftCellRef('A1', 2);
|
81
|
-
* @param {string} cellRef - The cell reference string to be shifted
|
82
|
-
* @param {number} rowShift - The number of rows to shift the reference by
|
83
|
-
* @returns {string} - The shifted cell reference string
|
84
|
-
*/
|
85
|
-
function shiftCellRef(cellRef, rowShift) {
|
86
|
-
const match = cellRef.match(/^([A-Z]+)(\d+)$/);
|
87
|
-
if (!match)
|
88
|
-
return cellRef;
|
89
|
-
const col = match[1];
|
90
|
-
if (!match[2])
|
91
|
-
return cellRef;
|
92
|
-
const row = parseInt(match[2], 10);
|
93
|
-
return `${col}${row + rowShift}`;
|
94
|
-
}
|
95
|
-
/**
|
96
|
-
* Checks if two Buffers are the same
|
97
|
-
* @param {Buffer} buf1 - the first Buffer
|
98
|
-
* @param {Buffer} buf2 - the second Buffer
|
99
|
-
* @returns {boolean} - true if the Buffers are the same, false otherwise
|
100
|
-
*/
|
101
|
-
function isSameBuffer(buf1, buf2) {
|
102
|
-
return buf1.equals(buf2);
|
103
|
-
}
|
104
|
-
/**
|
105
|
-
* Finds the maximum row number in a list of <row> elements.
|
106
|
-
* @param {string[]} rows - An array of strings, each representing a <row> element.
|
107
|
-
* @returns {number} - The maximum row number.
|
108
|
-
*/
|
109
|
-
function getMaxRowNumber(rows) {
|
110
|
-
let max = 0;
|
111
|
-
for (const row of rows) {
|
112
|
-
const match = row.match(/<row[^>]* r="(\d+)"/);
|
113
|
-
if (match) {
|
114
|
-
if (!match[1])
|
115
|
-
continue;
|
116
|
-
const num = parseInt(match[1], 10);
|
117
|
-
if (num > max)
|
118
|
-
max = num;
|
119
|
-
}
|
120
|
-
}
|
121
|
-
return max;
|
122
|
-
}
|
123
|
-
/**
|
124
|
-
* Removes the specified sheet from the workbook (xl/workbook.xml).
|
125
|
-
* @param {string} xml - The workbook file contents as a string
|
126
|
-
* @param {number} sheetIndex - The 1-based index of the sheet to remove
|
127
|
-
* @returns {string} - The modified workbook file contents
|
128
|
-
*/
|
129
|
-
function removeSheetFromWorkbook(xml, sheetIndex) {
|
130
|
-
return xml.replace(new RegExp(`<sheet[^>]+sheetId=["']${sheetIndex}["'][^>]*/>`, "g"), "");
|
131
|
-
}
|
132
|
-
/**
|
133
|
-
* Removes the specified sheet from the workbook relationships file (xl/_rels/workbook.xml.rels).
|
134
|
-
* @param {string} xml - The workbook relationships file contents as a string
|
135
|
-
* @param {number} sheetIndex - The 1-based index of the sheet to remove
|
136
|
-
* @returns {string} - The modified workbook relationships file contents
|
137
|
-
*/
|
138
|
-
function removeSheetFromRels(xml, sheetIndex) {
|
139
|
-
return xml.replace(new RegExp(`<Relationship[^>]+Target=["']worksheets/sheet${sheetIndex}\\.xml["'][^>]*/>`, "g"), "");
|
140
|
-
}
|
141
|
-
/**
|
142
|
-
* Removes the specified sheet from the Content_Types.xml file.
|
143
|
-
* @param {string} xml - The Content_Types.xml file contents as a string
|
144
|
-
* @param {number} sheetIndex - The 1-based index of the sheet to remove
|
145
|
-
* @returns {string} - The modified Content_Types.xml file contents
|
146
|
-
*/
|
147
|
-
function removeSheetFromContentTypes(xml, sheetIndex) {
|
148
|
-
return xml.replace(new RegExp(`<Override[^>]+PartName=["']/xl/worksheets/sheet${sheetIndex}\\.xml["'][^>]*/>`, "g"), "");
|
149
|
-
}
|
150
|
-
/**
|
151
|
-
* Removes a sheet from the Excel workbook by name.
|
152
|
-
* @param {Object.<string, string | Buffer>} files - The dictionary of files in the workbook.
|
153
|
-
* @param {string} sheetName - The name of the sheet to remove.
|
154
|
-
* @returns {void}
|
155
|
-
*/
|
156
|
-
function removeSheetByName(files, sheetName) {
|
157
|
-
const workbookXml = files["xl/workbook.xml"];
|
158
|
-
const relsXml = files["xl/_rels/workbook.xml.rels"];
|
159
|
-
if (!workbookXml || !relsXml) {
|
160
|
-
return;
|
161
|
-
}
|
162
|
-
const sheetMatch = workbookXml.match(new RegExp(`<sheet[^>]+name=["']${sheetName}["'][^>]*/>`));
|
163
|
-
if (!sheetMatch) {
|
164
|
-
return;
|
165
|
-
}
|
166
|
-
const sheetTag = sheetMatch[0];
|
167
|
-
const sheetIdMatch = sheetTag.match(/sheetId=["'](\d+)["']/);
|
168
|
-
const ridMatch = sheetTag.match(/r:id=["'](rId\d+)["']/);
|
169
|
-
if (!sheetIdMatch || !ridMatch) {
|
170
|
-
return;
|
171
|
-
}
|
172
|
-
const relId = ridMatch[1];
|
173
|
-
const relMatch = relsXml.match(new RegExp(`<Relationship[^>]+Id=["']${relId}["'][^>]+Target=["']([^"']+)["'][^>]*/>`));
|
174
|
-
if (!relMatch) {
|
175
|
-
return;
|
176
|
-
}
|
177
|
-
const relTag = relMatch[0];
|
178
|
-
const targetMatch = relTag.match(/Target=["']([^"']+)["']/);
|
179
|
-
if (!targetMatch) {
|
180
|
-
return;
|
181
|
-
}
|
182
|
-
const targetPath = `xl/${targetMatch[1]}`.replace(/\\/g, "/");
|
183
|
-
delete files[targetPath];
|
184
|
-
files["xl/workbook.xml"] = workbookXml.replace(sheetTag, "");
|
185
|
-
files["xl/_rels/workbook.xml.rels"] = relsXml.replace(relTag, "");
|
186
|
-
const contentTypes = files["[Content_Types].xml"];
|
187
|
-
if (contentTypes) {
|
188
|
-
files["[Content_Types].xml"] = contentTypes.replace(new RegExp(`<Override[^>]+PartName=["']/${targetPath}["'][^>]*/>`, "g"), "");
|
189
|
-
}
|
190
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"build-merged-sheet.d.ts","sourceRoot":"","sources":["../../../src/lib/xml/build-merged-sheet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC/B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAAE,EACpB,UAAU,GAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EAAO,GAChC,MAAM,CAwBR"}
|
@@ -1,32 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Builds a new XML string for a merged Excel sheet by combining the original XML
|
3
|
-
* with merged rows and optional cell merge information.
|
4
|
-
*
|
5
|
-
* This function replaces the sheet data content in the original XML with the merged rows
|
6
|
-
* and optionally adds merge cell definitions at the end of the sheet data.
|
7
|
-
*
|
8
|
-
* @param {string} originalXml - The original XML string of the Excel worksheet
|
9
|
-
* @param {string[]} mergedRows - Array of XML strings representing each row in the merged sheet
|
10
|
-
* @param {Object[]} [mergeCells] - Optional array of merge cell definitions
|
11
|
-
* Each object should have a 'ref' property specifying the merge range (e.g., "A1:B2")
|
12
|
-
* @returns {string} - The reconstructed XML string with merged content
|
13
|
-
*/
|
14
|
-
export function buildMergedSheet(originalXml, mergedRows, mergeCells = []) {
|
15
|
-
// Replace the entire sheetData section in the original XML with our merged rows
|
16
|
-
// The regex matches:
|
17
|
-
// - Opening <sheetData> tag with any attributes
|
18
|
-
// - Any content between opening and closing tags (including line breaks)
|
19
|
-
// - Closing </sheetData> tag
|
20
|
-
let xmlData = originalXml.replace(/<sheetData[^>]*>[\s\S]*?<\/sheetData>/, `<sheetData>\n${mergedRows.join("\n")}\n</sheetData>`);
|
21
|
-
// If merge cells were specified, add them after the sheetData section
|
22
|
-
if (mergeCells.length > 0) {
|
23
|
-
// Create mergeCells XML section:
|
24
|
-
// - Includes count attribute with total number of merges
|
25
|
-
// - Contains one mergeCell element for each merge definition
|
26
|
-
const mergeCellsXml = `<mergeCells count="${mergeCells.length}">${mergeCells.map(mc => `<mergeCell ref="${mc.ref}"/>`).join("")}</mergeCells>`;
|
27
|
-
// Insert the mergeCells section immediately after the sheetData closing tag
|
28
|
-
xmlData = xmlData.replace("</sheetData>", `</sheetData>${mergeCellsXml}`);
|
29
|
-
}
|
30
|
-
// Return the fully reconstructed XML
|
31
|
-
return xmlData;
|
32
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"extract-rows-from-sheet.d.ts","sourceRoot":"","sources":["../../../src/lib/xml/extract-rows-from-sheet.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG;IAC7D,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC9B,CA+CA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"extract-xml-from-sheet.d.ts","sourceRoot":"","sources":["../../../src/lib/xml/extract-xml-from-sheet.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAmC1D"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"extract-xml-from-system-content.d.ts","sourceRoot":"","sources":["../../../src/lib/xml/extract-xml-from-system-content.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,2BAA2B,WAAY,MAAM,QAAQ,MAAM,KAAG,MAqC1E,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"shift-row-indices.d.ts","sourceRoot":"","sources":["../../../src/lib/xml/shift-row-indices.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAsBxE"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/zip/constants.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;GAIG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,QAAiC,CAAC;AAErE;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,QAAiC,CAAC;AAErE;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,QAAiC,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/lib/zip/create.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAWrC;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,MAAM,CAkFzE"}
|
package/build/lib/zip/index.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/zip/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
|
package/build/lib/zip/index.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/lib/zip/read.ts"],"names":[],"mappings":";;AAEA;;;;;;GAMG;AAEH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CA+C5D"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/zip/utils.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAyChC;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA2BzC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAyB1C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAkB1D"}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|