@vdhewei/xlsx-template-lib 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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/index.d.mts +470 -0
- package/dist/index.d.ts +470 -0
- package/dist/index.js +4017 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3941 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -0
- package/src/index.ts +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PeerPackerHe
|
|
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/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import * as etree from 'elementtree';
|
|
2
|
+
import { Element } from 'elementtree';
|
|
3
|
+
import JsZip from 'jszip';
|
|
4
|
+
import exceljs from 'exceljs';
|
|
5
|
+
export { default as exceljs } from 'exceljs';
|
|
6
|
+
|
|
7
|
+
interface Placeholder {
|
|
8
|
+
placeholder: string;
|
|
9
|
+
type: string;
|
|
10
|
+
name: string;
|
|
11
|
+
key?: string;
|
|
12
|
+
subType?: string;
|
|
13
|
+
full: boolean;
|
|
14
|
+
[customKey: string]: any;
|
|
15
|
+
}
|
|
16
|
+
interface Ref {
|
|
17
|
+
table?: string | null;
|
|
18
|
+
colAbsolute?: boolean;
|
|
19
|
+
col: string;
|
|
20
|
+
rowAbsolute?: boolean;
|
|
21
|
+
row: number;
|
|
22
|
+
}
|
|
23
|
+
interface Range {
|
|
24
|
+
start: string;
|
|
25
|
+
end: string;
|
|
26
|
+
}
|
|
27
|
+
interface SheetInfo {
|
|
28
|
+
id: number;
|
|
29
|
+
name: string;
|
|
30
|
+
filename: string;
|
|
31
|
+
root?: etree.Element;
|
|
32
|
+
}
|
|
33
|
+
interface SheetInfoMust {
|
|
34
|
+
id: number;
|
|
35
|
+
name: string;
|
|
36
|
+
filename: string;
|
|
37
|
+
root: etree.Element;
|
|
38
|
+
}
|
|
39
|
+
interface DrawingInfo {
|
|
40
|
+
filename: string;
|
|
41
|
+
root: any;
|
|
42
|
+
relFilename?: string;
|
|
43
|
+
relRoot?: any;
|
|
44
|
+
}
|
|
45
|
+
interface TableInfo {
|
|
46
|
+
filename: string;
|
|
47
|
+
root: any;
|
|
48
|
+
}
|
|
49
|
+
interface RelsInfo {
|
|
50
|
+
filename: string;
|
|
51
|
+
root: any;
|
|
52
|
+
}
|
|
53
|
+
interface WorkbookOptions {
|
|
54
|
+
moveImages?: boolean;
|
|
55
|
+
substituteAllTableRow?: boolean;
|
|
56
|
+
moveSameLineImages?: boolean;
|
|
57
|
+
imageRatio?: number;
|
|
58
|
+
pushDownPageBreakOnTableSubstitution?: boolean;
|
|
59
|
+
imageRootPath?: string | null;
|
|
60
|
+
handleImageError?: ((imageObj: any, error: Error) => void) | null;
|
|
61
|
+
}
|
|
62
|
+
type OutputByType = {
|
|
63
|
+
readonly base64: string;
|
|
64
|
+
readonly string: string;
|
|
65
|
+
readonly text: string;
|
|
66
|
+
readonly binarystring: string;
|
|
67
|
+
readonly array: readonly number[];
|
|
68
|
+
readonly uint8array: Uint8Array;
|
|
69
|
+
readonly arraybuffer: ArrayBuffer;
|
|
70
|
+
readonly blob: Blob;
|
|
71
|
+
readonly nodebuffer: Buffer;
|
|
72
|
+
};
|
|
73
|
+
type CustomReplacer = (cell: any, stringValue: string, placeholder: Placeholder, substitution: any) => string | undefined | null;
|
|
74
|
+
type CustomPlaceholderExtractor = (inputString: string, options: ExtensionOptions) => Placeholder[];
|
|
75
|
+
declare enum BufferType {
|
|
76
|
+
Base64 = "base64",
|
|
77
|
+
String = "string",
|
|
78
|
+
Text = "text",
|
|
79
|
+
Blob = "blob",
|
|
80
|
+
Array = "array",
|
|
81
|
+
NodeBuffer = "nodebuffer",
|
|
82
|
+
Uint8array = "uint8array",
|
|
83
|
+
Arraybuffer = "arraybuffer",
|
|
84
|
+
BinaryString = "binarystring"
|
|
85
|
+
}
|
|
86
|
+
type BeforeReplaceHook = (stringValue: string, substitutions: Record<string, any>) => string | undefined | null;
|
|
87
|
+
type AfterReplaceHook = (resultString: string, stringValue: string, substitutions: Record<string, any>) => string;
|
|
88
|
+
type CustomFormatter = (value: any, placeholder: Placeholder, key?: string) => string | undefined | null;
|
|
89
|
+
type QueryFunction = (obj: Object | Record<string, any>, p: Placeholder) => any | undefined;
|
|
90
|
+
interface ExtensionOptions {
|
|
91
|
+
customReplacer?: CustomReplacer;
|
|
92
|
+
customPlaceholderExtractor?: CustomPlaceholderExtractor;
|
|
93
|
+
replacers?: CustomReplacer[];
|
|
94
|
+
beforeReplace?: BeforeReplaceHook;
|
|
95
|
+
afterReplace?: AfterReplaceHook;
|
|
96
|
+
formatters?: CustomFormatter[];
|
|
97
|
+
customPlaceholderRegex?: RegExp;
|
|
98
|
+
enableDefaultParsing?: boolean;
|
|
99
|
+
customQueryFunction?: QueryFunction;
|
|
100
|
+
}
|
|
101
|
+
type FullOptions = WorkbookOptions & ExtensionOptions;
|
|
102
|
+
type PathImpl<T, Key extends string> = T extends object ? Key extends `${infer K}.${infer Rest}` ? K extends keyof T ? PathImpl<T[K], Rest> : never : Key extends keyof T ? T[Key] : never : any;
|
|
103
|
+
type PathType<T, Key extends string> = string extends Key ? any : PathImpl<T, Key>;
|
|
104
|
+
declare function valueDotGet<T extends Record<string, any> & object, P extends string>(obj: T, path: P, defaultValue?: PathType<T, P>): PathType<T, P>;
|
|
105
|
+
declare function defaultValueDotGet<T extends Record<string, any> & object>(obj: T, p: Placeholder): PathType<T, string>;
|
|
106
|
+
declare const defaultExtractPlaceholders: CustomPlaceholderExtractor;
|
|
107
|
+
declare const defaultFormatters: CustomFormatter[];
|
|
108
|
+
declare const isUrl: (str: string) => boolean;
|
|
109
|
+
declare const toArrayBuffer: (buffer: Buffer) => ArrayBuffer;
|
|
110
|
+
declare class Workbook {
|
|
111
|
+
option: FullOptions;
|
|
112
|
+
archive: JsZip;
|
|
113
|
+
sharedStrings: string[];
|
|
114
|
+
sharedStringsLookup: Record<string, number>;
|
|
115
|
+
sharedStringsPath: string;
|
|
116
|
+
sheets: SheetInfo[] | SheetInfoMust[];
|
|
117
|
+
sheet: SheetInfo | SheetInfoMust | null;
|
|
118
|
+
workbook: Element | null;
|
|
119
|
+
workbookPath: string | null;
|
|
120
|
+
contentTypes: any;
|
|
121
|
+
prefix: string | null;
|
|
122
|
+
workbookRels: Element | null;
|
|
123
|
+
calChainRel: any;
|
|
124
|
+
calcChainPath: string;
|
|
125
|
+
private richDataIsInit;
|
|
126
|
+
private _relsrichValueRel;
|
|
127
|
+
private rdrichvalue;
|
|
128
|
+
private rdrichvaluestructure;
|
|
129
|
+
private rdRichValueTypes;
|
|
130
|
+
private richValueRel;
|
|
131
|
+
private metadata;
|
|
132
|
+
constructor(option?: FullOptions);
|
|
133
|
+
static parse(data: Buffer | string, option?: FullOptions): Promise<Workbook>;
|
|
134
|
+
addReplacer(replacer: CustomReplacer): this;
|
|
135
|
+
addFormatter(formatter: CustomFormatter): this;
|
|
136
|
+
setBeforeReplaceHook(hook: BeforeReplaceHook): this;
|
|
137
|
+
setAfterReplaceHook(hook: AfterReplaceHook): this;
|
|
138
|
+
setPlaceholderExtractor(extractor: CustomPlaceholderExtractor): this;
|
|
139
|
+
setPlaceholderRegex(regex: RegExp, enableDefaultParsing?: boolean): this;
|
|
140
|
+
setQueryFunctionHandler(h: QueryFunction): this;
|
|
141
|
+
private executeReplacers;
|
|
142
|
+
private executeFormatters;
|
|
143
|
+
private executeBeforeReplaceHook;
|
|
144
|
+
private executeAfterReplaceHook;
|
|
145
|
+
deleteSheet(sheetName: string | number): Promise<this>;
|
|
146
|
+
copySheet(sheetName: string | number, copyName?: string, binary?: boolean): Promise<this>;
|
|
147
|
+
private _rebuild;
|
|
148
|
+
loadTemplate(data: Buffer | string): Promise<void>;
|
|
149
|
+
substituteAll(substitutions: Record<string, any>): Promise<void>;
|
|
150
|
+
substitute(sheetName: string | number, substitutions: Record<string, any>): Promise<void>;
|
|
151
|
+
generate<T extends JsZip.OutputType>(options?: JsZip.JSZipGeneratorOptions<T>): Promise<OutputByType[T]>;
|
|
152
|
+
valueGet(substitutions: object | Record<string, any>, p: Placeholder, full?: boolean): any;
|
|
153
|
+
private writeSharedStrings;
|
|
154
|
+
private addSharedString;
|
|
155
|
+
private stringIndex;
|
|
156
|
+
private replaceString;
|
|
157
|
+
private loadSheets;
|
|
158
|
+
loadSheet(sheet: string | number): Promise<SheetInfoMust>;
|
|
159
|
+
loadSheetRels(sheetFilename: string): Promise<RelsInfo>;
|
|
160
|
+
private initSheetRels;
|
|
161
|
+
private loadDrawing;
|
|
162
|
+
private addContentType;
|
|
163
|
+
private initDrawing;
|
|
164
|
+
private writeDrawing;
|
|
165
|
+
private moveAllImages;
|
|
166
|
+
private _moveTwoCellAnchor;
|
|
167
|
+
loadTables(sheet: Element, sheetFilename: string): Promise<TableInfo[]>;
|
|
168
|
+
private writeTables;
|
|
169
|
+
private substituteHyperlinks;
|
|
170
|
+
private substituteTableColumnHeaders;
|
|
171
|
+
extractPlaceholders(inputString: string): Placeholder[];
|
|
172
|
+
private splitRef;
|
|
173
|
+
private joinRef;
|
|
174
|
+
private nextCol;
|
|
175
|
+
private nextRow;
|
|
176
|
+
private charToNum;
|
|
177
|
+
private numToChar;
|
|
178
|
+
private generateUUID;
|
|
179
|
+
private isRange;
|
|
180
|
+
private isWithin;
|
|
181
|
+
stringify(value: any, placeholder?: Placeholder, key?: string): string;
|
|
182
|
+
private insertCellValue;
|
|
183
|
+
private substituteScalar;
|
|
184
|
+
private substituteArray;
|
|
185
|
+
private substituteTable;
|
|
186
|
+
private initRichData;
|
|
187
|
+
private writeRichDataAlreadyExist;
|
|
188
|
+
private writeRichData;
|
|
189
|
+
private substituteImageInCell;
|
|
190
|
+
private substituteImage;
|
|
191
|
+
private cloneElement;
|
|
192
|
+
private replaceChildren;
|
|
193
|
+
private getCurrentRow;
|
|
194
|
+
private getCurrentCell;
|
|
195
|
+
private updateRowSpan;
|
|
196
|
+
private splitRange;
|
|
197
|
+
private joinRange;
|
|
198
|
+
private pushRight;
|
|
199
|
+
private pushDown;
|
|
200
|
+
hideCols(sheetName: string | number, hideItemIndexes: number[]): Promise<this>;
|
|
201
|
+
private getWidthCell;
|
|
202
|
+
private getWidthMergeCell;
|
|
203
|
+
private getHeightCell;
|
|
204
|
+
private getHeightMergeCell;
|
|
205
|
+
private getNbRowOfMergeCell;
|
|
206
|
+
private pixelsToEMUs;
|
|
207
|
+
private columnWidthToEMUs;
|
|
208
|
+
private rowHeightToEMUs;
|
|
209
|
+
private findMaxFileId;
|
|
210
|
+
private cellInMergeCells;
|
|
211
|
+
private imageToBuffer;
|
|
212
|
+
private findMaxId;
|
|
213
|
+
}
|
|
214
|
+
declare const generateXlsxTemplate: <T extends JsZip.OutputType>(data: Buffer, values: Object, options?: JsZip.JSZipGeneratorOptions<T> & FullOptions) => Promise<OutputByType[T]>;
|
|
215
|
+
|
|
216
|
+
type CellPosition = {
|
|
217
|
+
Row: string;
|
|
218
|
+
Column: number;
|
|
219
|
+
Sheet?: string | number;
|
|
220
|
+
};
|
|
221
|
+
type CellPoint = {
|
|
222
|
+
Row: number;
|
|
223
|
+
Column: number;
|
|
224
|
+
};
|
|
225
|
+
interface PlaceholderCellValue {
|
|
226
|
+
toString(): string;
|
|
227
|
+
mergeCell(values: string[]): string;
|
|
228
|
+
}
|
|
229
|
+
type ScanTokenData = {
|
|
230
|
+
value: string;
|
|
231
|
+
token: string;
|
|
232
|
+
};
|
|
233
|
+
type MacroArgs = {
|
|
234
|
+
type: string;
|
|
235
|
+
columnParam: number;
|
|
236
|
+
rowParam: number[] | number;
|
|
237
|
+
formatter?: string;
|
|
238
|
+
};
|
|
239
|
+
type ExtractMacroArgs = {
|
|
240
|
+
argToken: string;
|
|
241
|
+
startToken: string;
|
|
242
|
+
endToken: string;
|
|
243
|
+
};
|
|
244
|
+
declare enum RuleToken {
|
|
245
|
+
AliasToken = "alias",
|
|
246
|
+
CellToken = "cell",
|
|
247
|
+
MergeCellToken = "mergeCell",
|
|
248
|
+
RowCellToken = "rowCell",
|
|
249
|
+
UseAliasToken = "@",
|
|
250
|
+
RangeToken = "-",
|
|
251
|
+
PosToken = ":",
|
|
252
|
+
FunctionPatternToken = "<?>",
|
|
253
|
+
AnyToken = "?",
|
|
254
|
+
VarPatternToken = "${?}",
|
|
255
|
+
UndefinedToken = "",
|
|
256
|
+
EqualToken = "=",
|
|
257
|
+
ArgPosToken = ",",
|
|
258
|
+
LparenToken = "(",
|
|
259
|
+
RparenToken = ")",
|
|
260
|
+
DotGetToken = ".",
|
|
261
|
+
CompileGenToken = "compile:GenCell",
|
|
262
|
+
CompileMacroToken = "compile:Macro"
|
|
263
|
+
}
|
|
264
|
+
type RuleValue = {
|
|
265
|
+
express: string;
|
|
266
|
+
tokens: RuleToken[];
|
|
267
|
+
cells?: CellPoint[];
|
|
268
|
+
key?: string;
|
|
269
|
+
ref?: string[];
|
|
270
|
+
func?: string;
|
|
271
|
+
compileExpress?: string[];
|
|
272
|
+
posExpr?: RuleValue;
|
|
273
|
+
funcExpr?: RuleValue;
|
|
274
|
+
value: string | number[] | number | CellPoint | RangeCell | any[];
|
|
275
|
+
[key: string]: any;
|
|
276
|
+
};
|
|
277
|
+
type RuleResult = {
|
|
278
|
+
rules: Map<RuleToken, RuleValue[]>;
|
|
279
|
+
};
|
|
280
|
+
type FilterMacroResult = {
|
|
281
|
+
tokens: RuleToken[];
|
|
282
|
+
express: string[];
|
|
283
|
+
};
|
|
284
|
+
type CompileChecker = (iv: RuleResult, ctx: RuleMapOptions) => Error[] | undefined;
|
|
285
|
+
interface RuleOptions {
|
|
286
|
+
startLine?: number;
|
|
287
|
+
endLine?: number;
|
|
288
|
+
endColumn?: number;
|
|
289
|
+
startColumn?: number;
|
|
290
|
+
ruleKeyMap?: Map<RuleToken, string>;
|
|
291
|
+
compileCheckers?: CompileChecker[];
|
|
292
|
+
compileSheets?: string[];
|
|
293
|
+
[key: string]: any;
|
|
294
|
+
setEndRow(end: number): RuleOptions;
|
|
295
|
+
parseToken(value: string): RuleToken;
|
|
296
|
+
setEndColumn(end: number): RuleOptions;
|
|
297
|
+
setStartRow(start: number): RuleOptions;
|
|
298
|
+
setStartColumn(start: number): RuleOptions;
|
|
299
|
+
getContextMap(): Map<RuleToken, RuleValue[]>;
|
|
300
|
+
addRuleMap(key: RuleToken, value: string): RuleOptions;
|
|
301
|
+
parseDefault(worksheet: exceljs.Worksheet): RuleOptions;
|
|
302
|
+
getCompileCheckHandlers(): CompileChecker[] | undefined;
|
|
303
|
+
}
|
|
304
|
+
interface RangeCell {
|
|
305
|
+
minRow: number;
|
|
306
|
+
maxRow: number;
|
|
307
|
+
stepRow: number;
|
|
308
|
+
minColumn: number;
|
|
309
|
+
maxColumn: number;
|
|
310
|
+
stepColumn: number;
|
|
311
|
+
getCells(): CellPoint[];
|
|
312
|
+
}
|
|
313
|
+
declare class RuleMapOptions implements RuleOptions {
|
|
314
|
+
startLine?: number;
|
|
315
|
+
endLine?: number;
|
|
316
|
+
endColumn?: number;
|
|
317
|
+
startColumn?: number;
|
|
318
|
+
ruleKeyMap?: Map<RuleToken, string>;
|
|
319
|
+
compileCheckers?: CompileChecker[];
|
|
320
|
+
compileSheets?: string[];
|
|
321
|
+
[key: string]: any;
|
|
322
|
+
constructor(m?: Map<RuleToken, string>);
|
|
323
|
+
static withAllSheets(w: exceljs.Workbook, excludes?: string[]): RuleOptions;
|
|
324
|
+
parseDefault(worksheet: exceljs.Worksheet): RuleOptions;
|
|
325
|
+
addRuleMap(key: RuleToken, value: string): RuleOptions;
|
|
326
|
+
setStartRow(start: number): RuleOptions;
|
|
327
|
+
setStartColumn(start: number): RuleOptions;
|
|
328
|
+
setEndRow(end: number): RuleOptions;
|
|
329
|
+
setEndColumn(end: number): RuleOptions;
|
|
330
|
+
parseToken(value: string): RuleToken;
|
|
331
|
+
getContextMap(): Map<RuleToken, RuleValue[]>;
|
|
332
|
+
getCompileCheckHandlers(): CompileChecker[] | undefined;
|
|
333
|
+
}
|
|
334
|
+
declare class CompileContext extends RuleMapOptions {
|
|
335
|
+
private aliasMap;
|
|
336
|
+
sheet?: exceljs.Worksheet;
|
|
337
|
+
constructor(m?: Map<RuleToken, string>);
|
|
338
|
+
static create(r: RuleMapOptions): CompileContext;
|
|
339
|
+
private init;
|
|
340
|
+
loadAlias(m: Map<RuleToken, RuleValue[]>): this;
|
|
341
|
+
setAlias(key: string, value: string): void;
|
|
342
|
+
getAlias(key: string): string | undefined;
|
|
343
|
+
hasAlias(key: string): boolean;
|
|
344
|
+
filterSheet(sheetName: string): boolean;
|
|
345
|
+
}
|
|
346
|
+
type TokenParserReply = {
|
|
347
|
+
ok: boolean;
|
|
348
|
+
values?: any;
|
|
349
|
+
expr?: RuleValue;
|
|
350
|
+
[key: string]: any;
|
|
351
|
+
};
|
|
352
|
+
type TokenParser = (ctx: Map<RuleToken, RuleValue[]>, t: RuleToken, value: string) => TokenParserReply;
|
|
353
|
+
type TokenParseResolver = {
|
|
354
|
+
exists: boolean;
|
|
355
|
+
handler?: TokenParser;
|
|
356
|
+
};
|
|
357
|
+
declare class DefaultPlaceholderCellValue implements PlaceholderCellValue {
|
|
358
|
+
private readonly placeholder;
|
|
359
|
+
private readonly mergeCellPlaceholder?;
|
|
360
|
+
constructor(p: string, merge?: string);
|
|
361
|
+
mergeCell(values: string[]): string;
|
|
362
|
+
toString(): string;
|
|
363
|
+
}
|
|
364
|
+
declare class TokenParserManger {
|
|
365
|
+
static aliasParse(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken, value: string): TokenParserReply;
|
|
366
|
+
static equalParse(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken, value: string): TokenParserReply;
|
|
367
|
+
static cellParse(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken, value: string): TokenParserReply;
|
|
368
|
+
static useAliasParse(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken, value: string): TokenParserReply;
|
|
369
|
+
static rangeParse(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken, value: string): TokenParserReply;
|
|
370
|
+
static posParse(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken, value: string): TokenParserReply;
|
|
371
|
+
static mergeCellParse(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken, value: string): TokenParserReply;
|
|
372
|
+
static rowCellParse(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken, value: string): TokenParserReply;
|
|
373
|
+
static functionPatternParse(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken, value: string): TokenParserReply;
|
|
374
|
+
static varPatternParse(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken, value: string): TokenParserReply;
|
|
375
|
+
static compileExprExtract(value: string): RuleToken[];
|
|
376
|
+
static getTokenByCtx(ctx: Map<RuleToken, RuleValue[]>, token: RuleToken): string;
|
|
377
|
+
static scanToken(value: string, startToken: string, endTokens: string[]): ScanTokenData[];
|
|
378
|
+
static split(argsStr: string, argsSplitToken: string, ignoreTokenRange: string[]): string[];
|
|
379
|
+
static filterMacro(values: string[]): FilterMacroResult | undefined;
|
|
380
|
+
static extractUseAliasTokens(ctx: Map<RuleToken, RuleValue[]>, args: string[]): RuleToken[];
|
|
381
|
+
static toList(ctx: Map<RuleToken, RuleValue[]>, endTokens: RuleToken[]): string[];
|
|
382
|
+
private static parseRangeValue;
|
|
383
|
+
private static parsePosNumber;
|
|
384
|
+
}
|
|
385
|
+
declare function columnLetterToNumber(letter: string): number;
|
|
386
|
+
declare function columnNumberToLetter(num: number): string;
|
|
387
|
+
type MacroUnitHelper = (v: string) => string;
|
|
388
|
+
declare const loadWorkbook: <T extends ArrayBuffer | Buffer | string>(data: T) => Promise<exceljs.Workbook>;
|
|
389
|
+
declare const scanCellSetPlaceholder: <T extends ArrayBuffer | Buffer | string>(excelBuffer: T, cell: CellPosition & {
|
|
390
|
+
Sheet: string | number;
|
|
391
|
+
}, placeholder: PlaceholderCellValue) => Promise<ArrayBuffer | undefined>;
|
|
392
|
+
declare const workSheetSetPlaceholder: (worksheet: exceljs.Worksheet, cell: CellPosition, placeholder: PlaceholderCellValue) => exceljs.Worksheet;
|
|
393
|
+
declare const isRuleToken: (t: RuleToken) => boolean;
|
|
394
|
+
declare const getTokenParser: (token: RuleToken) => TokenParseResolver;
|
|
395
|
+
declare const registerTokenParser: (token: RuleToken, h: TokenParser) => boolean;
|
|
396
|
+
declare const registerTokenParserMust: (token: RuleToken, h: TokenParser) => void;
|
|
397
|
+
declare const parseWorkSheetRules: (worksheet: exceljs.Worksheet, options?: RuleOptions) => RuleResult;
|
|
398
|
+
declare const hasGeneratorToken: (tokens: RuleToken[]) => boolean;
|
|
399
|
+
declare const compileWorkSheetPlaceholder: (ctx: CompileContext, sheet: exceljs.Worksheet, result: RuleResult) => Error[] | undefined;
|
|
400
|
+
type CompileResult = {
|
|
401
|
+
workbook: exceljs.Workbook;
|
|
402
|
+
configure?: RuleResult;
|
|
403
|
+
errs?: Error[];
|
|
404
|
+
};
|
|
405
|
+
declare const compileWorkSheet: <T extends ArrayBuffer | Buffer | string>(data: T, sheetName: string | number, options?: RuleOptions) => Promise<exceljs.Xlsx | Error[]>;
|
|
406
|
+
declare class ExprResolver {
|
|
407
|
+
static toBuffer: (w: exceljs.Workbook) => Promise<Buffer>;
|
|
408
|
+
static compile: <T extends ArrayBuffer | Buffer | string>(data: T, ruleSheetName: string | number, options?: RuleOptions) => Promise<CompileResult>;
|
|
409
|
+
static toRowCells: (cells: CellPoint[]) => CellPoint[][];
|
|
410
|
+
static fetchAlias: (m: Map<RuleToken, RuleValue[]> | RuleResult) => Map<string, string>;
|
|
411
|
+
static getExprEnd: (macroExpr: string, matchIndex: number, rparenToken: string) => number;
|
|
412
|
+
static compileCheck: (iv: RuleResult, ctx: RuleOptions) => Error[] | undefined;
|
|
413
|
+
static extractMacro: (expr: string, options: ExtractMacroArgs) => MacroArgs;
|
|
414
|
+
static compileRowCells: (ctx: CompileContext, expr: RuleValue, cellPoints: CellPoint[], rowIndex: number, errs: Error[]) => void;
|
|
415
|
+
static searchIndexOf: (str: string, substr: string[], position?: number) => number;
|
|
416
|
+
static resolveAliasExpr: (ctx: CompileContext, templateValue: string, index: number) => string;
|
|
417
|
+
static resolveValueExpr: (ctx: CompileContext, templateValue: string) => string | null;
|
|
418
|
+
static resolveFunctionExpr: (ctx: CompileContext, templateValue: string, expr: RuleValue) => string;
|
|
419
|
+
static removeUnExportSheets: (w: exceljs.Workbook, options: RuleOptions) => exceljs.Workbook;
|
|
420
|
+
static resolveCompileMacroGen: (ctx: CompileContext, expr: string, currentCellIndex: number) => string;
|
|
421
|
+
static resolveCompileMacroExpr: (ctx: CompileContext, macroExpr: string, macroTokens: RuleToken[], currentCellIndex: number, totalCells: number) => string;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
type Argument = {
|
|
425
|
+
root: string;
|
|
426
|
+
alias?: string;
|
|
427
|
+
groups?: string[];
|
|
428
|
+
suffix?: string;
|
|
429
|
+
default: number | string | any;
|
|
430
|
+
func: string;
|
|
431
|
+
p: Placeholder;
|
|
432
|
+
};
|
|
433
|
+
type CmdFunction = (obj: Object | Record<string, any>, argument: Argument) => any | undefined;
|
|
434
|
+
declare class ArgumentData {
|
|
435
|
+
root: string;
|
|
436
|
+
p: Placeholder;
|
|
437
|
+
default: number | string | any;
|
|
438
|
+
alias?: string;
|
|
439
|
+
suffix?: string;
|
|
440
|
+
groups?: string[];
|
|
441
|
+
tokenIterIndex: number;
|
|
442
|
+
private readonly func;
|
|
443
|
+
constructor(fn: string, p: Placeholder);
|
|
444
|
+
To(): Argument;
|
|
445
|
+
Add(startToken: string, value: string | undefined): void;
|
|
446
|
+
ParseAlias(alias: any | object | Record<string, string>): void;
|
|
447
|
+
}
|
|
448
|
+
declare class ArgumentValue {
|
|
449
|
+
private readonly value;
|
|
450
|
+
private readonly defaultValue;
|
|
451
|
+
constructor(value: any, defValue: any);
|
|
452
|
+
isUndefined(): boolean;
|
|
453
|
+
getDefault(): any;
|
|
454
|
+
getNumber(): number;
|
|
455
|
+
toString(): string;
|
|
456
|
+
}
|
|
457
|
+
declare const ArgumentValueLoader: (values: Object | Record<string, any>, args: Argument) => ArgumentValue[];
|
|
458
|
+
declare const resolveArgument: (p: Placeholder, data: object | Record<string, any>) => Argument;
|
|
459
|
+
declare const commandExtendQuery: QueryFunction;
|
|
460
|
+
declare const AddCommand: (key: string, h: CmdFunction) => boolean;
|
|
461
|
+
declare const AddCommandMust: (key: string, h: CmdFunction) => void;
|
|
462
|
+
declare const generateCommandsXlsxTemplate: <T extends JsZip.OutputType>(data: Buffer, values: Object, options?: JsZip.JSZipGeneratorOptions<T> & FullOptions) => Promise<OutputByType[T]>;
|
|
463
|
+
declare const getCommands: () => Map<string, CmdFunction>;
|
|
464
|
+
type AutoOptions = RuleOptions & {
|
|
465
|
+
sheetName?: string;
|
|
466
|
+
};
|
|
467
|
+
declare const compileRuleSheetName = "export_metadata.config";
|
|
468
|
+
declare const generateCommandsXlsxTemplateWithCompile: <T extends JsZip.OutputType>(data: Buffer, values: Object, compileOptions: AutoOptions, options?: JsZip.JSZipGeneratorOptions<T> & FullOptions) => Promise<OutputByType[T]>;
|
|
469
|
+
|
|
470
|
+
export { AddCommand, AddCommandMust, type AfterReplaceHook, type Argument, ArgumentData, ArgumentValue, ArgumentValueLoader, type AutoOptions, type BeforeReplaceHook, BufferType, type CellPosition, type CmdFunction, CompileContext, type CompileResult, type CustomFormatter, type CustomPlaceholderExtractor, type CustomReplacer, DefaultPlaceholderCellValue, type DrawingInfo, ExprResolver, type ExtensionOptions, type ExtractMacroArgs, type FilterMacroResult, type FullOptions, type MacroArgs, type MacroUnitHelper, type OutputByType, type Placeholder, type PlaceholderCellValue, type QueryFunction, type Range, type Ref, type RelsInfo, RuleMapOptions, type RuleOptions, type RuleResult, RuleToken, type SheetInfo, type TableInfo, TokenParserManger, Workbook, type WorkbookOptions, columnLetterToNumber, columnNumberToLetter, commandExtendQuery, compileRuleSheetName, compileWorkSheet, compileWorkSheetPlaceholder, defaultExtractPlaceholders, defaultFormatters, defaultValueDotGet, generateCommandsXlsxTemplate, generateCommandsXlsxTemplateWithCompile, generateXlsxTemplate, getCommands, getTokenParser, hasGeneratorToken, isRuleToken, isUrl, loadWorkbook, parseWorkSheetRules, registerTokenParser, registerTokenParserMust, resolveArgument, scanCellSetPlaceholder, toArrayBuffer, valueDotGet, workSheetSetPlaceholder };
|