Skip to content

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.

fix(render): fix true and false render (#5626)

wpxp123456e5b2181e7e6a
diff --git a/packages/engine-render/src/components/sheets/extensions/font.ts b/packages/engine-render/src/components/sheets/extensions/font.ts
index 57e2b313ba..d523b968af 100644
--- a/packages/engine-render/src/components/sheets/extensions/font.ts
+++ b/packages/engine-render/src/components/sheets/extensions/font.ts
@@ -510,11 +510,23 @@ export class Font extends SheetExtension {
cellWidth = endX - startX - paddingLeft - paddingRight;
}
+ // If the horizontal alignment is not specified, we need to determine it based on the cell value type.
+ let hAlign = fontCache.horizontalAlign;
+ if (fontCache.horizontalAlign === HorizontalAlign.UNSPECIFIED) {
+ if (cellData.t === CellValueType.NUMBER) {
+ // If the cell value is a number, default to right alignment.
+ hAlign = HorizontalAlign.RIGHT;
+ } else if (cellData.t === CellValueType.BOOLEAN) {
+ // If the cell value is a boolean, default to center alignment.
+ hAlign = HorizontalAlign.CENTER;
+ }
+ }
+
Text.drawWith(ctx, {
text,
fontStyle: fontCache.fontString,
warp: wrapStrategy === WrapStrategy.WRAP && vertexAngle === 0,
- hAlign: (cellData.t === CellValueType.NUMBER && fontCache.horizontalAlign === HorizontalAlign.UNSPECIFIED) ? HorizontalAlign.RIGHT : fontCache.horizontalAlign,
+ hAlign,
vAlign: fontCache.verticalAlign,
width: cellWidth,
height: cellHeight,