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(statusbar): fix status bar can not read date type cell (#4573)
VicKun0a0aafe599f0
diff --git a/packages-experimental/sheets-source-binding/src/model/source-model.ts b/packages-experimental/sheets-source-binding/src/model/source-model.tsindex bdae7548b0..83518524e4 100644--- a/packages-experimental/sheets-source-binding/src/model/source-model.ts+++ b/packages-experimental/sheets-source-binding/src/model/source-model.ts@@ -124,16 +124,28 @@ export class ListSourceModel extends SourceModelBase {}if (node.isDate === true) {+ const formatter = node.formatter || 'yyyy-m-d am/pm h:mm';return {v: transformDate(data),s: {n: {- pattern: 'yyyy-m-d am/pm h:mm',+ pattern: formatter,},},t: CellValueType.NUMBER,};} else {+ if (node.formatter) {+ return {+ v: data,+ s: {+ n: {+ pattern: node.formatter,+ },+ },+ };+ }+return {t: typeof data === 'number' ? CellValueType.NUMBER : CellValueType.STRING,v: data,@@ -177,16 +189,27 @@ export class ObjectSourceModel extends SourceModelBase {}}if (node.isDate === true) {+ const formatter = node.formatter || 'yyyy-m-d am/pm h:mm';return {v: transformDate(data),s: {n: {- pattern: 'yyyy-m-d am/pm h:mm',+ pattern: formatter,},},t: CellValueType.NUMBER,};} else {+ if (node.formatter) {+ return {+ v: data,+ s: {+ n: {+ pattern: node.formatter,+ },+ },+ };+ }return {v: data,t: typeof data === 'number' ? CellValueType.NUMBER : CellValueType.STRING,diff --git a/packages-experimental/sheets-source-binding/src/types.ts b/packages-experimental/sheets-source-binding/src/types.tsindex 5990b3d47e..f90fd224ad 100644--- a/packages-experimental/sheets-source-binding/src/types.ts+++ b/packages-experimental/sheets-source-binding/src/types.ts@@ -105,6 +105,11 @@ export interface ICellBindingNodeParam {*/isDate?: boolean;nodeId?: string; // optional in ICellBindingNodeParam++ /**+ * The formatter of the binding node, the formatter will be applied to the binding value.+ */+ formatter?: string;}export interface ICellBindingNode extends ICellBindingNodeParam {diff --git a/packages/sheets-ui/src/controllers/status-bar.controller.ts b/packages/sheets-ui/src/controllers/status-bar.controller.tsindex 90a68e1fde..7965b94499 100644--- a/packages/sheets-ui/src/controllers/status-bar.controller.ts+++ b/packages/sheets-ui/src/controllers/status-bar.controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, ICommandInfo, IRange, ISelectionCell, Nullable, Workbook, Worksheet } from '@univerjs/core';+import type { ICellData, ICommandInfo, IRange, ISelectionCell, Nullable, Styles, Workbook, Worksheet } from '@univerjs/core';import type { ArrayValueObject, ISheetData } from '@univerjs/engine-formula';import type { ISelectionWithStyle } from '@univerjs/sheets';import type { IStatusBarServiceStatus } from '../services/status-bar.service';@@ -27,6 +27,7 @@ import {Inject,InterceptorManager,IUniverInstanceService,+ numfmt,ObjectMatrix,RANGE_TYPE,splitIntoGrid,@@ -54,7 +55,7 @@ class CalculateValueSet {private _min: number = Number.POSITIVE_INFINITY;private _max: number = Number.NEGATIVE_INFINITY;- add(value: Nullable<ICellData>) {+ add(value: Nullable<ICellData>, styles: Styles, patternInfoRecord: Record<string, any>) {const v = value?.v;const t = value?.t;if (v !== undefined && v !== null) {@@ -63,7 +64,26 @@ class CalculateValueSet {this._countNumber++;this._min = Math.min(this._min, v);this._max = Math.max(this._max, v);+ } else if (t === CellValueType.NUMBER && value?.s) {+ const style = styles.get(value.s);+ if (style && t === CellValueType.NUMBER && style.n) {+ const { pattern } = style.n;+ if (!patternInfoRecord[pattern]) {+ patternInfoRecord[pattern] = numfmt.getInfo(pattern);+ }+ const formatInfo = patternInfoRecord[pattern];+ const isDate = formatInfo.isDate;++ if (isDate) {+ const dateValue = numfmt.parseDate(v as string).v as number;+ this._sum += Number(dateValue);+ this._countNumber++;+ this._min = Math.min(this._min, Number(dateValue));+ this._max = Math.max(this._max, Number(dateValue));+ }+ }}+this._count++;}}@@ -261,12 +281,15 @@ export class StatusBarController extends Disposable {const noDuplicate = splitIntoGrid(realSelections);// const matrix = sheet.getCellMatrix();const calculateValueSet = new CalculateValueSet();+ const styles = workbook.getStyles();+ const patternInfoRecord: Record<string, any> = {};+for (const range of noDuplicate) {const { startRow, startColumn, endColumn, endRow } = this.getRangeStartEndInfo(range, sheet);for (let r = startRow; r <= endRow; r++) {for (let c = startColumn; c <= endColumn; c++) {const value = sheet.getCell(r, c);- calculateValueSet.add(value);+ calculateValueSet.add(value, styles, patternInfoRecord);}}}