@vdhewei/xlsx-template-lib 1.3.1 → 1.3.3

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.js CHANGED
@@ -3076,14 +3076,20 @@ var extractMacro = function(expr, options) {
3076
3076
  return extracResult;
3077
3077
  };
3078
3078
  var __codeKey = (str) => {
3079
- let vs = str.trim().replace("-", "_").replace("/", "_").trim();
3080
- for (; vs.indexOf("__") >= 0; ) {
3081
- vs = vs.replace("__", "_");
3079
+ const replaces = [` `, `-`, `/`, `,`, `'`, `&`, `.`, `(`, `)`, `{`, `}`, `@`, `\\`, `[`, `]`, `#`, `:`];
3080
+ for (const k in replaces) {
3081
+ str = str.replace(k, "_").trim();
3082
+ if (str.indexOf("__") >= 0) {
3083
+ str = str.replace("__", "_");
3084
+ }
3085
+ }
3086
+ if (str.startsWith("_")) {
3087
+ str = str.substring(1);
3082
3088
  }
3083
- for (; vs.indexOf(" ") >= 0; ) {
3084
- vs = vs.replace(" ", "");
3089
+ if (str.endsWith("_")) {
3090
+ str = str.substring(0, str.length - 1);
3085
3091
  }
3086
- return vs.trim().toUpperCase();
3092
+ return str.toUpperCase();
3087
3093
  };
3088
3094
  var __numberKey = (str) => {
3089
3095
  return Number.parseInt(str, 10).toString();
@@ -3513,21 +3519,26 @@ var compileRowCells = function(ctx, expr, cellPoints, rowIndex, errs) {
3513
3519
  return;
3514
3520
  }
3515
3521
  ctx.currentExpr = expr;
3516
- cellPoints.forEach((cellPoint, index) => {
3517
- const r = cellPoint.Row;
3518
- const sheet = ctx.sheet;
3519
- const c = cellPoint.Column;
3520
- const cell = sheet.findCell(r, c);
3521
- if (cell === void 0 || cell.value !== void 0 && cell.value !== null && cell.value !== "") {
3522
- return;
3523
- }
3524
- let templateValue = String(expr.value);
3525
- const macroTokens2 = getMacroTokens(expr);
3526
- templateValue = resolveFunctionExpr(ctx, templateValue, expr);
3527
- templateValue = resolveCompileMacroExpr(ctx, templateValue, macroTokens2, index, cellPoints.length);
3528
- templateValue = resolveAliasExpr(ctx, templateValue, index);
3529
- cell.value = resolveValueExpr(ctx, templateValue);
3530
- });
3522
+ try {
3523
+ cellPoints.forEach((cellPoint, index) => {
3524
+ const r = cellPoint.Row;
3525
+ const sheet = ctx.sheet;
3526
+ const c = cellPoint.Column;
3527
+ const cell = sheet.findCell(r, c);
3528
+ if (cell === void 0 || cell.value !== void 0 && cell.value !== null && cell.value !== "") {
3529
+ return;
3530
+ }
3531
+ let templateValue = String(expr.value);
3532
+ const macroTokens2 = getMacroTokens(expr);
3533
+ templateValue = resolveFunctionExpr(ctx, templateValue, expr);
3534
+ templateValue = resolveCompileMacroExpr(ctx, templateValue, macroTokens2, index, cellPoints.length);
3535
+ templateValue = resolveAliasExpr(ctx, templateValue, index);
3536
+ cell.value = resolveValueExpr(ctx, templateValue);
3537
+ });
3538
+ } catch (err) {
3539
+ const msg = err.message;
3540
+ throw new Error(`expr:${expr.express}, resolve error: ${msg}`);
3541
+ }
3531
3542
  };
3532
3543
  var generateWorkSheetCellsPlaceholder = function(ctx, expr, sheet) {
3533
3544
  const errs = [];