Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix: fixed the issue that the numfmt setting for numeric strings does not take effect (#5278)

wpxp1234568073a3a5bba2
diff --git a/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts b/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts
index f768641ef7..447b86c067 100644
--- a/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts
+++ b/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts
@@ -96,7 +96,7 @@ export class NumfmtAlertRenderController extends Disposable implements IRenderMo
}
this._cellAlertManagerService.showAlert({
- type: CellAlertType.WARNING,
+ type: CellAlertType.ERROR,
title: this._localeService.t('info.error'),
message: this._localeService.t('info.forceStringInfo'),
location,
diff --git a/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.ts
index a61ec2818f..3f5a2fcae5 100644
--- a/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.ts
+++ b/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.ts
@@ -113,7 +113,7 @@ export class SheetsNumfmtCellContentController extends Disposable {
const sheetId = location.subUnitId;
let numfmtValue;
const originCellValue = cell;
- if (!originCellValue) {
+ if (!originCellValue || originCellValue.v === undefined || originCellValue.v === null) {
return next(cell);
}
@@ -132,8 +132,8 @@ export class SheetsNumfmtCellContentController extends Disposable {
return next(cell);
}
- const type = cell?.t || checkCellValueType(originCellValue.v);
- // just handle number
+ const type = checkCellValueType(originCellValue.v);
+ // just handle number or number string
if (type !== CellValueType.NUMBER) {
return next(cell);
}
@@ -160,9 +160,7 @@ export class SheetsNumfmtCellContentController extends Disposable {
if (cache && cache.parameters === `${originCellValue.v}_${numfmtValue.pattern}`) {
return next({ ...cell, ...cache.result });
}
- if (originCellValue.v === undefined || originCellValue.v === null) {
- return next(cell);
- }
+
const info = getPatternPreviewIgnoreGeneral(numfmtValue.pattern, Number(originCellValue.v), this.local);
numfmtRes = info.result;
if (!numfmtRes) {