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(formula): add getStyleByCell for formula get style from cell or styles
Dushusir84d12d74668f
diff --git a/packages/base-render/src/Component/Sheets/SheetSkeleton.ts b/packages/base-render/src/Component/Sheets/SheetSkeleton.tsindex a9d6729fbc..e4dd0ae5e1 100644--- a/packages/base-render/src/Component/Sheets/SheetSkeleton.ts+++ b/packages/base-render/src/Component/Sheets/SheetSkeleton.ts@@ -29,7 +29,6 @@ import {Nullable,getColorStyle,IDocumentRenderConfig,- getStyle,} from '@univer/core';import { BORDER_TYPE, COLOR_BLACK_RGB } from '../../Basics/Const';import { IStylesCache, BorderCache } from './Interfaces';@@ -664,7 +663,8 @@ export class SpreadsheetSkeleton extends Skeleton {// style supports inline styles// const style = styles && styles.get(cell.s);- const style = getStyle(styles, cell);+ // const style = getStyle(styles, cell);+ const style = styles && styles.getStyleByCell(cell);if (!skipBackgroundAndBorder && style && style.bg && style.bg.rgb) {const rgb = style.bg.rgb;diff --git a/packages/core/src/Shared/Common.ts b/packages/core/src/Shared/Common.tsindex f6c9f39177..81b2d1c8b2 100644--- a/packages/core/src/Shared/Common.ts+++ b/packages/core/src/Shared/Common.ts@@ -1,14 +1,7 @@import { Tools } from './Tools';import { Nullable } from '.';-import {- ICellInfo,- ISelection,- ICellData,- IColorStyle,- IStyleData,-} from '../Interfaces';-import { ColorBuilder, Styles } from '../Sheets/Domain';-import { DEFAULT_STYLES } from '../Const';+import { ICellInfo, ISelection, ICellData, IColorStyle } from '../Interfaces';+import { ColorBuilder } from '../Sheets/Domain';export function makeCellToSelection(cellInfo: Nullable<ICellInfo>@@ -86,16 +79,19 @@ export function isFormulaString(value: any): boolean {return Tools.isString(value) && value.indexOf('=') === 0 && value.length > 1;}-export function getStyle(- styles: Nullable<Styles>,- cell: Nullable<ICellData>-): IStyleData {- let style;- if (cell && Tools.isObject(cell.s)) {- style = cell.s as IStyleData;- } else {- style = cell?.s && styles?.get(cell.s);- }+/**+ * move to Styles.getStyleByCell+ */+// export function getStyle(+// styles: Nullable<Styles>,+// cell: Nullable<ICellData>+// ): Nullable<IStyleData> {+// let style;+// if (cell && Tools.isObject(cell.s)) {+// style = cell.s as IStyleData;+// } else {+// style = cell?.s && styles?.get(cell.s);+// }- return style || DEFAULT_STYLES;-}+// return style as IStyleData;+// }diff --git a/packages/core/src/Sheets/Domain/Range.ts b/packages/core/src/Sheets/Domain/Range.tsindex 6b09f5ed65..daae0cfb40 100644--- a/packages/core/src/Sheets/Domain/Range.ts+++ b/packages/core/src/Sheets/Domain/Range.ts@@ -45,7 +45,6 @@ import {ITextDecoration,} from '../../Interfaces';import {- getStyle,Nullable,ObjectArrayPrimitiveType,ObjectMatrix,@@ -455,8 +454,9 @@ export class Range {row.map((cell: Nullable<ICellData>) => {const styles = this._context.getWorkBook().getStyles();- const style = getStyle(styles, cell);- return style[arg];+ // const style = getStyle(styles, cell);+ const style = styles && styles.getStyleByCell(cell);+ return (style && style[arg]) || DEFAULT_STYLES[arg];}));}diff --git a/packages/core/src/Sheets/Domain/Styles.ts b/packages/core/src/Sheets/Domain/Styles.tsindex 41fbf6cdd1..e237918851 100644--- a/packages/core/src/Sheets/Domain/Styles.ts+++ b/packages/core/src/Sheets/Domain/Styles.ts@@ -1,5 +1,5 @@import { nanoid } from 'nanoid';-import { IStyleData } from '../../Interfaces';+import { ICellData, IStyleData } from '../../Interfaces';import { IKeyType, Nullable, Tools } from '../../Shared';/**@@ -58,4 +58,15 @@ export class Styles {toJSON(): IKeyType<Nullable<IStyleData>> {return this._styles;}++ getStyleByCell(cell: Nullable<ICellData>): Nullable<IStyleData> {+ let style;+ if (cell && Tools.isObject(cell.s)) {+ style = cell.s as IStyleData;+ } else {+ style = cell?.s && this.get(cell.s);+ }++ return style as IStyleData;+ }}