vue-office icon indicating copy to clipboard operation
vue-office copied to clipboard

excel 展示数字的时候是否可以改成可配置的 去 toFixed(1) 保留几位小数

Open wyaoting opened this issue 11 months ago • 0 comments

 if (cell.style.numFmt) {
          if (cell.style.numFmt.endsWith("%")) {
            let precision = cell.style.numFmt.match(/\.(\d+)%/);
            if (precision) {
              return (value * 100).toFixed(precision[1].length) + "%";
            } else {
              return value * 100 + "%";
            }
          } else if (/0(\.0+)?/.test(cell.style.numFmt)) {
            let prefix = "";
            if (cell.style.numFmt.startsWith("$")) {
              prefix = "$";
            } else if (cell.style.numFmt.startsWith('"¥')) {
              prefix = "¥";
            }

            if (value === 0 && cell.style.numFmt.startsWith("_")) {
              return "-";
            }
            let precision = cell.style.numFmt.match(/0\.(0+)(_|;|$)/);
            if (precision) {
              precision = precision[1].length;
            } else {
              precision = 0;
            }

            let result = value.toFixed(precision) + "";
            if (cell.style.numFmt.includes("#,##")) {
              //千分位
              result = result.split(".");
              let number = result[0].split("").reverse();
              let newNumber = [];
              for (let i = 0; i < number.length; i++) {
                newNumber.push(number[i]);
                if (
                  (i + 1) % 3 === 0 &&
                  i < number.length - 1 &&
                  number[i + 1] !== "-"
                ) {
                  newNumber.push(",");
                }
              }
              result[0] = newNumber.reverse().join("");
              result = result.join(".");
            }
            return prefix + result;
          }
        }
        return value.toFixed(1) + "";

image 大佬有时间优化吗? x-data-spreadsheet 这个库不知道为啥会自动 聚焦,github 库上有 autoFocus 但是我看大佬依赖包没有这个配置项

wyaoting avatar Mar 22 '24 02:03 wyaoting