@cj-tech-master/excelts 1.6.1 → 1.6.2-canary.20251223042142.4d33ec6
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 +0 -15
- package/README_zh.md +0 -15
- package/dist/browser/excelts.iife.js +1 -22
- package/dist/browser/excelts.iife.js.map +1 -1
- package/dist/browser/excelts.iife.min.js +1 -1
- package/dist/cjs/doc/worksheet.js +2 -21
- package/dist/cjs/stream/xlsx/hyperlink-reader.js +1 -1
- package/dist/cjs/stream/xlsx/workbook-reader.js +7 -4
- package/dist/cjs/stream/xlsx/workbook-writer.js +37 -23
- package/dist/cjs/stream/xlsx/worksheet-reader.js +12 -8
- package/dist/cjs/stream/xlsx/worksheet-writer.js +12 -6
- package/dist/esm/doc/worksheet.js +2 -21
- package/dist/esm/stream/xlsx/hyperlink-reader.js +1 -1
- package/dist/esm/stream/xlsx/workbook-reader.js +7 -4
- package/dist/esm/stream/xlsx/workbook-writer.js +37 -23
- package/dist/esm/stream/xlsx/worksheet-reader.js +12 -8
- package/dist/esm/stream/xlsx/worksheet-writer.js +12 -6
- package/dist/types/doc/worksheet.d.ts +6 -27
- package/dist/types/index.d.ts +3 -0
- package/dist/types/stream/xlsx/hyperlink-reader.d.ts +11 -11
- package/dist/types/stream/xlsx/workbook-reader.d.ts +125 -36
- package/dist/types/stream/xlsx/workbook-writer.d.ts +105 -22
- package/dist/types/stream/xlsx/worksheet-reader.d.ts +40 -22
- package/dist/types/stream/xlsx/worksheet-writer.d.ts +83 -49
- package/dist/types/types.d.ts +4 -16
- package/package.json +5 -5
|
@@ -25,7 +25,7 @@ class WorksheetReader extends EventEmitter {
|
|
|
25
25
|
destroy() {
|
|
26
26
|
throw new Error("Invalid Operation: destroy");
|
|
27
27
|
}
|
|
28
|
-
// return the current dimensions of the
|
|
28
|
+
// return the current dimensions of the reader
|
|
29
29
|
get dimensions() {
|
|
30
30
|
return this._dimensions;
|
|
31
31
|
}
|
|
@@ -44,7 +44,7 @@ class WorksheetReader extends EventEmitter {
|
|
|
44
44
|
if (col) {
|
|
45
45
|
return col;
|
|
46
46
|
}
|
|
47
|
-
//
|
|
47
|
+
// otherwise, assume letter
|
|
48
48
|
c = colCache.l2n(c);
|
|
49
49
|
}
|
|
50
50
|
if (!this._columns) {
|
|
@@ -85,9 +85,9 @@ class WorksheetReader extends EventEmitter {
|
|
|
85
85
|
}
|
|
86
86
|
async *[Symbol.asyncIterator]() {
|
|
87
87
|
for await (const events of this.parse()) {
|
|
88
|
-
for (const
|
|
89
|
-
if (eventType === "row") {
|
|
90
|
-
yield value;
|
|
88
|
+
for (const event of events) {
|
|
89
|
+
if (event.eventType === "row") {
|
|
90
|
+
yield event.value;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -283,6 +283,7 @@ class WorksheetReader extends EventEmitter {
|
|
|
283
283
|
cell.value = sharedStrings[index];
|
|
284
284
|
}
|
|
285
285
|
else {
|
|
286
|
+
// Streaming format - unresolved shared string reference
|
|
286
287
|
cell.value = {
|
|
287
288
|
sharedString: index
|
|
288
289
|
};
|
|
@@ -299,19 +300,22 @@ class WorksheetReader extends EventEmitter {
|
|
|
299
300
|
case "b":
|
|
300
301
|
cell.value = parseInt(c.v.text, 10) !== 0;
|
|
301
302
|
break;
|
|
302
|
-
default:
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
default: {
|
|
304
|
+
const numFmtStr = typeof cell.numFmt === "string" ? cell.numFmt : cell.numFmt?.formatCode;
|
|
305
|
+
if (numFmtStr && isDateFmt(numFmtStr)) {
|
|
306
|
+
cell.value = excelToDate(parseFloat(c.v.text), properties?.model?.date1904);
|
|
305
307
|
}
|
|
306
308
|
else {
|
|
307
309
|
cell.value = parseFloat(c.v.text);
|
|
308
310
|
}
|
|
309
311
|
break;
|
|
312
|
+
}
|
|
310
313
|
}
|
|
311
314
|
}
|
|
312
315
|
if (hyperlinks) {
|
|
313
316
|
const hyperlink = hyperlinks[c.ref];
|
|
314
317
|
if (hyperlink) {
|
|
318
|
+
// Streaming-specific: assign text and hyperlink for further processing
|
|
315
319
|
cell.text = cell.value;
|
|
316
320
|
cell.value = undefined;
|
|
317
321
|
cell.hyperlink = hyperlink;
|
|
@@ -275,20 +275,26 @@ class WorksheetWriter {
|
|
|
275
275
|
}
|
|
276
276
|
// iterate over every uncommitted row in the worksheet, including maybe empty rows
|
|
277
277
|
eachRow(options, iteratee) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
278
|
+
let callback;
|
|
279
|
+
let opts;
|
|
280
|
+
if (typeof options === "function") {
|
|
281
|
+
callback = options;
|
|
282
|
+
opts = undefined;
|
|
281
283
|
}
|
|
282
|
-
|
|
284
|
+
else {
|
|
285
|
+
callback = iteratee;
|
|
286
|
+
opts = options;
|
|
287
|
+
}
|
|
288
|
+
if (opts && opts.includeEmpty) {
|
|
283
289
|
const n = this._nextRow;
|
|
284
290
|
for (let i = this._rowZero; i < n; i++) {
|
|
285
|
-
|
|
291
|
+
callback(this.getRow(i), i);
|
|
286
292
|
}
|
|
287
293
|
}
|
|
288
294
|
else {
|
|
289
295
|
this._rows.forEach(row => {
|
|
290
296
|
if (row.hasValues) {
|
|
291
|
-
|
|
297
|
+
callback(row, row.number);
|
|
292
298
|
}
|
|
293
299
|
});
|
|
294
300
|
}
|
|
@@ -220,33 +220,12 @@ declare class Worksheet {
|
|
|
220
220
|
* A count of the number of rows that have values. If a mid-document row is empty, it will not be included in the count.
|
|
221
221
|
*/
|
|
222
222
|
get actualRowCount(): number;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
*/
|
|
230
|
-
getRows(start: number, length: number): Row[] | undefined;
|
|
231
|
-
/**
|
|
232
|
-
* Add a couple of Rows by key-value, after the last current row, using the column keys,
|
|
233
|
-
* or add a row by contiguous Array (assign to columns A, B & C)
|
|
234
|
-
*/
|
|
235
|
-
addRow(value: RowValues, style?: string): Row;
|
|
236
|
-
/**
|
|
237
|
-
* Add multiple rows by providing an array of arrays or key-value pairs
|
|
238
|
-
*/
|
|
239
|
-
addRows(value: RowValues[], style?: string): Row[];
|
|
240
|
-
/**
|
|
241
|
-
* Insert a Row by key-value, at the position (shifting down all rows from position),
|
|
242
|
-
* using the column keys, or add a row by contiguous Array (assign to columns A, B & C)
|
|
243
|
-
*/
|
|
244
|
-
insertRow(pos: number, value: RowValues, style?: string): Row;
|
|
245
|
-
/**
|
|
246
|
-
* Insert multiple rows at position (shifting down all rows from position)
|
|
247
|
-
* by providing an array of arrays or key-value pairs
|
|
248
|
-
*/
|
|
249
|
-
insertRows(pos: number, values: RowValues[], style?: string): Row[] | undefined;
|
|
223
|
+
getRow(r: number): any;
|
|
224
|
+
getRows(start: number, length: number): any[] | undefined;
|
|
225
|
+
addRow(value: any, style?: string): any;
|
|
226
|
+
addRows(value: any[], style?: string): any[];
|
|
227
|
+
insertRow(pos: number, value: any, style?: string): any;
|
|
228
|
+
insertRows(pos: number, values: any[], style?: string): Row[] | undefined;
|
|
250
229
|
_setStyleOption(pos: number, style?: string): void;
|
|
251
230
|
_copyStyle(src: number, dest: number, styleEmpty?: boolean): void;
|
|
252
231
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export { Image } from "./doc/image.js";
|
|
|
13
13
|
export * from "./doc/anchor.js";
|
|
14
14
|
export { Table } from "./doc/table.js";
|
|
15
15
|
export { DataValidations } from "./doc/data-validations.js";
|
|
16
|
+
export type { WorkbookReaderOptions, ParseEvent, SharedStringEvent, WorksheetReadyEvent, HyperlinksEvent } from "./stream/xlsx/workbook-reader.js";
|
|
17
|
+
export type { WorksheetReaderOptions, WorksheetEvent, RowEvent, HyperlinkEvent, WorksheetHyperlink } from "./stream/xlsx/worksheet-reader.js";
|
|
18
|
+
export type { WorkbookWriterOptions, ZipOptions, ZlibOptions } from "./stream/xlsx/workbook-writer.js";
|
|
16
19
|
export type { PivotTable, PivotTableModel, PivotTableSource, CacheField, DataField, PivotTableSubtotal, ParsedCacheDefinition, ParsedCacheRecords } from "./doc/pivot-table.js";
|
|
17
20
|
export * from "./doc/enums.js";
|
|
18
21
|
export * from "./types.js";
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import type { WorkbookReader, InternalWorksheetOptions } from "./workbook-reader.js";
|
|
3
|
+
export interface HyperlinkReaderOptions {
|
|
4
|
+
workbook: WorkbookReader;
|
|
4
5
|
id: number;
|
|
5
|
-
iterator:
|
|
6
|
-
options:
|
|
6
|
+
iterator: AsyncIterable<unknown>;
|
|
7
|
+
options: InternalWorksheetOptions;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/** Hyperlink relationship parsed from worksheet rels */
|
|
10
|
+
export interface Hyperlink {
|
|
9
11
|
type: number;
|
|
10
12
|
rId: string;
|
|
11
13
|
target: string;
|
|
12
14
|
targetMode: string;
|
|
13
15
|
}
|
|
14
16
|
declare class HyperlinkReader extends EventEmitter {
|
|
15
|
-
workbook:
|
|
17
|
+
workbook: WorkbookReader;
|
|
16
18
|
id: number;
|
|
17
|
-
iterator:
|
|
18
|
-
options:
|
|
19
|
-
hyperlinks?:
|
|
20
|
-
[key: string]: Hyperlink;
|
|
21
|
-
};
|
|
19
|
+
iterator: AsyncIterable<unknown>;
|
|
20
|
+
options: InternalWorksheetOptions;
|
|
21
|
+
hyperlinks?: Record<string, Hyperlink>;
|
|
22
22
|
constructor({ workbook, id, iterator, options }: HyperlinkReaderOptions);
|
|
23
23
|
get count(): number;
|
|
24
24
|
each(fn: (hyperlink: Hyperlink, rId: string) => void): void;
|
|
@@ -1,44 +1,133 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { Readable } from "stream";
|
|
3
|
+
import { StylesXform } from "../../xlsx/xform/style/styles-xform.js";
|
|
4
|
+
import { WorksheetReader } from "./worksheet-reader.js";
|
|
5
|
+
import { HyperlinkReader } from "./hyperlink-reader.js";
|
|
6
|
+
import type { WorksheetState, Font, WorkbookProperties } from "../../types.js";
|
|
7
|
+
/** Internal options type that includes undocumented 'prep' value */
|
|
8
|
+
export interface InternalWorksheetOptions {
|
|
9
|
+
worksheets?: "emit" | "ignore" | "prep";
|
|
10
|
+
sharedStrings?: "cache" | "emit" | "ignore";
|
|
11
|
+
hyperlinks?: "cache" | "emit" | "ignore";
|
|
12
|
+
styles?: "cache" | "ignore";
|
|
13
|
+
entries?: "emit" | "ignore";
|
|
8
14
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
sharedStrings?: any[];
|
|
15
|
-
workbookRels?: any[];
|
|
16
|
-
properties?: any;
|
|
17
|
-
model?: any;
|
|
18
|
-
constructor(input: any, options?: WorkbookReaderOptions);
|
|
19
|
-
_getStream(input: any): any;
|
|
20
|
-
read(input?: any, options?: WorkbookReaderOptions): Promise<void>;
|
|
21
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
|
22
|
-
parse(input?: any, options?: WorkbookReaderOptions): AsyncIterableIterator<{
|
|
23
|
-
eventType: string;
|
|
24
|
-
value: any;
|
|
15
|
+
/** Rich text item from shared strings */
|
|
16
|
+
export interface SharedStringRichText {
|
|
17
|
+
richText: Array<{
|
|
18
|
+
font: Partial<Font> | null;
|
|
19
|
+
text: string | null;
|
|
25
20
|
}>;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
}
|
|
22
|
+
/** Shared string value - either plain text or rich text */
|
|
23
|
+
export type SharedStringValue = string | SharedStringRichText;
|
|
24
|
+
/** Relationship entry from workbook.xml.rels */
|
|
25
|
+
export interface WorkbookRelationship {
|
|
26
|
+
Id: string;
|
|
27
|
+
Target: string;
|
|
28
|
+
Type?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Sheet metadata from workbook.xml */
|
|
31
|
+
export interface SheetMetadata {
|
|
32
|
+
id: number;
|
|
33
|
+
name: string;
|
|
34
|
+
state?: WorksheetState;
|
|
35
|
+
rId: string;
|
|
36
|
+
}
|
|
37
|
+
/** Workbook model parsed from workbook.xml */
|
|
38
|
+
export interface WorkbookModel {
|
|
39
|
+
sheets?: SheetMetadata[];
|
|
40
|
+
properties?: Partial<WorkbookProperties>;
|
|
41
|
+
views?: unknown[];
|
|
42
|
+
definedNames?: unknown[];
|
|
43
|
+
}
|
|
44
|
+
/** Properties parsed from workbook.xml (workbookPr element) */
|
|
45
|
+
export interface WorkbookPropertiesXform {
|
|
46
|
+
model?: Partial<WorkbookProperties>;
|
|
47
|
+
}
|
|
48
|
+
/** Entry event payload */
|
|
49
|
+
interface EntryPayload {
|
|
50
|
+
type: "shared-strings" | "styles" | "workbook" | "worksheet" | "hyperlinks";
|
|
51
|
+
id?: string;
|
|
52
|
+
}
|
|
53
|
+
/** Parse event types */
|
|
54
|
+
export type ParseEventType = "shared-strings" | "worksheet" | "hyperlinks";
|
|
55
|
+
export interface SharedStringEvent {
|
|
56
|
+
eventType: "shared-strings";
|
|
57
|
+
value: {
|
|
30
58
|
index: number;
|
|
31
|
-
text:
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
59
|
+
text: SharedStringValue;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface WorksheetReadyEvent {
|
|
63
|
+
eventType: "worksheet";
|
|
64
|
+
value: WorksheetReader;
|
|
65
|
+
}
|
|
66
|
+
export interface HyperlinksEvent {
|
|
67
|
+
eventType: "hyperlinks";
|
|
68
|
+
value: HyperlinkReader;
|
|
69
|
+
}
|
|
70
|
+
export type ParseEvent = SharedStringEvent | WorksheetReadyEvent | HyperlinksEvent;
|
|
71
|
+
/**
|
|
72
|
+
* Options for WorkbookReader
|
|
73
|
+
*/
|
|
74
|
+
export interface WorkbookReaderOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Specifies whether to emit worksheets ('emit') or not ('ignore').
|
|
77
|
+
* @default 'emit'
|
|
78
|
+
*/
|
|
79
|
+
worksheets?: "emit" | "ignore";
|
|
80
|
+
/**
|
|
81
|
+
* Specifies whether to cache shared strings ('cache'), emit them ('emit'), or ignore them ('ignore').
|
|
82
|
+
* @default 'cache'
|
|
83
|
+
*/
|
|
84
|
+
sharedStrings?: "cache" | "emit" | "ignore";
|
|
85
|
+
/**
|
|
86
|
+
* Specifies whether to cache hyperlinks ('cache'), emit them ('emit'), or ignore them ('ignore').
|
|
87
|
+
* @default 'ignore'
|
|
88
|
+
*/
|
|
89
|
+
hyperlinks?: "cache" | "emit" | "ignore";
|
|
90
|
+
/**
|
|
91
|
+
* Specifies whether to cache styles ('cache') or ignore them ('ignore').
|
|
92
|
+
* @default 'ignore'
|
|
93
|
+
*/
|
|
94
|
+
styles?: "cache" | "ignore";
|
|
95
|
+
/**
|
|
96
|
+
* Specifies whether to emit entries ('emit') or not ('ignore').
|
|
97
|
+
* @default 'ignore'
|
|
98
|
+
*/
|
|
99
|
+
entries?: "emit" | "ignore";
|
|
100
|
+
}
|
|
101
|
+
declare class WorkbookReader extends EventEmitter {
|
|
102
|
+
input: string | Readable;
|
|
103
|
+
options: {
|
|
104
|
+
worksheets: "emit" | "ignore";
|
|
105
|
+
sharedStrings: "cache" | "emit" | "ignore";
|
|
106
|
+
hyperlinks: "cache" | "emit" | "ignore";
|
|
107
|
+
styles: "cache" | "ignore";
|
|
108
|
+
entries: "emit" | "ignore";
|
|
109
|
+
};
|
|
110
|
+
styles: StylesXform;
|
|
111
|
+
stream?: Readable;
|
|
112
|
+
sharedStrings?: SharedStringValue[];
|
|
113
|
+
workbookRels?: WorkbookRelationship[];
|
|
114
|
+
properties?: WorkbookPropertiesXform;
|
|
115
|
+
model?: WorkbookModel;
|
|
116
|
+
constructor(input: string | Readable, options?: WorkbookReaderOptions);
|
|
117
|
+
_getStream(input: string | Readable): Readable;
|
|
118
|
+
read(input?: string | Readable, options?: WorkbookReaderOptions): Promise<void>;
|
|
119
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<WorksheetReader>;
|
|
120
|
+
parse(input?: string | Readable, options?: WorkbookReaderOptions): AsyncIterableIterator<ParseEvent>;
|
|
121
|
+
_emitEntry(payload: EntryPayload): void;
|
|
122
|
+
_parseRels(entry: NodeJS.ReadableStream): Promise<void>;
|
|
123
|
+
_parseWorkbook(entry: NodeJS.ReadableStream): Promise<void>;
|
|
124
|
+
_parseSharedStrings(entry: NodeJS.ReadableStream): AsyncIterableIterator<{
|
|
125
|
+
index: number;
|
|
126
|
+
text: SharedStringValue;
|
|
41
127
|
}>;
|
|
128
|
+
_parseStyles(entry: NodeJS.ReadableStream): Promise<void>;
|
|
129
|
+
_parseWorksheet(iterator: AsyncIterable<unknown>, sheetNo: string): IterableIterator<WorksheetReadyEvent>;
|
|
130
|
+
_parseHyperlinks(iterator: AsyncIterable<unknown>, sheetNo: string): IterableIterator<HyperlinksEvent>;
|
|
42
131
|
}
|
|
43
132
|
declare const WorkbookReaderOptions: {
|
|
44
133
|
readonly worksheets: readonly ["emit", "ignore"];
|
|
@@ -1,51 +1,134 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { Zip } from "fflate";
|
|
3
|
+
import { StreamBuf } from "../../utils/stream-buf.js";
|
|
4
|
+
import { StylesXform } from "../../xlsx/xform/style/styles-xform.js";
|
|
5
|
+
import { SharedStrings } from "../../utils/shared-strings.js";
|
|
6
|
+
import { DefinedNames } from "../../doc/defined-names.js";
|
|
7
|
+
import { WorksheetWriter } from "./worksheet-writer.js";
|
|
1
8
|
import type Stream from "stream";
|
|
2
|
-
|
|
9
|
+
import type { Image, WorkbookView, AddWorksheetOptions } from "../../types.js";
|
|
10
|
+
/** Internal medium type for storing images in workbook */
|
|
11
|
+
interface Medium extends Image {
|
|
12
|
+
type: "image";
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
/** Internal comment reference type for tracking comment files */
|
|
16
|
+
interface CommentRef {
|
|
17
|
+
commentName: string;
|
|
18
|
+
vmlDrawing: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ZlibOptions {
|
|
21
|
+
/** @default constants.Z_NO_FLUSH */
|
|
22
|
+
flush?: number;
|
|
23
|
+
/** @default constants.Z_FINISH */
|
|
24
|
+
finishFlush?: number;
|
|
25
|
+
/** @default 16*1024 */
|
|
26
|
+
chunkSize?: number;
|
|
27
|
+
windowBits?: number;
|
|
28
|
+
/** compression level (0-9) */
|
|
29
|
+
level?: number;
|
|
30
|
+
memLevel?: number;
|
|
31
|
+
strategy?: number;
|
|
32
|
+
dictionary?: Buffer | NodeJS.TypedArray | DataView | ArrayBuffer;
|
|
33
|
+
}
|
|
34
|
+
export interface ZipOptions {
|
|
35
|
+
comment?: string;
|
|
36
|
+
forceLocalTime?: boolean;
|
|
37
|
+
forceZip64?: boolean;
|
|
38
|
+
store?: boolean;
|
|
39
|
+
zlib?: Partial<ZlibOptions>;
|
|
40
|
+
/** Alternative way to set compression level */
|
|
41
|
+
compressionOptions?: {
|
|
42
|
+
level?: number;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export interface WorkbookWriterOptions {
|
|
46
|
+
/** The date the workbook was created */
|
|
3
47
|
created?: Date;
|
|
48
|
+
/** The date the workbook was last modified */
|
|
4
49
|
modified?: Date;
|
|
50
|
+
/** The author of the workbook */
|
|
5
51
|
creator?: string;
|
|
52
|
+
/** Who last modified the workbook */
|
|
6
53
|
lastModifiedBy?: string;
|
|
54
|
+
/** The date the workbook was last printed */
|
|
7
55
|
lastPrinted?: Date;
|
|
56
|
+
/** Specifies whether to use shared strings in the workbook. Default is false */
|
|
8
57
|
useSharedStrings?: boolean;
|
|
58
|
+
/** Specifies whether to add style information to the workbook. Default is false */
|
|
9
59
|
useStyles?: boolean;
|
|
10
|
-
|
|
60
|
+
/** Zip compression options */
|
|
61
|
+
zip?: Partial<ZipOptions>;
|
|
62
|
+
/** Specifies a writable stream to write the XLSX workbook to */
|
|
11
63
|
stream?: Stream;
|
|
64
|
+
/** If stream not specified, this field specifies the path to a file to write the XLSX workbook to */
|
|
12
65
|
filename?: string;
|
|
13
66
|
}
|
|
14
67
|
declare class WorkbookWriter {
|
|
68
|
+
/** The date the workbook was created */
|
|
15
69
|
created: Date;
|
|
70
|
+
/** The date the workbook was last modified */
|
|
16
71
|
modified: Date;
|
|
72
|
+
/** The author of the workbook */
|
|
17
73
|
creator: string;
|
|
74
|
+
/** Who last modified the workbook */
|
|
18
75
|
lastModifiedBy: string;
|
|
76
|
+
/** The date the workbook was last printed */
|
|
19
77
|
lastPrinted?: Date;
|
|
78
|
+
/** Whether to use shared strings */
|
|
20
79
|
useSharedStrings: boolean;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
80
|
+
/** Shared strings collection - internal use */
|
|
81
|
+
sharedStrings: SharedStrings;
|
|
82
|
+
/** Style manager - internal use */
|
|
83
|
+
styles: StylesXform;
|
|
84
|
+
/** Defined names - internal use */
|
|
85
|
+
_definedNames: DefinedNames;
|
|
86
|
+
/** Worksheets collection */
|
|
87
|
+
_worksheets: WorksheetWriter[];
|
|
88
|
+
/** Workbook views controls how many separate windows Excel will open */
|
|
89
|
+
views: WorkbookView[];
|
|
90
|
+
/** Zip options - internal use */
|
|
91
|
+
zipOptions?: Partial<ZipOptions>;
|
|
92
|
+
/** Compression level (0-9) */
|
|
27
93
|
compressionLevel: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
94
|
+
/** Media collection (images) - internal use */
|
|
95
|
+
media: Medium[];
|
|
96
|
+
/** Comment references - internal use */
|
|
97
|
+
commentRefs: CommentRef[];
|
|
98
|
+
/** Zip instance - internal use */
|
|
99
|
+
zip: Zip;
|
|
100
|
+
/** Output stream - internal use */
|
|
101
|
+
stream: Stream | fs.WriteStream | InstanceType<typeof StreamBuf>;
|
|
102
|
+
/** Internal promise for async operations */
|
|
103
|
+
promise: Promise<void[]>;
|
|
33
104
|
constructor(options?: WorkbookWriterOptions);
|
|
34
|
-
get definedNames():
|
|
35
|
-
_openStream(path: string):
|
|
36
|
-
_addFile(data: string |
|
|
105
|
+
get definedNames(): DefinedNames;
|
|
106
|
+
_openStream(path: string): InstanceType<typeof StreamBuf>;
|
|
107
|
+
_addFile(data: string | Uint8Array, name: string, base64?: boolean): void;
|
|
37
108
|
_commitWorksheets(): Promise<void>;
|
|
38
|
-
commit(): Promise<
|
|
109
|
+
commit(): Promise<void>;
|
|
39
110
|
get nextId(): number;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Add Image to Workbook and return the id
|
|
113
|
+
*/
|
|
114
|
+
addImage(image: Image): number;
|
|
115
|
+
/**
|
|
116
|
+
* Get image by id
|
|
117
|
+
*/
|
|
118
|
+
getImage(id: number): Image | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* Add a new worksheet and return a reference to it
|
|
121
|
+
*/
|
|
122
|
+
addWorksheet(name?: string, options?: Partial<AddWorksheetOptions>): WorksheetWriter;
|
|
123
|
+
/**
|
|
124
|
+
* Fetch sheet by name or id
|
|
125
|
+
*/
|
|
126
|
+
getWorksheet(id?: string | number): WorksheetWriter | undefined;
|
|
44
127
|
addStyles(): Promise<void>;
|
|
45
128
|
addThemes(): Promise<void>;
|
|
46
129
|
addOfficeRels(): Promise<void>;
|
|
47
130
|
addContentTypes(): Promise<void>;
|
|
48
|
-
addMedia(): Promise<
|
|
131
|
+
addMedia(): Promise<void[]>;
|
|
49
132
|
addApp(): Promise<void>;
|
|
50
133
|
addCore(): Promise<void>;
|
|
51
134
|
addSharedStrings(): Promise<void>;
|
|
@@ -1,37 +1,55 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { Dimensions } from "../../doc/range.js";
|
|
3
|
+
import { Row } from "../../doc/row.js";
|
|
4
|
+
import { Column } from "../../doc/column.js";
|
|
5
|
+
import type { WorkbookReader, InternalWorksheetOptions } from "./workbook-reader.js";
|
|
6
|
+
import type { WorksheetState } from "../../types.js";
|
|
7
|
+
/** Hyperlink reference from worksheet XML */
|
|
8
|
+
export interface WorksheetHyperlink {
|
|
9
|
+
ref: string;
|
|
10
|
+
rId: string;
|
|
11
|
+
}
|
|
12
|
+
/** Events emitted during worksheet parsing */
|
|
13
|
+
export type WorksheetEventType = "row" | "hyperlink";
|
|
14
|
+
/** Row event emitted during parsing */
|
|
15
|
+
export interface RowEvent {
|
|
16
|
+
eventType: "row";
|
|
17
|
+
value: Row;
|
|
18
|
+
}
|
|
19
|
+
/** Hyperlink event emitted during parsing */
|
|
20
|
+
export interface HyperlinkEvent {
|
|
21
|
+
eventType: "hyperlink";
|
|
22
|
+
value: WorksheetHyperlink;
|
|
23
|
+
}
|
|
24
|
+
export type WorksheetEvent = RowEvent | HyperlinkEvent;
|
|
25
|
+
export interface WorksheetReaderOptions {
|
|
26
|
+
workbook: WorkbookReader;
|
|
4
27
|
id: number;
|
|
5
|
-
iterator:
|
|
6
|
-
options?:
|
|
28
|
+
iterator: AsyncIterable<unknown>;
|
|
29
|
+
options?: InternalWorksheetOptions;
|
|
7
30
|
}
|
|
8
31
|
declare class WorksheetReader extends EventEmitter {
|
|
9
|
-
workbook:
|
|
32
|
+
workbook: WorkbookReader;
|
|
10
33
|
id: number | string;
|
|
11
|
-
iterator:
|
|
12
|
-
options:
|
|
34
|
+
iterator: AsyncIterable<unknown>;
|
|
35
|
+
options: InternalWorksheetOptions;
|
|
13
36
|
name: string;
|
|
14
|
-
state?:
|
|
37
|
+
state?: WorksheetState;
|
|
15
38
|
private _columns;
|
|
16
39
|
private _keys;
|
|
17
40
|
private _dimensions;
|
|
18
|
-
hyperlinks?:
|
|
19
|
-
[key: string]: any;
|
|
20
|
-
};
|
|
41
|
+
hyperlinks?: Record<string, WorksheetHyperlink>;
|
|
21
42
|
constructor({ workbook, id, iterator, options }: WorksheetReaderOptions);
|
|
22
43
|
destroy(): void;
|
|
23
|
-
get dimensions():
|
|
24
|
-
get columns():
|
|
25
|
-
getColumn(c: string | number):
|
|
26
|
-
getColumnKey(key: string):
|
|
27
|
-
setColumnKey(key: string, value:
|
|
44
|
+
get dimensions(): Dimensions;
|
|
45
|
+
get columns(): Column[] | null;
|
|
46
|
+
getColumn(c: string | number): Column;
|
|
47
|
+
getColumnKey(key: string): Column | undefined;
|
|
48
|
+
setColumnKey(key: string, value: Column): void;
|
|
28
49
|
deleteColumnKey(key: string): void;
|
|
29
|
-
eachColumnKey(f: (column:
|
|
50
|
+
eachColumnKey(f: (column: Column, key: string) => void): void;
|
|
30
51
|
read(): Promise<void>;
|
|
31
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<
|
|
32
|
-
parse(): AsyncIterableIterator<
|
|
33
|
-
eventType: string;
|
|
34
|
-
value: any;
|
|
35
|
-
}>>;
|
|
52
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Row>;
|
|
53
|
+
parse(): AsyncIterableIterator<WorksheetEvent[]>;
|
|
36
54
|
}
|
|
37
55
|
export { WorksheetReader };
|