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(facade): fix set horizontal, vertical, warp (#1766)
#FF00001876e68d2324
diff --git a/packages/facade/src/apis/sheets/__tests__/f-range.spec.ts b/packages/facade/src/apis/sheets/__tests__/f-range.spec.tsindex fc0f2a3c41..b84ab7c3a2 100644--- a/packages/facade/src/apis/sheets/__tests__/f-range.spec.ts+++ b/packages/facade/src/apis/sheets/__tests__/f-range.spec.ts@@ -15,8 +15,8 @@*/import type { ICellData, IStyleData, Nullable } from '@univerjs/core';-import { ICommandService, IUniverInstanceService } from '@univerjs/core';-import { SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand } from '@univerjs/sheets';+import { HorizontalAlign, ICommandService, IUniverInstanceService, VerticalAlign, WrapStrategy } from '@univerjs/core';+import { SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand } from '@univerjs/sheets';import type { Injector } from '@wendellhu/redi';import { beforeEach, describe, expect, it } from 'vitest';@@ -49,6 +49,9 @@ describe('Test FRange', () => {commandService.registerCommand(SetRangeValuesCommand);commandService.registerCommand(SetRangeValuesMutation);commandService.registerCommand(SetStyleCommand);+ commandService.registerCommand(SetVerticalTextAlignCommand);+ commandService.registerCommand(SetHorizontalTextAlignCommand);+ commandService.registerCommand(SetTextWrapCommand);getValueByPosition = (startRow: number,@@ -451,4 +454,21 @@ describe('Test FRange', () => {expect(getStyleByPosition(0, 0, 0, 0)?.fs).toBe(undefined);expect(getStyleByPosition(0, 0, 0, 0)?.cl).toBe(undefined);});++ it('Range set range vertical and Horizontal and Warp', async () => {+ const activeSheet = univerAPI.getActiveWorkbook()?.getActiveSheet();++ const range = activeSheet?.getRange(0, 0, 10, 10);++ await range!.setVerticalAlignment('middle');+ await range!.setHorizontalAlignment('center');++ expect(getStyleByPosition(0, 0, 0, 0)?.ht).toBe(HorizontalAlign.CENTER);+ expect(getStyleByPosition(0, 0, 0, 0)?.vt).toBe(VerticalAlign.MIDDLE);++ await range!.setWrap(true);+ expect(getStyleByPosition(0, 0, 0, 0)?.tb).toBe(WrapStrategy.WRAP);+ await range!.setWrapStrategy(WrapStrategy.CLIP);+ expect(getStyleByPosition(0, 0, 0, 0)?.tb).toBe(WrapStrategy.CLIP);+ });});diff --git a/packages/facade/src/apis/sheets/f-range.ts b/packages/facade/src/apis/sheets/f-range.tsindex 9f3ec933c6..5ccde1d6ee 100644--- a/packages/facade/src/apis/sheets/f-range.ts+++ b/packages/facade/src/apis/sheets/f-range.ts@@ -160,6 +160,10 @@ export class FRange {});}+ /**+ * Set the cell wrap of the given range.+ * Cells with wrap enabled (the default) resize to display their full content. Cells with wrap disabled display as much as possible in the cell without resizing or running to multiple lines.+ */setWrap(isWrapEnabled: boolean): Promise<boolean> {return this._commandService.executeCommand(SetTextWrapCommand.id, {unitId: this._workbook.getUnitId(),@@ -169,6 +173,9 @@ export class FRange {} as ISetTextWrapCommandParams);}+ /**+ * Sets the text wrapping strategy for the cells in the range.+ */setWrapStrategy(strategy: WrapStrategy): Promise<boolean> {return this._commandService.executeCommand(SetTextWrapCommand.id, {unitId: this._workbook.getUnitId(),@@ -178,6 +185,9 @@ export class FRange {} as ISetTextWrapCommandParams);}+ /**+ * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).+ */setVerticalAlignment(alignment: FVerticalAlignment): Promise<boolean> {return this._commandService.executeCommand(SetVerticalTextAlignCommand.id, {unitId: this._workbook.getUnitId(),@@ -187,6 +197,9 @@ export class FRange {} as ISetVerticalTextAlignCommandParams);}+ /**+ * Set the horizontal (left to right) alignment for the given range (left/center/right).+ */setHorizontalAlignment(alignment: FHorizontalAlignment): Promise<boolean> {return this._commandService.executeCommand(SetHorizontalTextAlignCommand.id, {unitId: this._workbook.getUnitId(),diff --git a/packages/sheets/src/commands/commands/set-style.command.ts b/packages/sheets/src/commands/commands/set-style.command.tsindex c2e20a06ae..6fa24d675b 100644--- a/packages/sheets/src/commands/commands/set-style.command.ts+++ b/packages/sheets/src/commands/commands/set-style.command.ts@@ -67,7 +67,7 @@ export const SetStyleCommand: ICommand<ISetStyleCommandParams<unknown>> = {type: CommandType.COMMAND,id: 'sheet.command.set-style',- handler: async <T>(accessor: IAccessor, params: ISetStyleCommandParams<T>) => {+ handler: async <T> (accessor: IAccessor, params: ISetStyleCommandParams<T>) => {const univerInstanceService = accessor.get(IUniverInstanceService);const {@@ -466,7 +466,7 @@ export const ResetBackgroundColorCommand: ICommand = {},};-export interface ISetVerticalTextAlignCommandParams {+export interface ISetVerticalTextAlignCommandParams extends ISetStyleCommonParams {value: VerticalAlign;}@@ -480,6 +480,9 @@ export const SetVerticalTextAlignCommand: ICommand<ISetVerticalTextAlignCommandPconst commandService = accessor.get(ICommandService);const setStyleParams: ISetStyleCommandParams<VerticalAlign> = {+ unitId: params.unitId,+ subUnitId: params.subUnitId,+ range: params.range,style: {type: 'vt',value: params.value,@@ -490,7 +493,7 @@ export const SetVerticalTextAlignCommand: ICommand<ISetVerticalTextAlignCommandP},};-export interface ISetHorizontalTextAlignCommandParams {+export interface ISetHorizontalTextAlignCommandParams extends ISetStyleCommonParams {value: HorizontalAlign;}@@ -504,6 +507,9 @@ export const SetHorizontalTextAlignCommand: ICommand<ISetHorizontalTextAlignCommconst commandService = accessor.get(ICommandService);const setStyleParams: ISetStyleCommandParams<HorizontalAlign> = {+ unitId: params.unitId,+ subUnitId: params.subUnitId,+ range: params.range,style: {type: 'ht',value: params.value,@@ -528,6 +534,9 @@ export const SetTextWrapCommand: ICommand<ISetTextWrapCommandParams> = {const commandService = accessor.get(ICommandService);const setStyleParams: ISetStyleCommandParams<WrapStrategy> = {+ unitId: params.unitId,+ subUnitId: params.subUnitId,+ range: params.range,style: {type: 'tb',value: params.value,