/** * Copyright 2023-present DreamNum Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type { IRangeThemeStyleJSON } from '@univerjs/sheets'; import type { ITableFilterButtonConfig, ITableFilterItem, ITableInfoWithUnitId, ITableOptions, ITableRange } from '@univerjs/sheets-table'; import { FWorksheet } from '@univerjs/sheets/facade'; /** * @ignore */ export interface IFWorksheetTableMixin { /** * Apply a formula to every data row of a table column, excluding header and footer. * References are relative to the first data row. Empty string stops future auto-fill and preserves cells. * @param tableId Table ID in this worksheet. * @param columnId Stable column ID from getSubTableInfos(). * @param formula Formula to apply, or an empty string to stop automatic filling. * @returns Whether the undoable update succeeded synchronously. */ setTableColumnFormula(tableId: string, columnId: string, formula: string): boolean; /** * Update table filter button visibility without clearing filter criteria. * Column overrides use stable column IDs from getSubTableInfos(). * @param tableId Table ID in this worksheet. * @param config Partial table and column button visibility settings. * @returns Whether the update succeeded synchronously. */ setTableFilterButtons(tableId: string, config: ITableFilterButtonConfig): boolean; /** * Add a table to the worksheet * @param {string} tableName The table name * @param {ITableRange} rangeInfo The table range information * @param {string} [tableId] The table id * @param {ITableOptions} [options] The table options * @returns {Promise | boolean} `false` for an invalid table name; otherwise, a promise resolving to whether the command succeeded. * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Insert a table in the range B2:F11 * const fRange = fWorksheet.getRange('B2:F11'); * const success = await fWorksheet.addTable( * 'name-1', * fRange.getRange(), * 'id-1', * { * tableStyleId: 'table-default-4', * columns: [ * { id: 'col-1', displayName: 'Column 1' } * ], * filters: [ * { * filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition, * filterInfo: { * conditionType: univerAPI.Enum.TableConditionTypeEnum.Number, * compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan, * expectedValue: 2, * } * } * ] * } * ); * * if (success) { * const tableInfo = fWorkbook.getTableInfo('id-1'); * console.log('debugger tableInfo', tableInfo); * } * ``` */ addTable(tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise | boolean; /** * Set the filter for a table column * @param {string} tableId The table id * @param {number} column The table column index, starting from 0. For example, the first column is 0, the second column is 1, and so on. * @param {ITableFilterItem} filter The filter item * @returns {Promise} Whether the table filter was set successfully * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Insert a table in the range B2:F11 * const fRange = fWorksheet.getRange('B2:F11'); * const success = await fWorksheet.addTable( * 'name-1', * fRange.getRange(), * 'id-1', * { * tableStyleId: 'table-default-4', * } * ); * * if (success) { * // Set the filter for the second column * await fWorksheet.setTableFilter('id-1', 1, { * filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition, * filterInfo: { * conditionType: univerAPI.Enum.TableConditionTypeEnum.Number, * compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan, * expectedValue: 10, * }, * }); * * const tableInfo = fWorkbook.getTableInfo('id-1'); * console.log('debugger tableInfo', tableInfo); * } * ``` */ setTableFilter(tableId: string, column: number, filter: ITableFilterItem): Promise; /** * Remove a table from the worksheet * @param {string} tableId The table id * @returns {Promise} Whether the table was removed successfully * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * const tableInfo = fWorkbook.getTableInfo('id-1'); * console.log('debugger tableInfo', tableInfo); * * if (tableInfo) { * // Remove the table with the specified id * await fWorksheet.removeTable('id-1'); * } * ``` */ removeTable(tableId: string): Promise; /** * Set the range of a table * @param {string} tableId The table id * @param {ITableRange} rangeInfo The new range information * @returns {Promise} Whether the table range was set successfully * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Insert a table in the range B2:F11 * const fRange = fWorksheet.getRange('B2:F11'); * const success = await fWorksheet.addTable( * 'name-1', * fRange.getRange(), * 'id-1', * { * tableStyleId: 'table-default-4', * } * ); * * if (success) { * // Update the table range to B2:F21 after 3 seconds * setTimeout(async () => { * const newRange = fWorksheet.getRange('B2:F21'); * await fWorksheet.setTableRange('id-1', newRange.getRange()); * * const tableInfo = fWorkbook.getTableInfo('id-1'); * console.log('debugger tableInfo', tableInfo); * }, 3000); * } * ``` */ setTableRange(tableId: string, rangeInfo: ITableRange): Promise; /** * Set the name of a table * @param {string} tableId The table id * @param {string} tableName The new table name * @returns {Promise | boolean} `false` for an invalid table name; otherwise, a promise resolving to whether the command succeeded. * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Insert a table in the range B2:F11 * const fRange = fWorksheet.getRange('B2:F11'); * const success = await fWorksheet.addTable( * 'name-1', * fRange.getRange(), * 'id-1', * { * tableStyleId: 'table-default-4', * } * ); * * if (success) { * // Update the table name after 3 seconds * setTimeout(async () => { * await fWorksheet.setTableName('id-1', 'new-name'); * * const tableInfo = fWorkbook.getTableInfo('id-1'); * console.log('debugger tableInfo', tableInfo); * }, 3000); * } * ``` */ setTableName(tableId: string, tableName: string): Promise | boolean; /** * Get the list of tables in the worksheet * @returns {ITableInfoWithUnitId[]} The list of tables * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * const tables = fWorksheet.getSubTableInfos(); * console.log('debugger tables', tables); * ``` */ getSubTableInfos(): ITableInfoWithUnitId[]; /** * Reset the column filter of a table * @param {string} tableId The table id * @param {number} column The column index, starting from 0. For example, the first column is 0, the second column is 1, and so on. * @returns {Promise} Whether the table filter was reset successfully * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Insert a table in the range B2:F11 * const fRange = fWorksheet.getRange('B2:F11'); * const success = await fWorksheet.addTable( * 'name-1', * fRange.getRange(), * 'id-1', * { * tableStyleId: 'table-default-4', * } * ); * * if (success) { * // Set the filter for the second column * await fWorksheet.setTableFilter('id-1', 1, { * filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition, * filterInfo: { * conditionType: univerAPI.Enum.TableConditionTypeEnum.Number, * compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan, * expectedValue: 10, * }, * }); * * // Reset the filter for the second column after 3 seconds * setTimeout(async () => { * await fWorksheet.resetFilter('id-1', 1); * }, 3000); * * const tableInfo = fWorkbook.getTableInfo('id-1'); * console.log('debugger tableInfo', tableInfo); * } * ``` */ resetFilter(tableId: string, column: number): Promise; /** * Get the table information by cell position * @param {number} row The cell row index, starting from 0. * @param {number} column The cell column index, starting from 0. * @returns {ITableInfoWithUnitId | undefined} The table information or undefined if not found * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * const cellB2 = fWorksheet.getRange('B2'); * const row = cellB2.getRow(); * const column = cellB2.getColumn(); * console.log('debugger tableInfo', fWorksheet.getTableByCell(row, column)); * * // Insert a table in the range B2:F11 * const fRange = fWorksheet.getRange('B2:F11'); * const success = await fWorksheet.addTable( * 'name-1', * fRange.getRange(), * 'id-1', * { * tableStyleId: 'table-default-4', * } * ); * console.log('debugger tableInfo2', fWorksheet.getTableByCell(row, column)); * ``` */ getTableByCell(row: number, column: number): ITableInfoWithUnitId | undefined; /** * Add a theme to the table * @param {string} tableId The table id * @param {IRangeThemeStyleJSON} themeStyleJSON The theme style JSON * @returns {Promise} Whether the theme was added successfully * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Insert a table in the range B2:F11 * const fRange = fWorksheet.getRange('B2:F11'); * const success = await fWorksheet.addTable( * 'name-1', * fRange.getRange(), * 'id-1', * { * tableStyleId: 'table-default-4', * } * ); * * if (success) { * await fWorksheet.addTableTheme('id-1', { * name: 'table-custom-1', * headerRowStyle: { * bg: { * rgb: '#145f82', * }, * }, * firstRowStyle: { * bg: { * rgb: '#c0e4f5', * }, * }, * }); * * const tableInfo = fWorkbook.getTableInfo('id-1'); * console.log('debugger tableInfo', tableInfo); * } * ``` */ addTableTheme(tableId: string, themeStyleJSON: IRangeThemeStyleJSON): Promise; } export declare class FWorksheetTableMixin extends FWorksheet implements IFWorksheetTableMixin { setTableColumnFormula(tableId: string, columnId: string, formula: string): boolean; setTableFilterButtons(tableId: string, config: ITableFilterButtonConfig): boolean; addTable(tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise | boolean; setTableFilter(tableId: string, column: number, filter: ITableFilterItem): Promise; removeTable(tableId: string): Promise; setTableRange(tableId: string, rangeInfo: ITableRange): Promise; setTableName(tableId: string, tableName: string): Promise | boolean; getSubTableInfos(): ITableInfoWithUnitId[]; resetFilter(tableId: string, column: number): Promise; getTableByCell(row: number, column: number): ITableInfoWithUnitId | undefined; addTableTheme(tableId: string, themeStyleJSON: IRangeThemeStyleJSON): Promise; } declare module '@univerjs/sheets/facade' { interface FWorksheet extends IFWorksheetTableMixin { } }