Browse Source

更新配置

lanyunfei 7 months ago
parent
commit
d8ad55f8a0
2 changed files with 18 additions and 8 deletions
  1. 10 4
      dist/ExcelUtil.js
  2. 8 4
      src/ExcelUtil.ts

+ 10 - 4
dist/ExcelUtil.js

@@ -85,6 +85,7 @@ var ExcelUtil = /** @class */ (function () {
                 var type = '';
                 var isUniq = false; // 重复的行
                 var isArray = false; // 是否是数组
+                var canZeroStr = false; // 是否允许为0的字符串
                 if (ls != -1 && le != -1 && le > ls + 1) {
                     var s = name_1.substring(ls + 1, le);
                     name_1 = name_1.substring(0, ls);
@@ -107,9 +108,12 @@ var ExcelUtil = /** @class */ (function () {
                         else if (s[i] == 'a') { // array
                             isArray = true;
                         }
-                        else if (s[i] == 'k') { // array
+                        else if (s[i] == 'k') { // key
                             Config_1.Config.objectKey = name_1;
                         }
+                        else if (s[i] == 'z') {
+                            canZeroStr = true;
+                        }
                         else {
                             Config_1.Config.checkState(Config_1.RetCode.EXCEL_DATA_ERROR, "".concat(StringUtil_1.default.getCheckString(address, ret), " \n\u610F\u5916\u7684\u8868\u5934\u5B9A\u4E49\uFF01").concat(s));
                         }
@@ -118,7 +122,7 @@ var ExcelUtil = /** @class */ (function () {
                 if (ret.keys.findIndex(function (v) { return v == name_1; }) != -1) {
                     Config_1.Config.checkState(Config_1.RetCode.COL_NAME_REPEAT, "".concat(StringUtil_1.default.getCheckString(address, ret), " \n\u540C\u4E00\u4E2A\u8868\u4E2D\u53D1\u73B0\u5217\u540D\u91CD\u590D\uFF01").concat(name_1));
                 }
-                ret.keys.push({ name: name_1, outputclient: outputclient, outputserver: outputserver, type: type, isUniq: isUniq, isArray: isArray });
+                ret.keys.push({ name: name_1, outputclient: outputclient, outputserver: outputserver, type: type, isUniq: isUniq, isArray: isArray, canZeroStr: canZeroStr });
                 delete worksheet[address]; // 删除表头信息
             }
         };
@@ -169,7 +173,7 @@ var ExcelUtil = /** @class */ (function () {
         }
         return ret;
     };
-    ExcelUtil.tryGetArray = function (value, isMult, isNumber) {
+    ExcelUtil.tryGetArray = function (value, isMult, isNumber, canZeroStr) {
         var ret = '';
         value = StringUtil_1.default.replaceAll(value, '<color=#', '<color=@');
         var threeArr = value.split(Config_1.Config.THREEE_ARRAY_SYMBOL);
@@ -187,6 +191,8 @@ var ExcelUtil = /** @class */ (function () {
                         ret += oneUnit;
                     }
                     else {
+                        if (!canZeroStr && oneUnit.toString() == '0')
+                            oneUnit = '';
                         ret += "'".concat(oneUnit, "'"); // 支持字符串数组
                     }
                     if (oneIndex != oneArr.length - 1) {
@@ -241,7 +247,7 @@ var ExcelUtil = /** @class */ (function () {
                 else if (headInfo.keys[i].type == 'string' || headInfo.keys[i].type == 'string[]') {
                     if (isArray[i]) {
                         headInfo.keys[i].type = 'string[]';
-                        temp = this.tryGetArray(temp, isMultArr[i]);
+                        temp = this.tryGetArray(temp, isMultArr[i], false, headInfo.keys[i].canZeroStr);
                     }
                 }
                 cobj[headInfo.keys[i].name] = temp;

+ 8 - 4
src/ExcelUtil.ts

@@ -89,6 +89,7 @@ export default class ExcelUtil {
                 let type = ''
                 let isUniq = false      // 重复的行
                 let isArray = false     // 是否是数组
+                let canZeroStr = false     // 是否允许为0的字符串
                 if (ls != -1 && le != -1 && le > ls + 1) {
                     let s = name.substring(ls + 1, le)
                     name = name.substring(0, ls)
@@ -105,8 +106,10 @@ export default class ExcelUtil {
                             isUniq = true
                         } else if (s[i] == 'a') { // array
                             isArray = true
-                        } else if (s[i] == 'k') { // array
+                        } else if (s[i] == 'k') { // key
                             Config.objectKey = name
+                        } else if (s[i] == 'z') {
+                            canZeroStr = true
                         } else {
                             Config.checkState(RetCode.EXCEL_DATA_ERROR, `${StringUtil.getCheckString(address, ret)} \n意外的表头定义!${s}`)
                         }
@@ -115,7 +118,7 @@ export default class ExcelUtil {
                 if (ret.keys.findIndex(v => v == name) != -1) {
                     Config.checkState(RetCode.COL_NAME_REPEAT, `${StringUtil.getCheckString(address, ret)} \n同一个表中发现列名重复!${name}`)
                 }
-                ret.keys.push({name, outputclient, outputserver, type, isUniq, isArray})
+                ret.keys.push({name, outputclient, outputserver, type, isUniq, isArray, canZeroStr})
                 delete worksheet[address];  // 删除表头信息
             }
 
@@ -163,7 +166,7 @@ export default class ExcelUtil {
         return ret;
     }
 
-    public static tryGetArray(value: string, isMult: boolean, isNumber?: boolean) {
+    public static tryGetArray(value: string, isMult: boolean, isNumber: boolean, canZeroStr?: boolean) {
         let ret = '';
         value = StringUtil.replaceAll(value, '<color=#', '<color=@')
         let threeArr = value.split(Config.THREEE_ARRAY_SYMBOL)
@@ -180,6 +183,7 @@ export default class ExcelUtil {
                     if (MathUtil.isNumber(oneUnit) && isNumber) {
                         ret += oneUnit
                     } else {
+                        if (!canZeroStr && oneUnit.toString() == '0') oneUnit = ''
                         ret += `'${oneUnit}'`	// 支持字符串数组
                     }
                     if (oneIndex != oneArr.length - 1) {
@@ -232,7 +236,7 @@ export default class ExcelUtil {
                 } else if (headInfo.keys[i].type == 'string' || headInfo.keys[i].type == 'string[]') {
                     if (isArray[i]) {
                         headInfo.keys[i].type = 'string[]'
-                        temp = this.tryGetArray(temp, isMultArr[i])
+                        temp = this.tryGetArray(temp, isMultArr[i], false, headInfo.keys[i].canZeroStr)
                     }
                 }
                 cobj[headInfo.keys[i].name] = temp