@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.mjs CHANGED
@@ -2998,14 +2998,20 @@ var extractMacro = function(expr, options) {
2998
2998
  return extracResult;
2999
2999
  };
3000
3000
  var __codeKey = (str) => {
3001
- let vs = str.trim().replace("-", "_").replace("/", "_").trim();
3002
- for (; vs.indexOf("__") >= 0; ) {
3003
- vs = vs.replace("__", "_");
3001
+ const replaces = [` `, `-`, `/`, `,`, `'`, `&`, `.`, `(`, `)`, `{`, `}`, `@`, `\\`, `[`, `]`, `#`, `:`];
3002
+ for (const k in replaces) {
3003
+ str = str.replace(k, "_").trim();
3004
+ if (str.indexOf("__") >= 0) {
3005
+ str = str.replace("__", "_");
3006
+ }
3007
+ }
3008
+ if (str.startsWith("_")) {
3009
+ str = str.substring(1);
3004
3010
  }
3005
- for (; vs.indexOf(" ") >= 0; ) {
3006
- vs = vs.replace(" ", "");
3011
+ if (str.endsWith("_")) {
3012
+ str = str.substring(0, str.length - 1);
3007
3013
  }
3008
- return vs.trim().toUpperCase();
3014
+ return str.toUpperCase();
3009
3015
  };
3010
3016
  var __numberKey = (str) => {
3011
3017
  return Number.parseInt(str, 10).toString();
@@ -3435,21 +3441,26 @@ var compileRowCells = function(ctx, expr, cellPoints, rowIndex, errs) {
3435
3441
  return;
3436
3442
  }
3437
3443
  ctx.currentExpr = expr;
3438
- cellPoints.forEach((cellPoint, index) => {
3439
- const r = cellPoint.Row;
3440
- const sheet = ctx.sheet;
3441
- const c = cellPoint.Column;
3442
- const cell = sheet.findCell(r, c);
3443
- if (cell === void 0 || cell.value !== void 0 && cell.value !== null && cell.value !== "") {
3444
- return;
3445
- }
3446
- let templateValue = String(expr.value);
3447
- const macroTokens2 = getMacroTokens(expr);
3448
- templateValue = resolveFunctionExpr(ctx, templateValue, expr);
3449
- templateValue = resolveCompileMacroExpr(ctx, templateValue, macroTokens2, index, cellPoints.length);
3450
- templateValue = resolveAliasExpr(ctx, templateValue, index);
3451
- cell.value = resolveValueExpr(ctx, templateValue);
3452
- });
3444
+ try {
3445
+ cellPoints.forEach((cellPoint, index) => {
3446
+ const r = cellPoint.Row;
3447
+ const sheet = ctx.sheet;
3448
+ const c = cellPoint.Column;
3449
+ const cell = sheet.findCell(r, c);
3450
+ if (cell === void 0 || cell.value !== void 0 && cell.value !== null && cell.value !== "") {
3451
+ return;
3452
+ }
3453
+ let templateValue = String(expr.value);
3454
+ const macroTokens2 = getMacroTokens(expr);
3455
+ templateValue = resolveFunctionExpr(ctx, templateValue, expr);
3456
+ templateValue = resolveCompileMacroExpr(ctx, templateValue, macroTokens2, index, cellPoints.length);
3457
+ templateValue = resolveAliasExpr(ctx, templateValue, index);
3458
+ cell.value = resolveValueExpr(ctx, templateValue);
3459
+ });
3460
+ } catch (err) {
3461
+ const msg = err.message;
3462
+ throw new Error(`expr:${expr.express}, resolve error: ${msg}`);
3463
+ }
3453
3464
  };
3454
3465
  var generateWorkSheetCellsPlaceholder = function(ctx, expr, sheet) {
3455
3466
  const errs = [];