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(sheets): preserve default style in blank cell editor (#7654)
wpxp123456a53381cdf367
diff --git a/packages/core/src/sheets/__tests__/worksheet.spec.ts b/packages/core/src/sheets/__tests__/worksheet.spec.tsindex fbe1e8ac40..5e433e5ea1 100644--- a/packages/core/src/sheets/__tests__/worksheet.spec.ts+++ b/packages/core/src/sheets/__tests__/worksheet.spec.ts@@ -19,7 +19,7 @@ import type { IRange, IWorkbookData } from '../typedef';import type { Worksheet } from '../worksheet';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { DisposableCollection } from '../../shared/lifecycle';-import { CellValueType } from '../../types/enum';+import { CellValueType, HorizontalAlign, VerticalAlign, WrapStrategy } from '../../types/enum';import { LocaleType } from '../../types/enum/locale-type';import { RANGE_TYPE } from '../typedef';import { extractPureTextFromCell } from '../worksheet';@@ -323,6 +323,29 @@ describe('test worksheet', () => {},});});++ it('preserves the composed style in the blank cell document model', () => {+ const paddingData = { t: 3, r: 4, b: 5, l: 6 };+ worksheet.setDefaultCellStyle({+ ff: 'Noto Sans',+ bg: { rgb: '#abcdef' },+ ht: HorizontalAlign.CENTER,+ vt: VerticalAlign.MIDDLE,+ tb: WrapStrategy.WRAP,+ pd: paddingData,+ });++ const documentLayoutObject = worksheet.getBlankCellDocumentModel(null, 2, 0);++ expect(documentLayoutObject).toMatchObject({+ horizontalAlign: HorizontalAlign.CENTER,+ verticalAlign: VerticalAlign.MIDDLE,+ wrapStrategy: WrapStrategy.WRAP,+ paddingData,+ fill: '#abcdef',+ });+ expect(documentLayoutObject.fontString).toContain('Noto Sans');+ });});});diff --git a/packages/core/src/sheets/worksheet.ts b/packages/core/src/sheets/worksheet.tsindex 8f7eb26e55..5fe8b80e9b 100644--- a/packages/core/src/sheets/worksheet.ts+++ b/packages/core/src/sheets/worksheet.ts@@ -1309,19 +1309,14 @@ export class Worksheet {return documentModelObject;}- const content = '';-- let fontString = 'document';-+ const cellOtherConfig = extractOtherStyle(style);const textRotation: ITextRotation = DEFAULT_STYLES.tr;- const horizontalAlign: HorizontalAlign = DEFAULT_STYLES.ht;- const verticalAlign: VerticalAlign = DEFAULT_STYLES.vt;- const wrapStrategy: WrapStrategy = DEFAULT_STYLES.tb;- const paddingData: IPaddingData = DEFAULT_PADDING_DATA;-- fontString = getFontStyleString({}).fontCache;-- const documentModel = createDocumentModelWithStyle(content, textStyle);+ const horizontalAlign: HorizontalAlign = cellOtherConfig.horizontalAlign ?? DEFAULT_STYLES.ht;+ const verticalAlign: VerticalAlign = cellOtherConfig.verticalAlign ?? DEFAULT_STYLES.vt;+ const wrapStrategy: WrapStrategy = cellOtherConfig.wrapStrategy ?? DEFAULT_STYLES.tb;+ const paddingData: IPaddingData = cellOtherConfig.paddingData ?? DEFAULT_PADDING_DATA;+ const fontString = getFontStyleString(textStyle).fontCache;+ const documentModel = createDocumentModelWithStyle('', textStyle);return {documentModel,@@ -1331,6 +1326,7 @@ export class Worksheet {verticalAlign,horizontalAlign,paddingData,+ fill: style?.bg?.rgb,};}