import type { HorizontalAlign as HorizontalAlignType, IDocTextFill, IDocumentData, Injector, ITextStyle } from '@univerjs/core'; import type { ISlideTableElement, SlideModel } from '@univerjs-pro/slides'; import type { ISlideTableBorder, ISlideTableCell, ISlideTableCellRange, ISlideTableCellStyle, ISlideTableFill, ISlideTableSnapshot, ISlideTableStyleOptions } from '../types'; import { FPageElement } from '@univerjs-pro/slides/facade'; import { FSlideTableBuilder } from './f-slide-table-builder'; import { FSlideTableCell } from './f-slide-table-cell'; export type SlideTableBorderPreset = 'all' | 'inner' | 'outer' | 'top' | 'bottom' | 'left' | 'right' | 'none' | 'innerHorizontal' | 'innerVertical'; export interface ISlideTableInfo { id: string; elementId: string; rowCount: number; columnCount: number; name?: string; description?: string; styleId?: string; options: ISlideTableStyleOptions; } export interface ISlideTableDescription extends ISlideTableInfo { sampleRows: string[][]; columns: Array<{ index: number; width: number; }>; rows: Array<{ index: number; height?: number; }>; } export interface ISlideTableFacadeStyle { fill?: ISlideTableFill; border?: ISlideTableBorder; options?: ISlideTableStyleOptions; } /** * Facade object for a slide table element and its table resource. * * @example * ```ts * import '@univerjs-pro/slides-table/facade'; * * const fPresentation = univerAPI.getActivePresentation(); * const fSlide = fPresentation?.getActiveSlide(); * const table = fSlide?.insertTable(2, 2, { tableId: 'status-table' }); * table?.setCellText(0, 0, 'Name'); * table?.setCellText(0, 1, 'Status'); * ``` */ export declare class FSlideTable extends FPageElement { constructor(unitId: string, subUnitId: string, elementId: string, slideModel: SlideModel, injector: Injector); /** * Return the table resource id. * * @returns {string} The table resource id. * * @example * ```ts * const table = fSlide.getTables()[0]; * console.log(table?.getTableId()); * ``` */ getTableId(): string; /** * Return the raw table resource snapshot. * * @returns {ISlideTableSnapshot} The table resource snapshot. * * @example * ```ts * const table = fSlide.getTables()[0]; * console.log(table?.getTableData().rows.length); * ``` */ getTableData(): ISlideTableSnapshot; /** * Return compact table metadata. * * @returns {ISlideTableInfo} Table id, element id, size, and style metadata. * * @example * ```ts * const table = fSlide.getTables()[0]; * console.log(table?.getInfo().rowCount); * ``` */ getInfo(): ISlideTableInfo; /** * Return a human-readable table description with sample rows. * * @returns {ISlideTableDescription} The table description. * * @example * ```ts * const table = fSlide.getTables()[0]; * console.log(table?.describe().sampleRows); * ``` */ describe(): ISlideTableDescription; /** * Return the number of rows. * * @returns {number} The row count. * * @example * ```ts * const table = fSlide.getTables()[0]; * console.log(table?.getRowCount()); * ``` */ getRowCount(): number; /** * Return the number of columns. * * @returns {number} The column count. * * @example * ```ts * const table = fSlide.getTables()[0]; * console.log(table?.getColumnCount()); * ``` */ getColumnCount(): number; /** * Return a cell facade by row and column. * * @param {number} row The zero-based row index. * @param {number} column The zero-based column index. * @returns {FSlideTableCell | null} The cell facade, or `null` when it does not exist. * * @example * ```ts * const cell = table.getCell(0, 0); * console.log(cell?.getText()); * ``` */ getCell(row: number, column: number): FSlideTableCell | null; /** * Return raw cell data by row and column. * * @param {number} row The zero-based row index. * @param {number} column The zero-based column index. * @returns {ISlideTableCell | null} The cell data, or `null` when it does not exist. * * @example * ```ts * const cellData = table.getCellData(0, 0); * console.log(cellData?.rowSpan); * ``` */ getCellData(row: number, column: number): ISlideTableCell | null; /** * Return plain text in a cell. * * @param {number} row The zero-based row index. * @param {number} column The zero-based column index. * @returns {string} The cell plain text. * * @example * ```ts * console.log(table.getCellText(0, 0)); * ``` */ getCellText(row: number, column: number): string; /** * Return rich text document data in a cell. * * @param {number} row The zero-based row index. * @param {number} column The zero-based column index. * @returns {IDocumentData | undefined} The rich text document data. * * @example * ```ts * console.log(table.getCellTextData(0, 0)?.body?.dataStream); * ``` */ getCellTextData(row: number, column: number): IDocumentData | undefined; /** * Return cell style by row and column. * * @param {number} row The zero-based row index. * @param {number} column The zero-based column index. * @returns {ISlideTableCellStyle | undefined} The cell style. * * @example * ```ts * console.log(table.getCellStyle(0, 0)?.fill); * ``` */ getCellStyle(row: number, column: number): ISlideTableCellStyle | undefined; /** * Return a range covering the whole table. * * @returns {ISlideTableCellRange} The table range. * * @example * ```ts * table.setTableBackground('#F8FAFC'); * console.log(table.getTableRange()); * ``` */ getTableRange(): ISlideTableCellRange; /** * Return a one-cell range. * * @param {number} row The zero-based row index. * @param {number} column The zero-based column index. * @returns {ISlideTableCellRange} The cell range. * * @example * ```ts * table.setCellBackground(table.getCellRange(0, 0), '#E8F1FF'); * ``` */ getCellRange(row: number, column: number): ISlideTableCellRange; /** * Return a row range. * * @param {number} startRow The first row. * @param {number} [count] The number of rows. * @returns {ISlideTableCellRange} The row range. * * @example * ```ts * table.setCellBackground(table.getRowsRange(0, 1), '#F8FAFC'); * ``` */ getRowsRange(startRow: number, count?: number): ISlideTableCellRange; /** * Return a column range. * * @param {number} startColumn The first column. * @param {number} [count] The number of columns. * @returns {ISlideTableCellRange} The column range. * * @example * ```ts * table.setCellBackground(table.getColumnsRange(0, 1), '#F8FAFC'); * ``` */ getColumnsRange(startColumn: number, count?: number): ISlideTableCellRange; /** * Return a builder initialized from this table. * * @returns {FSlideTableBuilder} A table builder. * * @example * ```ts * const tableInfo = table.toBuilder() * .setPosition(80, 120) * .build(); * fSlide.insertTable(tableInfo); * ``` */ toBuilder(): FSlideTableBuilder; /** * Insert rows before a row. * * @param {number} row The row index to insert before. * @param {number} [count] The number of rows to insert. * @param {number} [height] Optional height for new rows. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.insertRowsBefore(1, 2, 32); * ``` */ insertRowsBefore(row: number, count?: number, height?: number): boolean; /** * Insert rows after a row. * * @param {number} row The row index to insert after. * @param {number} [count] The number of rows to insert. * @param {number} [height] Optional height for new rows. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.insertRowsAfter(0, 1); * ``` */ insertRowsAfter(row: number, count?: number, height?: number): boolean; /** * Append rows to the table. * * @param {number} [count] The number of rows to append. * @param {number} [height] Optional height for new rows. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.appendRows(2); * ``` */ appendRows(count?: number, height?: number): boolean; /** * Delete rows from the table. * * @param {number} startRow The first row to delete. * @param {number} [count] The number of rows to delete. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.deleteRows(1, 2); * ``` */ deleteRows(startRow: number, count?: number): boolean; /** * Insert columns before a column. * * @param {number} column The column index to insert before. * @param {number} [count] The number of columns to insert. * @param {number} [width] Optional width for new columns. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.insertColumnsBefore(1, 2, 96); * ``` */ insertColumnsBefore(column: number, count?: number, width?: number): boolean; /** * Insert columns after a column. * * @param {number} column The column index to insert after. * @param {number} [count] The number of columns to insert. * @param {number} [width] Optional width for new columns. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.insertColumnsAfter(0, 1); * ``` */ insertColumnsAfter(column: number, count?: number, width?: number): boolean; /** * Append columns to the table. * * @param {number} [count] The number of columns to append. * @param {number} [width] Optional width for new columns. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.appendColumns(2); * ``` */ appendColumns(count?: number, width?: number): boolean; /** * Delete columns from the table. * * @param {number} startColumn The first column to delete. * @param {number} [count] The number of columns to delete. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.deleteColumns(1, 2); * ``` */ deleteColumns(startColumn: number, count?: number): boolean; /** * Merge a rectangular cell range. * * @param {ISlideTableCellRange} range The range to merge. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.mergeCells({ startRow: 0, endRow: 1, startColumn: 0, endColumn: 1 }); * ``` */ mergeCells(range: ISlideTableCellRange): boolean; /** * Unmerge the merged range containing a cell. * * @param {number} row The row index. * @param {number} column The column index. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.unmergeCell(0, 0); * ``` */ unmergeCell(row: number, column: number): boolean; /** * Remove this table element and resource. * * @returns {boolean} Whether the command succeeded. * * @example * ```ts * const table = fSlide.getTables()[0]; * table?.remove(); * ``` */ remove(): boolean; /** * Replace a cell with plain text. * * @param {number} row The row index. * @param {number} column The column index. * @param {string} text The new text. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCellText(0, 0, 'Ready'); * ``` */ setCellText(row: number, column: number, text: string): boolean; /** * Replace a cell with rich text document data. * * @param {number} row The row index. * @param {number} column The column index. * @param {IDocumentData} textData The rich text document data. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * const textData = { * id: 'cell-doc', * body: { dataStream: 'Ready\r\n', paragraphs: [{ startIndex: 0 }], textRuns: [] }, * documentStyle: {}, * }; * table.setCellTextData(0, 0, textData); * ``` */ setCellTextData(row: number, column: number, textData: IDocumentData): boolean; /** * Merge style fields into a cell range. * * @param {ISlideTableCellRange} range The target range. * @param {ISlideTableCellStyle} style The style patch. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCellStyle(table.getTableRange(), { * verticalAlign: 'middle', * margins: { left: 8, right: 8 }, * }); * ``` */ setCellStyle(range: ISlideTableCellRange, style: ISlideTableCellStyle): boolean; /** * Set cell fill for a range. * * @param {ISlideTableCellRange} range The target range. * @param {ISlideTableFill | undefined} fill The fill, or `undefined` to clear it. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCellFill(table.getCellRange(0, 0), { color: '#E8F1FF', alpha: 1 }); * ``` */ setCellFill(range: ISlideTableCellRange, fill?: ISlideTableFill): boolean; /** * Set solid background color for a range. * * @param {ISlideTableCellRange} range The target range. * @param {string} color The background color. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCellBackground(table.getTableRange(), '#F8FAFC'); * ``` */ setCellBackground(range: ISlideTableCellRange, color: string): boolean; /** * Clear cell background for a range. * * @param {ISlideTableCellRange} range The target range. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.clearCellBackground(table.getTableRange()); * ``` */ clearCellBackground(range: ISlideTableCellRange): boolean; /** * Set table background color. * * @param {string} color The background color. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setTableBackground('#F8FAFC'); * ``` */ setTableBackground(color: string): boolean; /** * Apply borders to a range. * * @param {ISlideTableCellRange} range The target range. * @param {ISlideTableBorder} border The border style. * @param {SlideTableBorderPreset} [preset] Which borders to apply. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setBorder(table.getTableRange(), { color: '#111827', width: 1, dash: 'solid' }, 'outer'); * ``` */ setBorder(range: ISlideTableCellRange, border: ISlideTableBorder, preset?: SlideTableBorderPreset): boolean; /** * Apply borders to the whole table. * * @param {ISlideTableBorder} border The border style. * @param {SlideTableBorderPreset} [preset] Which borders to apply. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setTableBorder({ color: '#111827', width: 1, dash: 'solid' }, 'all'); * ``` */ setTableBorder(border: ISlideTableBorder, preset?: SlideTableBorderPreset): boolean; /** * Set horizontal text alignment for a range. * * @param {ISlideTableCellRange} range The target range. * @param {HorizontalAlignType} horizontalAlign The horizontal alignment. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCellHorizontalAlign(table.getTableRange(), univerAPI.Enum.HorizontalAlign.CENTER); * ``` */ setCellHorizontalAlign(range: ISlideTableCellRange, horizontalAlign: HorizontalAlignType): boolean; /** * Set vertical text alignment for a range. * * @param {ISlideTableCellRange} range The target range. * @param {'top' | 'middle' | 'bottom'} verticalAlign The vertical alignment. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCellVerticalAlign(table.getTableRange(), 'middle'); * ``` */ setCellVerticalAlign(range: ISlideTableCellRange, verticalAlign: NonNullable): boolean; /** * Set text direction for a range. * * @param {ISlideTableCellRange} range The target range. * @param {'horizontal' | 'vertical' | 'vertical270'} textDirection The text direction. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCellTextDirection(table.getTableRange(), 'horizontal'); * ``` */ setCellTextDirection(range: ISlideTableCellRange, textDirection: NonNullable): boolean; /** * Apply document text style to a range. * * @param {ISlideTableCellRange} range The target range. * @param {ITextStyle} textStyle The document text style patch. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCellTextStyle(table.getTableRange(), { fs: 14, bl: 1 }); * ``` */ setCellTextStyle(range: ISlideTableCellRange, textStyle: ITextStyle): boolean; /** * Set text color for a range. * * @param {ISlideTableCellRange} range The target range. * @param {string} color The text color. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCellTextColor(table.getTableRange(), '#111827'); * ``` */ setCellTextColor(range: ISlideTableCellRange, color: string): boolean; /** * Apply rich text fill to a range. * * @param {ISlideTableCellRange} range The target range. * @param {IDocTextFill | undefined} fill The rich text fill, or `undefined` to clear it. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCellTextFill(table.getTableRange(), { type: 'solid', color: '#111827', opacity: 1 }); * ``` */ setCellTextFill(range: ISlideTableCellRange, fill?: IDocTextFill): boolean; /** * Set one row's height. * * @param {number} row The row index. * @param {number} height The row height. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setRowHeight(0, 40); * ``` */ setRowHeight(row: number, height: number): boolean; /** * Set one column's width. * * @param {number} column The column index. * @param {number} width The column width. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setColumnWidth(1, 160); * ``` */ setColumnWidth(column: number, width: number): boolean; /** * Resize the table grid. * * @param {number} rows The target row count. * @param {number} columns The target column count. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.resize(5, 4); * ``` */ resize(rows: number, columns: number): boolean; /** * Distribute row heights evenly. * * @param {number} [startRow] The first row. * @param {number} [count] The number of rows. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.distributeRows(); * ``` */ distributeRows(startRow?: number, count?: number): boolean; /** * Distribute column widths evenly. * * @param {number} [startColumn] The first column. * @param {number} [count] The number of columns. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.distributeColumns(); * ``` */ distributeColumns(startColumn?: number, count?: number): boolean; /** * Set table style options. * * @param {ISlideTableStyleOptions} options The table style options. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setOptions({ firstRow: true, bandRow: true }); * ``` */ setOptions(options: ISlideTableStyleOptions): boolean; /** * Apply table-level style settings. * * @param {ISlideTableFacadeStyle} style Table style settings. * @returns {boolean} Whether every command succeeded. * * @example * ```ts * table.setTableStyle({ * fill: { color: '#F8FAFC', alpha: 1 }, * border: { color: '#111827', width: 1, dash: 'solid' }, * options: { firstRow: true }, * }); * ``` */ setTableStyle(style: ISlideTableFacadeStyle): boolean; /** * Set the table name. * * @param {string | null} name The table name, or `null` to clear it. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setTableName('Status table'); * ``` */ setTableName(name: string | null): boolean; /** * Set the table description. * * @param {string | null} description The description, or `null` to clear it. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setTableDescription('Quarterly status table'); * ``` */ setTableDescription(description: string | null): boolean; /** * Set the table style id. * * @param {string | null} styleId The style id, or `null` to clear it. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setStyleId('mediumStyle2'); * ``` */ setStyleId(styleId: string | null): boolean; /** * Set custom table metadata. * * @param {Record | null} custom Custom metadata, or `null` to clear it. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * table.setCustom({ source: 'agent' }); * ``` */ setCustom(custom: Record | null): boolean; private _getResourceService; private _getCommandService; private _execute; private _updateTable; private _updateRows; }