テーブル

プラグイン情報

テーブル機能の登録

Slides のテーブル機能は、モデルパッケージと UI パッケージに分かれています:

TypeScript
import { UniverSlidesTablePlugin } from '@univerjs-pro/slides-table'import { UniverSlidesTableUIPlugin } from '@univerjs-pro/slides-table-ui'import SlidesTableUIEnUS from '@univerjs-pro/slides-table-ui/locale/en-US'import '@univerjs-pro/slides-table-ui/lib/index.css'import '@univerjs-pro/slides-table/facade'univer.registerPlugin(UniverSlidesTablePlugin)univer.registerPlugin(UniverSlidesTableUIPlugin)

モバイル対応

まずモバイルエディターを設定します。このページのプラグインモードの初期化コードで、以下のデスクトップ登録を同じパッケージのモバイル版に置き換え、文書を開く前に完了してください。モデル、スタイル、言語ファイル、Facade は維持し、両方を同時に登録しないでください。

パッケージデスクトップの登録モバイルの登録
@univerjs-pro/slides-table-uiUniverSlidesTableUIPluginUniverSlidesTableMobileUIPlugin

パッケージの役割

  • @univerjs-pro/slides-table は table element を slide model に保存し、table 操作用の facade API を提供します。
  • @univerjs-pro/slides-table-ui はブラウザー編集 UI、レンダー統合、選択動作、コンテキストメニュー操作を追加します。

Runtime の選択

ブラウザーエディターでは両方のパッケージを使用します。Node.js 処理では、ブラウザーレンダリングも必要な場合を除き、通常はモデルパッケージのみを登録します。

TypeScript
univer.registerPlugin(UniverSlidesPlugin)univer.registerPlugin(UniverSlidesTablePlugin)

table element を含む可能性がある deck を開く、またはインポートする前にテーブル機能を登録してください。登録されていない場合、runtime はそれらの要素を完全には解釈できません。

テーブル色を固定する

テーブルの挿入時またはスタイル変更時に、プラグインは現在のテーマパレットをテーブル所有のスナップショットへ解決します。そのため、グローバル Univer テーマを変更しても既存のテーブル色は維持され、別のテーブルスタイルを選ぶと新しいスナップショットが作成されます。標準の Facade 操作では自動的に管理されます。

Facade API

facade エントリをインポートすると、FSlide にテーブル関連メソッドが追加されます:

TypeScript
import '@univerjs-pro/slides-table/facade'

プレーンテキストの二次元配列からテーブルを作成します:

TypeScript
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideById('slide-1')const table = fSlide.insertTableFromData(  [    ['Quarter', 'Owner', 'Status'],    ['Q1', 'Sales', 'Done'],    ['Q2', 'Marketing', 'In progress'],  ],  {    id: 'status-table',    rowHeight: 42,    columnWidth: 160,  },)

位置とサイズを明示的に制御したい場合は table builder を使用します:

TypeScript
const tableInfo = fSlide.newTable()  .setValues([    ['Metric', 'Value'],    ['Revenue', '$120K'],  ])  .setRows(2)  .setColumns(2)  .setAbsolutePosition(80, 120)  .setSize(420, 180)  .build()const table = fSlide.insertTable(tableInfo)

テーブルセルを読み取り、更新します:

TypeScript
const table = fSlide.getTableById('status-table') ?? fSlide.getTableAt(0)if (table) {  console.log(table.describe())  console.log(table.getCellText(0, 0))  table.getCell(1, 2)?.setText('Blocked')  table.getCell(0, 0)?.setBackgroundColor('#E8F1FF')}

既存のテーブルを更新、または削除します:

TypeScript
const table = fSlide.getTableById('status-table')if (table) {  const nextTableInfo = table.toBuilder()    .setValues([      ['Quarter', 'Owner', 'Status'],      ['Q1', 'Sales', 'Done'],      ['Q2', 'Marketing', 'Blocked'],    ])    .setSize(480, 200)    .build()  fSlide.updateTable(nextTableInfo)  fSlide.removeTable(table)}

テーブルの行と列のインデックスは 0 から始まります。Builder の行数と列数は渡された値に合わせて自動的に拡張されるため、単純なテーブルでは setValues() をデータの基準として使用できます。

このガイドはいかがですか?

© 2026 DreamNum Co., Ltd.