/** * 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 { ITableFilterItem, ITableInfo, ITableInfoWithUnitId, ITableOptions, ITableRange } from '@univerjs/sheets-table'; import { FWorkbook } from '@univerjs/sheets/facade'; /** * @ignore */ export interface IFWorkbookSheetsTableMixin { /** * Get table information * @param {string} tableId The table id * @returns {ITableInfoWithUnitId | undefined} The table information, including workbook and worksheet IDs, or `undefined` if not found. * @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) { * const tableInfo = fWorkbook.getTableInfo('id-1'); * console.log('debugger tableInfo', tableInfo); * } * ``` */ getTableInfo(tableId: string): ITableInfoWithUnitId | undefined; /** * Get table information by name * @param {string} tableName The table name * @returns {ITableInfoWithUnitId | undefined} The table information, including workbook and worksheet IDs, or `undefined` if not found. * @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) { * const tableInfo = fWorkbook.getTableInfoByName('name-1'); * console.log('debugger tableInfo', tableInfo); * } * ``` */ getTableInfoByName(tableName: string): ITableInfoWithUnitId | undefined; /** * Get table list * @returns {ITableInfo[]} The table list * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const tables = fWorkbook.getTableList(); * console.log('debugger tables', tables); * ``` */ getTableList(): ITableInfo[]; /** * Add table * @param {string} subUnitId The sub unit id * @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} A promise resolving to the table ID, or `undefined` if the name is invalid or creation fails. * @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 id = await fWorkbook.addTable( * fWorksheet.getSheetId(), * 'name-1', * fRange.getRange(), * 'id-1', * { * tableStyleId: 'table-default-4', * } * ); * * if (id) { * const tableInfo = fWorkbook.getTableInfo(id); * console.log('debugger tableInfo', tableInfo); * } * ``` */ addTable(subUnitId: string, tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise; /** * set table filter * @param {string} tableId The table id * @param {number} column The column index, starting from 0. * @param {ITableFilterItem | undefined} filter The filter to apply, or `undefined` to clear the column filter. * @returns {Promise} The result of set table filter * @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 fWorkbook.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 | undefined): Promise; /** * Remove table * @param {string} tableId The table id * @returns {Promise} A promise resolving to whether the table was removed; `false` if the table is not found. * @example * ```typescript * const fWorkbook = univerAPI.getActiveWorkbook(); * const tableInfo = fWorkbook.getTableInfo('id-1'); * console.log('debugger tableInfo', tableInfo); * * if (tableInfo) { * // Remove the table with the specified id * await fWorkbook.removeTable('id-1'); * } * ``` */ removeTable(tableId: string): Promise; } export declare class FWorkbookSheetsTableMixin extends FWorkbook implements IFWorkbookSheetsTableMixin { getTableInfo(tableId: string): ITableInfoWithUnitId | undefined; getTableList(): ITableInfoWithUnitId[]; addTable(subUnitId: string, tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise; removeTable(tableId: string): Promise; getTableInfoByName(tableName: string): ITableInfoWithUnitId | undefined; setTableFilter(tableId: string, column: number, filter: ITableFilterItem | undefined): Promise; } declare module '@univerjs/sheets/facade' { interface FWorkbook extends IFWorkbookSheetsTableMixin { } }