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(sheet): force string sets style (#2448)
Dushusir17130d1c4319
diff --git a/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.tsindex 7b38d1a8ac..c51eceb7b6 100644--- a/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts+++ b/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IMutationInfo } from '@univerjs/core';-import { CellValueType, Disposable, IUniverInstanceService, LifecycleStages, ObjectMatrix, OnLifecycle, Range, Tools } from '@univerjs/core';+import type { IMutationInfo, Workbook } from '@univerjs/core';+import { CellValueType, Disposable, IUniverInstanceService, LifecycleStages, ObjectMatrix, OnLifecycle, Range, Tools, UniverInstanceType } from '@univerjs/core';import { Inject, Injector } from '@wendellhu/redi';import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';import { ClearSelectionAllCommand, ClearSelectionContentCommand, ClearSelectionFormatCommand, getSheetCommandTarget, SelectionManagerService, SetRangeValuesCommand, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService } from '@univerjs/sheets';@@ -51,6 +51,7 @@ export class SheetHyperLinkSetRangeController extends Disposable {if (command.id === AddHyperLinkCommand.id) {const params = command.params as IAddHyperLinkCommandParams;const { unitId, subUnitId, link } = params;+ const currentCell = this._getCurrentCell(unitId, subUnitId, link.row, link.column);const redoParams: ISetRangeValuesMutationParams = {unitId,subUnitId,@@ -58,8 +59,9 @@ export class SheetHyperLinkSetRangeController extends Disposable {[link.row]: {[link.column]: {v: link.display,- t: CellValueType.STRING,+ // t: CellValueType.STRING, // Setting a link to a number is still a numberp: null,+ t: currentCell?.t ?? undefined, // Keep force string type},},},@@ -258,4 +260,8 @@ export class SheetHyperLinkSetRangeController extends Disposable {},}));}++ private _getCurrentCell(unitId: string, subUnitId: string, row: number, col: number) {+ return this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(subUnitId)?.getCell(row, col);+ }}diff --git a/packages/sheets/src/commands/mutations/__tests__/set-range-values.mutation.spec.ts b/packages/sheets/src/commands/mutations/__tests__/set-range-values.mutation.spec.tsindex e0aa50e5ba..82a4810b75 100644--- a/packages/sheets/src/commands/mutations/__tests__/set-range-values.mutation.spec.ts+++ b/packages/sheets/src/commands/mutations/__tests__/set-range-values.mutation.spec.ts@@ -36,6 +36,8 @@ describe('test "SetRangeValuesMutation" ', () => {expect(checkCellValueType(1, CellValueType.BOOLEAN)).toBe(CellValueType.BOOLEAN); // it is valid boolean valueexpect(checkCellValueType(0, CellValueType.BOOLEAN)).toBe(CellValueType.BOOLEAN); // it is valid boolean value++ expect(checkCellValueType('2', CellValueType.FORCE_STRING)).toBe(CellValueType.FORCE_STRING); // do not change cell value type when it is force string});it('should be able to cast values that can be casted to boolean', () => {diff --git a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts b/packages/sheets/src/commands/mutations/set-range-values.mutation.tsindex 4c00c6e685..47ab966bf0 100644--- a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-range-values.mutation.ts@@ -270,6 +270,8 @@ export const SetRangeValuesMutation: IMutation<ISetRangeValuesMutationParams, boexport function checkCellValueType(v: Nullable<CellValue>, oldType: Nullable<CellValueType>): Nullable<CellValueType> {if (v === null) return null;+ if (oldType === CellValueType.FORCE_STRING) return oldType;+if (typeof v === 'string') {if (isSafeNumeric(v)) {if ((+v === 0 || +v === 1) && oldType === CellValueType.BOOLEAN) {