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): string bool and number align (#1525)
Univer473cf6f91844
diff --git a/packages/core/src/types/interfaces/i-document-data.ts b/packages/core/src/types/interfaces/i-document-data.tsindex 1c7cc52af8..1b2325f5d9 100644--- a/packages/core/src/types/interfaces/i-document-data.ts+++ b/packages/core/src/types/interfaces/i-document-data.ts@@ -15,7 +15,7 @@*/import type { ISize } from '../../services/floating-object/floating-object-interfaces';-import type { BooleanNumber, HorizontalAlign, LocaleType, TextDirection, VerticalAlign, WrapStrategy } from '../enum';+import type { BooleanNumber, CellValueType, HorizontalAlign, LocaleType, TextDirection, VerticalAlign, WrapStrategy } from '../enum';import type { IExtraModelData } from './i-extra-model-data';import type { IColorStyle, IStyleBase } from './i-style-data';@@ -364,7 +364,8 @@ export interface IDocumentRenderConfig {horizontalAlign?: HorizontalAlign; // HorizontalAlignment, only valid for pages, word does not have this arrangement, used for secondary calculationsisRotateNonEastAsian?: BooleanNumber; // Word is not rotate non-eastAsianbackground?: IColorStyle; // background- wrapStrategy?: WrapStrategy;+ wrapStrategy?: WrapStrategy; // wrap to the next line, for sheet cell+ cellValueType?: CellValueType; // sheet cell type, In a spreadsheet cell, without any alignment settings applied, text should be left-aligned, numbers should be right-aligned, and Boolean values should be center-aligned.}export interface ISectionBreakBase {diff --git a/packages/engine-render/src/components/docs/document.ts b/packages/engine-render/src/components/docs/document.tsindex 03f16910bc..fd91301900 100644--- a/packages/engine-render/src/components/docs/document.ts+++ b/packages/engine-render/src/components/docs/document.ts@@ -17,7 +17,7 @@import './extensions';import type { Nullable, Observer } from '@univerjs/core';-import { HorizontalAlign, Observable, VerticalAlign, WrapStrategy } from '@univerjs/core';+import { CellValueType, HorizontalAlign, Observable, VerticalAlign, WrapStrategy } from '@univerjs/core';import { calculateRectRotate, getRotateOffsetAndFarthestHypotenuse } from '../../basics/draw';import type { IDocumentSkeletonCached, IDocumentSkeletonPage } from '../../basics/i-document-skeleton-cached';@@ -235,11 +235,12 @@ export class Documents extends DocComponent {renderConfig = {},} = page;const {- verticalAlign = VerticalAlign.UNSPECIFIED,- horizontalAlign = HorizontalAlign.UNSPECIFIED,+ verticalAlign = VerticalAlign.TOP, // Do not make changes, otherwise the document will not render.+ horizontalAlign = HorizontalAlign.LEFT, // Do not make changes, otherwise the document will not render.centerAngle: centerAngleDeg = 0,vertexAngle: vertexAngleDeg = 0,wrapStrategy = WrapStrategy.UNSPECIFIED,+ cellValueType,// isRotateNonEastAsian = BooleanNumber.FALSE,} = renderConfig;@@ -248,7 +249,8 @@ export class Documents extends DocComponent {pagePaddingLeft,pagePaddingRight,horizontalAlign,- vertexAngleDeg+ vertexAngleDeg,+ cellValueType);const verticalOffsetNoAngle = this._verticalHandler(@@ -457,7 +459,8 @@ export class Documents extends DocComponent {pagePaddingLeft: number,pagePaddingRight: number,horizontalAlign: HorizontalAlign,- angle: number = 0+ angle: number = 0,+ cellValueType: Nullable<CellValueType>) {let offsetLeft = 0;if (horizontalAlign === HorizontalAlign.CENTER) {@@ -469,8 +472,24 @@ export class Documents extends DocComponent {* In Excel, if horizontal alignment is not specified,* rotated text aligns to the right when rotated downwards and aligns to the left when rotated upwards.*/- if (horizontalAlign === HorizontalAlign.UNSPECIFIED && angle > 0) {- offsetLeft = this.width - pageWidth - pagePaddingRight;+ if (horizontalAlign === HorizontalAlign.UNSPECIFIED) {+ if (angle > 0) {+ return this.width - pageWidth - pagePaddingRight;+ }++ /**+ * sheet cell type, In a spreadsheet cell, without any alignment settings applied,+ * text should be left-aligned,+ * numbers should be right-aligned,+ * and Boolean values should be center-aligned.+ */+ if (cellValueType === CellValueType.NUMBER) {+ offsetLeft = this.width - pageWidth - pagePaddingRight;+ } else if (cellValueType === CellValueType.BOOLEAN) {+ offsetLeft = (this.width - pageWidth) / 2;+ } else {+ offsetLeft = pagePaddingLeft;+ }} else {offsetLeft = pagePaddingLeft;}diff --git a/packages/engine-render/src/components/sheets/sheet-skeleton.ts b/packages/engine-render/src/components/sheets/sheet-skeleton.tsindex b4dd150e2d..f0d4d4632f 100644--- a/packages/engine-render/src/components/sheets/sheet-skeleton.ts+++ b/packages/engine-render/src/components/sheets/sheet-skeleton.ts@@ -158,6 +158,8 @@ interface ICellOtherConfig {* padding*/paddingData?: IPaddingData;++ cellValueType?: CellValueType;}interface IRowColumnSegment {@@ -1073,6 +1075,7 @@ export class SpreadsheetSkeleton extends Skeleton {documentModel = this._getDocumentDataByStyle(cell.v.toString(), textStyle, {...cellOtherConfig,textRotation,+ cellValueType: cell.t!,});}@@ -1731,6 +1734,7 @@ export class SpreadsheetSkeleton extends Skeleton {horizontalAlign = HorizontalAlign.UNSPECIFIED,verticalAlign = VerticalAlign.UNSPECIFIED,wrapStrategy = WrapStrategy.UNSPECIFIED,+ cellValueType,} = config;const { a: angle = 0, v: isVertical = BooleanNumber.FALSE } = textRotation;@@ -1777,6 +1781,7 @@ export class SpreadsheetSkeleton extends Skeleton {centerAngle,vertexAngle,wrapStrategy,+ cellValueType,},},};