Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"immer": "^9.0.12",
"lodash": "^4.17.21",
"numeral": "^2.0.6",
"numfmt": "2.5.1",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/api/cell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import _ from "lodash";
// @ts-ignore
import numfmt from "numfmt";
import { Context } from "../context";
import {
delFunctionGroup,
Expand All @@ -13,8 +15,6 @@ import {
import { Cell, CellStyle, SingleRange } from "../types";
import { CommonOptions, getSheet } from "./common";
import { SHEET_NOT_FOUND } from "./errors";
// @ts-ignore
import SSF from "../modules/ssf";

export function getCellValue(
ctx: Context,
Expand Down Expand Up @@ -220,7 +220,7 @@ export function setCellFormat(
"'fa' and 't' should be present in value when attr is 'ct'"
);
} else if (attr === "ct" && !_.isNil(cellData.v)) {
cellData.m = SSF.format(value.fa, cellData.v); // auto generate mask
cellData.m = numfmt.format(value.fa, cellData.v); // auto generate mask
}

// @ts-ignore
Expand Down
26 changes: 13 additions & 13 deletions packages/core/src/modules/format.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numeral from "numeral";
import _ from "lodash";
import { isRealNum, valueIsError, isdatetime } from "./validation";
// @ts-ignore
import SSF from "./ssf";
import numfmt from "numfmt";
import { isRealNum, valueIsError, isdatetime } from "./validation";
import { CellMatrix } from "../types";
import { getCellValue } from "./cell";

Expand Down Expand Up @@ -126,7 +126,7 @@ export function genarate(value: string | number | boolean) {
ct = { fa: "#0.E+00", t: "n" };
}

m = SSF.format(ct.fa, v);
m = numfmt.format(ct.fa, v);
} else if (value.toString().indexOf("%") > -1) {
const index = value.toString().indexOf("%");
const value2 = value.toString().substring(0, index);
Expand Down Expand Up @@ -160,15 +160,15 @@ export function genarate(value: string | number | boolean) {
t: "n",
};
v = numeral(value).value();
m = SSF.format(ct.fa, v);
m = numfmt.format(ct.fa, v);
} else {
m = value.toString();
ct = { fa: "@", t: "s" };
}
} else {
ct = { fa: `0.${new Array(len + 1).join("0")}%`, t: "n" };
v = numeral(value).value();
m = SSF.format(ct.fa, v);
m = numfmt.format(ct.fa, v);
}
} else {
m = value.toString();
Expand All @@ -188,15 +188,15 @@ export function genarate(value: string | number | boolean) {
if (isThousands) {
ct = { fa: "#,##0%", t: "n" };
v = numeral(value).value();
m = SSF.format(ct.fa, v);
m = numfmt.format(ct.fa, v);
} else {
m = value.toString();
ct = { fa: "@", t: "s" };
}
} else {
ct = { fa: "0%", t: "n" };
v = numeral(value).value();
m = SSF.format(ct.fa, v);
m = numfmt.format(ct.fa, v);
}
} else {
m = value.toString();
Expand Down Expand Up @@ -226,7 +226,7 @@ export function genarate(value: string | number | boolean) {
if (isThousands) {
ct = { fa: `#,##0.${new Array(len + 1).join("0")}`, t: "n" };
v = numeral(value).value();
m = SSF.format(ct.fa, v);
m = numfmt.format(ct.fa, v);
} else {
m = value.toString();
ct = { fa: "@", t: "s" };
Expand All @@ -235,7 +235,7 @@ export function genarate(value: string | number | boolean) {
if (isRealNum(value1) && isRealNum(value2)) {
ct = { fa: `0.${new Array(len + 1).join("0")}`, t: "n" };
v = numeral(value).value();
m = SSF.format(ct.fa, v);
m = numfmt.format(ct.fa, v);
} else {
m = value.toString();
ct = { fa: "@", t: "s" };
Expand Down Expand Up @@ -270,7 +270,7 @@ export function genarate(value: string | number | boolean) {
}

ct.t = "d";
m = SSF.format(ct.fa, v);
m = numfmt.format(ct.fa, v);
} else {
m = value as string;
ct.fa = "General";
Expand All @@ -281,11 +281,11 @@ export function genarate(value: string | number | boolean) {
}

export function update(fmt: string, v: any) {
return SSF.format(fmt, v);
return numfmt.format(fmt, v);
}

export function is_date(fmt: string, v?: any) {
return SSF.is_date(fmt, v);
export function is_date(fmt: string) {
return numfmt.isDate(fmt);
}

function fuzzynum(s: string | number) {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/modules/selection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import _, { isPlainObject } from "lodash";
// @ts-ignore
import numfmt from "numfmt";
import type { Sheet as SheetType, Freezen, Range } from "../types";
import { Context, getFlowdata } from "../context";
import {
Expand All @@ -20,8 +22,6 @@ import {
} from "../utils";
import { hasPartMC } from "./validation";
import { update } from "./format";
// @ts-ignore
import SSF from "./ssf";
import { CFSplitRange } from "./ConditionFormat";

export const selectionCache = {
Expand Down Expand Up @@ -2380,9 +2380,9 @@ export function calcSelectionInfo(ctx: Context, lang?: string | null) {
}
const formatString =
lang && !["zh", "zh_tw"].includes(lang) ? "0.00" : "w0.00";
const average: string = SSF.format(formatString, sum / numberC);
sum = SSF.format(formatString, sum);
max = SSF.format(formatString, max);
min = SSF.format(formatString, min);
const average: string = numfmt.format(formatString, sum / numberC);
sum = numfmt.format(formatString, sum);
max = numfmt.format(formatString, max);
min = numfmt.format(formatString, min);
return { numberC, count, sum, max, min, average };
}
Loading