@vdhewei/xlsx-template-lib 1.2.4 → 1.2.5
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/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +40 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2053,16 +2053,16 @@ var RuleMapOptions = class _RuleMapOptions {
|
|
|
2053
2053
|
}
|
|
2054
2054
|
parseDefault(worksheet) {
|
|
2055
2055
|
this.ruleKeyMap = mergeOption(this.ruleKeyMap, defaultRuleTokenMap);
|
|
2056
|
-
if (this.startLine === void 0) {
|
|
2056
|
+
if (this.startLine === void 0 || isNaN(this.startLine) || this.startLine < 0) {
|
|
2057
2057
|
this.startLine = 1;
|
|
2058
2058
|
}
|
|
2059
|
-
if (this.endLine === void 0) {
|
|
2059
|
+
if (this.endLine === void 0 || isNaN(this.endLine) || this.endLine < 0) {
|
|
2060
2060
|
this.endLine = worksheet.rowCount;
|
|
2061
2061
|
}
|
|
2062
|
-
if (this.startColumn === void 0) {
|
|
2062
|
+
if (this.startColumn === void 0 || isNaN(this.startColumn) || this.startColumn < 0) {
|
|
2063
2063
|
this.startColumn = 1;
|
|
2064
2064
|
}
|
|
2065
|
-
if (this.endColumn === void 0) {
|
|
2065
|
+
if (this.endColumn === void 0 || isNaN(this.endColumn) || this.endColumn < 0) {
|
|
2066
2066
|
this.endColumn = worksheet.columnCount;
|
|
2067
2067
|
}
|
|
2068
2068
|
return this;
|
|
@@ -3492,6 +3492,25 @@ var compileWorkSheetPlaceholder = function(ctx, sheet, result) {
|
|
|
3492
3492
|
}
|
|
3493
3493
|
return void 0;
|
|
3494
3494
|
};
|
|
3495
|
+
var loadCompileSheets = (workbook, ruleSheetName) => {
|
|
3496
|
+
let first;
|
|
3497
|
+
let sheets = [];
|
|
3498
|
+
for (const [_, w] of workbook.worksheets.entries()) {
|
|
3499
|
+
if (w.name === ruleSheetName) {
|
|
3500
|
+
continue;
|
|
3501
|
+
}
|
|
3502
|
+
if (first === "") {
|
|
3503
|
+
first = w.name;
|
|
3504
|
+
}
|
|
3505
|
+
if (!w.name.endsWith(".json") && !w.name.endsWith(".config")) {
|
|
3506
|
+
sheets.push(w.name);
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
if (sheets.length <= 0 && first !== "") {
|
|
3510
|
+
sheets.push(first);
|
|
3511
|
+
}
|
|
3512
|
+
return sheets;
|
|
3513
|
+
};
|
|
3495
3514
|
var compile = async function(data, ruleSheetName, options) {
|
|
3496
3515
|
const workbook = await loadWorkbook(data);
|
|
3497
3516
|
const sheet = workbook.getWorksheet(ruleSheetName);
|
|
@@ -3510,6 +3529,10 @@ var compile = async function(data, ruleSheetName, options) {
|
|
|
3510
3529
|
const excludes = [ruleSheetName];
|
|
3511
3530
|
options = RuleMapOptions.withAllSheets(workbook, excludes);
|
|
3512
3531
|
}
|
|
3532
|
+
options = options.parseDefault(sheet);
|
|
3533
|
+
if (options.compileSheets === void 0 || options.compileSheets.length === 0) {
|
|
3534
|
+
options.compileSheets = loadCompileSheets(workbook, ruleSheetName);
|
|
3535
|
+
}
|
|
3513
3536
|
const result = parseWorkSheetRules(sheet, options);
|
|
3514
3537
|
const errs = compileCheck(result, options);
|
|
3515
3538
|
if (errs !== void 0) {
|
|
@@ -3572,6 +3595,9 @@ var fetchAlias = (m) => {
|
|
|
3572
3595
|
};
|
|
3573
3596
|
var removeUnExportSheets = (w, options) => {
|
|
3574
3597
|
const removes = [];
|
|
3598
|
+
if (typeof options.skipRemoveUnExportSheet === "boolean" && options.skipRemoveUnExportSheet === true) {
|
|
3599
|
+
return w;
|
|
3600
|
+
}
|
|
3575
3601
|
if (options.compileSheets === void 0 || options.compileSheets.length <= 0) {
|
|
3576
3602
|
for (const [i, v] of w.worksheets.entries()) {
|
|
3577
3603
|
const sheetName = v.name;
|
|
@@ -3614,6 +3640,7 @@ ExprResolver.resolveCompileMacroGen = resolveCompileMacroGen;
|
|
|
3614
3640
|
ExprResolver.resolveCompileMacroExpr = resolveCompileMacroExpr;
|
|
3615
3641
|
|
|
3616
3642
|
// src/extends.ts
|
|
3643
|
+
import fs2 from "fs/promises";
|
|
3617
3644
|
function hasToString(obj) {
|
|
3618
3645
|
return obj != null && typeof obj.toString === "function";
|
|
3619
3646
|
}
|
|
@@ -3883,6 +3910,12 @@ var autoRegisterAlias = function(values, configure) {
|
|
|
3883
3910
|
values[aliasKey] = alias;
|
|
3884
3911
|
return values;
|
|
3885
3912
|
};
|
|
3913
|
+
var saveCompile = async (compileOptions, wb) => {
|
|
3914
|
+
if (typeof compileOptions.save === "boolean" && compileOptions.save === true && typeof compileOptions.saveFile === "string" && compileOptions.saveFile !== "") {
|
|
3915
|
+
const path2 = compileOptions.saveFile;
|
|
3916
|
+
await fs2.writeFile(`${path2}compile_${(/* @__PURE__ */ new Date()).valueOf()}.xlsx`, wb);
|
|
3917
|
+
}
|
|
3918
|
+
};
|
|
3886
3919
|
var generateCommandsXlsxTemplateWithCompile = async function(data, values, compileOptions, options) {
|
|
3887
3920
|
if (compileOptions.sheetName === void 0 || compileOptions.sheetName === "") {
|
|
3888
3921
|
compileOptions.sheetName = compileRuleSheetName;
|
|
@@ -3894,6 +3927,7 @@ var generateCommandsXlsxTemplateWithCompile = async function(data, values, compi
|
|
|
3894
3927
|
values = autoRegisterAlias(values, result.configure);
|
|
3895
3928
|
result.workbook = ExprResolver.removeUnExportSheets(result.workbook, compileOptions);
|
|
3896
3929
|
const wb = await ExprResolver.toBuffer(result.workbook);
|
|
3930
|
+
await saveCompile(compileOptions, wb);
|
|
3897
3931
|
const w = await Workbook.parse(wb, options);
|
|
3898
3932
|
w.setQueryFunctionHandler(commandExtendQuery);
|
|
3899
3933
|
await w.substituteAll(values);
|
|
@@ -3932,6 +3966,7 @@ export {
|
|
|
3932
3966
|
hasGeneratorToken,
|
|
3933
3967
|
isRuleToken,
|
|
3934
3968
|
isUrl,
|
|
3969
|
+
loadCompileSheets,
|
|
3935
3970
|
loadWorkbook,
|
|
3936
3971
|
mergeMap,
|
|
3937
3972
|
parseWorkSheetRules,
|