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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: force string supports cell string type (#5019)
Dushusir5050785c92c7
diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.tsindex d1b4ec2672..4ae3d3d04e 100644--- a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts+++ b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts@@ -230,6 +230,25 @@ test('diff set force string cell', async () => {activeWorkbook.startEditing();await window.univerAPI.getActiveDocument().appendText("'1");activeWorkbook.endEditing(true);++ activeSheet.getRange('I1').setValue({+ v: '001',+ t: 1,+ s: {+ ff: 'Arial CE',+ fs: 11,+ bl: 1,+ cl: {+ rgb: '#000080',+ th: 0,+ },+ n: {+ pattern: 'General',+ },+ ht: 1,+ tb: 3,+ },+ });});const filename = generateSnapshotName('set-force-string-cell');diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-chromium-linux.pngnew file mode 100644index 0000000000..5f490a74e3Binary files /dev/null and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-chromium-linux.png differdiff --git a/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.tsindex 37190df0f6..886a7af963 100644--- a/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.ts+++ b/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.ts@@ -130,7 +130,7 @@ export class SheetsNumfmtCellContentController extends Disposable {return next(cell);}- const type = checkCellValueType(originCellValue.v);+ const type = cell.t || checkCellValueType(originCellValue.v);// just handle numberif (type !== CellValueType.NUMBER) {return next(cell);diff --git a/packages/sheets-ui/src/controllers/force-string-render.controller.ts b/packages/sheets-ui/src/controllers/force-string-render.controller.tsindex 0a14d9fbc6..e10420b97b 100644--- a/packages/sheets-ui/src/controllers/force-string-render.controller.ts+++ b/packages/sheets-ui/src/controllers/force-string-render.controller.ts@@ -17,6 +17,7 @@import type { Workbook } from '@univerjs/core';import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';import { CellValueType, Inject, InterceptorEffectEnum, isRealNum, RxDisposable } from '@univerjs/core';+import { isTextFormat } from '@univerjs/engine-numfmt';import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';@@ -57,7 +58,13 @@ export class ForceStringRenderController extends RxDisposable implements IRenderreturn next(cell);}- if (cell?.t === CellValueType.FORCE_STRING && isRealNum(cellRaw.v)) {+ if ((cell?.t === CellValueType.FORCE_STRING || cell?.t === CellValueType.STRING) && isRealNum(cellRaw.v)) {+ // If the cell is in text format, follow the logic of number format+ const cellStyle = pos.workbook.getStyles().get(cellRaw.s);+ if (isTextFormat(cellStyle?.n?.pattern)) {+ return next(cell);+ }+return next({...cell,markers: {