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-table): return undefined for empty cell values & fix i18n (#5649)
白熱48aea112d621
diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.tsindex b112b42c21..e732762c7f 100644--- a/examples/src/sheets/main.ts+++ b/examples/src/sheets/main.ts@@ -21,6 +21,7 @@ import { UniverDocsPlugin } from '@univerjs/docs';import { UniverDocsUIPlugin } from '@univerjs/docs-ui';import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';import { UniverRenderEnginePlugin } from '@univerjs/engine-render';+import { DEFAULT_WORKBOOK_DATA_DEMO } from '@univerjs/mockdata';import zhCN from '@univerjs/mockdata/locales/zh-CN';import { UniverNetworkPlugin } from '@univerjs/network';import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';@@ -143,53 +144,7 @@ function createNewInstance() {// create univer sheet instanceif (!IS_E2E) {- univer.createUnit(UniverInstanceType.UNIVER_SHEET, {- id: 'fbpG8l',- sheetOrder: [- 'xeyZKmZIRXwhSzwbec9-c',- ],- sheets: {- 'xeyZKmZIRXwhSzwbec9-c': {- id: 'xeyZKmZIRXwhSzwbec9-c',- name: 'Sheet1',- tabColor: '',- hidden: 0,- rowCount: 1000,- columnCount: 20,- zoomRatio: 1,- freeze: {- xSplit: 0,- ySplit: 0,- startRow: -1,- startColumn: -1,- },- scrollTop: 0,- scrollLeft: 0,- defaultColumnWidth: 88,- defaultRowHeight: 24,- mergeData: [],- cellData: {},- rowData: {},- columnData: {},- showGridlines: 1,- rowHeader: {- width: 46,- hidden: 0,- },- columnHeader: {- height: 20,- hidden: 0,- },- rightToLeft: 0,- },- },- resources: [- {- name: 'SHEET_DATA_VALIDATION_PLUGIN',- data: '{"xeyZKmZIRXwhSzwbec9-c":[{"uid":"VvFh9x","type":"date","operator":"greaterThan","formula1":"2020-11-11","ranges":[{"startRow":0,"startColumn":0,"endRow":0,"endColumn":0,"rangeType":0}],"formula2":""},{"uid":"K2P_rg","type":"date","operator":"greaterThanOrEqual","formula1":"2025-11-12","ranges":[{"startRow":0,"startColumn":1,"endRow":0,"endColumn":1,"rangeType":0,"unitId":"fbpG8l","sheetId":"xeyZKmZIRXwhSzwbec9-c"}],"formula2":"","bizInfo":{"showTime":true}}]}',- },- ],- });+ univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);}setTimeout(() => {diff --git a/packages/sheets-table-ui/src/services/sheets-table-ui-service.ts b/packages/sheets-table-ui/src/services/sheets-table-ui-service.tsindex 73907d899d..f160d04faa 100644--- a/packages/sheets-table-ui/src/services/sheets-table-ui-service.ts+++ b/packages/sheets-table-ui/src/services/sheets-table-ui-service.ts@@ -18,7 +18,7 @@ import type { Workbook } from '@univerjs/core';import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';import type { ISetSheetTableParams, ITableFilterItem } from '@univerjs/sheets-table';import type { IFilterByValueWithTreeItem, ITableFilterItemList } from '../types';-import { cellToRange, Disposable, ICommandService, Inject, IUniverInstanceService, ObjectMatrix, Rectangle } from '@univerjs/core';+import { cellToRange, Disposable, ICommandService, Inject, IUniverInstanceService, LocaleService, ObjectMatrix, Rectangle } from '@univerjs/core';import { SetRangeValuesMutation } from '@univerjs/sheets';import { isConditionFilter, isManualFilter, SetSheetTableFilterCommand, SheetTableService, TableManager } from '@univerjs/sheets-table';import { FilterByEnum } from '../types';@@ -38,7 +38,8 @@ export class SheetsTableUiService extends Disposable {@Inject(TableManager) private _tableManager: TableManager,@Inject(SheetTableService) private _sheetTableService: SheetTableService,@Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService,- @ICommandService private readonly _commandService: ICommandService+ @ICommandService private readonly _commandService: ICommandService,+ @Inject(LocaleService) private readonly _localeService: LocaleService) {super();this._registerTableFilterChangeEvent();@@ -148,7 +149,11 @@ export class SheetsTableUiService extends Disposable {if (isFiltered) {continue;}- const stringItem = this._sheetTableService.getCellValueWithConditionType(worksheet, row, column) as string;+ let stringItem = this._sheetTableService.getCellValueWithConditionType(worksheet, row, column) as string;++ if (stringItem === undefined) {+ stringItem = this._localeService.t('sheets-table.condition.empty');+ }if (!map.has(stringItem)) {data.push({diff --git a/packages/sheets-table/src/model/filter-util/condition.ts b/packages/sheets-table/src/model/filter-util/condition.tsindex 299ed1b8b6..bf832382bf 100644--- a/packages/sheets-table/src/model/filter-util/condition.ts+++ b/packages/sheets-table/src/model/filter-util/condition.ts@@ -117,7 +117,7 @@ function getStringCellValue(sheet: Worksheet, row: number, col: number) {if (typeof v === 'boolean') return v ? 'TRUE' : 'FALSE';if (v === undefined) {- return '(空白)';+ return undefined;}return String(v);