FSlideTableBuilder
Builder for creating slide tables through the facade.
Access
Access through:
Example
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide .newTable() .setValues([ ['Quarter', 'Owner', 'Status'], ['Q1', 'Sales', 'Done'], ]) .setRows(3) .setColumns(4) .setColumnWidth(105) .setRowHeight(60) .setAbsolutePosition(80, 100) .setSize(420, 180) .build()fSlide.insertTable(tableInfo)Setup
Register @univerjs-pro/slides-table or a preset that includes it. In plugin mode, import @univerjs-pro/slides-table/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs-pro/slides-table
FSlideTableBuilder.build
Build the table info used by fSlide.insertTable().
build(): ISlideTableBuilderInfoReturns
The table resource and element data.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide .newTable() .setValues([ ['Quarter', 'Owner', 'Status'], ['Q1', 'Sales', 'Done'], ]) .setRows(3) .setColumns(4) .setColumnWidth(105) .setRowHeight(60) .setAbsolutePosition(80, 100) .setSize(420, 180) .build()fSlide.insertTable(tableInfo)Types: ISlideTableBuilderInfo
Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.element
The table element data. It is optional when building a table snapshot, but required when building a table element.
element: Partial<ISlideTableElement>Types: ISlideTableElement · Partial
Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setAbsolutePosition
Set the table position by slide coordinates.
setAbsolutePosition(left: number, top: number): thisParameters
left— Required. The x-coordinate of the table.top— Required. The y-coordinate of the table.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide.newTable().setRows(3).setColumns(4).setAbsolutePosition(80, 120).build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setCellStyles
Set style for one cell in the initial table snapshot.
setCellStyles(styles: Array<{ row: number; column: number; style: ISlideTableCellStyle; }>): thisParameters
styles— Required. An array of cell styles with their corresponding row and column indexes.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide .newTable() .setValues([ ['Name', 'Status'], ['Facade', 'Ready'], ]) .setCellStyles([{ row: 0, column: 0, style: { fill: { color: '#E8F1FF', alpha: 1 } } }]) .build()fSlide.insertTable(tableInfo)Types: Array · ISlideTableCellStyle
Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setColumns
Set the number of columns for the table. Default is 2. If the table already has values or text data, their maximum will be used as the column count instead.
setColumns(columns: number): thisParameters
columns— Required. The number of columns.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide.newTable().setRows(3).setColumns(4).build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setColumnWidth
Set default column width for all created columns.
setColumnWidth(width: number): thisParameters
width— Required. The column width.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide.newTable().setRows(3).setColumns(4).setColumnWidth(120).build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setCustom
Set custom table metadata.
setCustom(custom: Record<string, unknown> | null): thisParameters
custom— Required. The custom metadata.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide.newTable().setRows(3).setColumns(4).setCustom({ source: 'agent' }).build()fSlide.insertTable(tableInfo)Types: Record
Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setDescription
Set the table description.
setDescription(description: string): thisParameters
description— Required. The table description.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide .newTable() .setRows(3) .setColumns(4) .setDescription('Quarterly status table') .build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setName
Set the table name.
setName(name: string): thisParameters
name— Required. The table name.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide.newTable().setRows(3).setColumns(4).setName('Status table').build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setOptions
Set table style options such as first row or banded rows.
setOptions(options: ISlideTableStyleOptions): thisParameters
options— Required. The table style options.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide .newTable() .setRows(4) .setColumns(2) .setOptions({ firstRow: true, bandRow: true, }) .build()fSlide.insertTable(tableInfo)Types: ISlideTableStyleOptions
Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setPlaceholder
Set placeholder metadata on the table element.
setPlaceholder(placeholder: ISlidePlaceholderData): thisParameters
placeholder— Required. The placeholder metadata.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide .newTable() .setRows(3) .setColumns(4) .setPlaceholder({ id: 'body-1', type: univerAPI.Enum.SlidePlaceholderTypeEnum.Table, }) .build()fSlide.insertTable(tableInfo)Types: ISlidePlaceholderData
Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setRichTextValues
Sets initial table cells from values returned by univerAPI.newRichText().
setRichTextValues(values: RichTextValue[][]): thisParameters
values— Required. Two-dimensional rich-text values.
Returns
This builder for chaining.
Examples
const presentation = univerAPI.getActivePresentation()if (!presentation) throw new Error('No active presentation')const slide = presentation.getSlideByIndex(0)const richText = univerAPI .newRichText() .align({ horizontal: univerAPI.Enum.HorizontalAlign.CENTER, vertical: univerAPI.Enum.VerticalAlign.MIDDLE, }) .text('Status: ') .bold('Ready')const table = slide.insertTable( slide .newTable() .setRichTextValues([[richText]]) .build(),)if (!table) throw new Error('Cannot insert rich-text slide table')Types: RichTextValue
Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setRotation
Set the table rotation.
setRotation(rotation: number): thisParameters
rotation— Required. The rotation in degrees.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide.newTable().setRows(3).setColumns(4).setRotation(90).build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setRowHeight
Set default row height for all created rows.
setRowHeight(height: number): thisParameters
height— Required. The row height.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide.newTable().setRows(3).setColumns(4).setRowHeight(32).build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setRows
Set the number of rows for the table. Default is 2. If the table already has values or text data, their maximum will be used as the row count instead.
setRows(rows: number): thisParameters
rows— Required. The number of rows.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide.newTable().setRows(3).setColumns(4).build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setSize
Set the table size.
setSize(width: number, height: number): thisParameters
width— Required. The table width.height— Required. The table height.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide.newTable().setRows(3).setColumns(4).setSize(480, 220).build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setStyleId
Set the table theme style id. Built-in ids include:
univerPrimaryPlainGrid, univerPrimaryHeader, univerPrimaryHeaderBandedRows,
univerNeutralPlainGrid, univerGreenHeaderBandedRows, univerPurpleStrongHeader;
univer{Neutral|Primary|Blue|Cyan|Green|Orange|Purple|Pink}LightPlainGrid,
univer{Neutral|Primary|Blue|Cyan|Green|Orange|Purple|Pink}LightHeader,
univer{Neutral|Primary|Blue|Cyan|Green|Orange|Purple|Pink}LightHeaderBandedRows;
univer{Neutral|Primary|Blue|Cyan|Green|Orange|Purple|Pink}MediumStrongHeader,
univer{Neutral|Primary|Blue|Cyan|Green|Orange|Purple|Pink}MediumFirstColumn,
univer{Neutral|Primary|Blue|Cyan|Green|Orange|Purple|Pink}MediumHeaderFirstColumn;
univer{Neutral|Primary|Blue|Cyan|Green|Orange|Purple|Pink}HorizontalLines,
univerPrimarySoftGrid, and univerNeutralSoftGrid.
setStyleId(styleId: string): thisParameters
styleId— Required. The table style id.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide .newTable() .setRows(3) .setColumns(4) .setStyleId('univerGreenMediumHeaderFirstColumn') .setOptions({ firstRow: true, firstCol: true, bandRow: true, }) .build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setTextData
Set raw Univer document data for the table cells.
This is an advanced integration escape hatch. Application and agent code should prefer setRichTextValues().
setTextData(textData: IDocumentData[][]): thisParameters
textData— Required. Two-dimensional rich text document data.
Returns
This builder, for chaining.
Examples
// Advanced: preserve the exact document model while cloning imported table content.const presentation = univerAPI.getActivePresentation()if (!presentation) throw new Error('No active presentation')const slide = presentation.getSlideByIndex(0)const sourceTable = slide.getTableById('imported-table')const importedTextData = sourceTable?.getCellTextData(0, 0)if (!importedTextData) throw new Error('Imported cell data is unavailable')const tableInfo = slide .newTable() .setTextData([[importedTextData]]) .build()slide.insertTable(tableInfo)Types: IDocumentData
Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.setValues
Set plain text values for the table cells.
setValues(values: string[][]): thisParameters
values— Required. Two-dimensional plain text values.
Returns
This builder, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const tableInfo = fSlide .newTable() .setValues([ ['Name', 'Status'], ['Facade', 'Ready'], ]) .build()fSlide.insertTable(tableInfo)Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.subUnitId
readonly subUnitId: stringPackage: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.table
The table snapshot data.
table: Partial<ISlideTableSnapshot>Types: ISlideTableSnapshot · Partial
Package: @univerjs-pro/slides-table · Type definitions
FSlideTableBuilder.unitId
readonly unitId: stringPackage: @univerjs-pro/slides-table · Type definitions
你觉得这篇文档如何?