メインコンテンツまでスキップ

Presentation API

Presentation ドキュメントを開いた iframe には Office.show(iframe) を使用します。module 識別子は show で、製品名は Presentation です。

まず Editor SDK クイックスタートの配布ファイル・import map・HTTP サーバーの設定を完了し、 このドキュメント種類を office-frame iframe で開きます。以下の JavaScript ブロックは同じモジュールスクリプト内で順番に 使用します。書き込みの例はドキュメントを変更するため、サンプルまたはコピーで実行してください。

オブジェクトモデル​

ルートハンドルは Show.Document です。現在のカタログのオブジェクト型:Slide、Shape、Image、Line、Group、Chart、 Table、TableCell、Comment、Diagram、OleObject、Control。

すべてのハンドルメソッドは Thinkfree Office との往復通信であり、Promise を返します。

スライドと図形​

import { Office, ShapePreset } from "@thinkfree.dev/tfo-sdk";

const iframe = document.querySelector("#office-frame");
const show = Office.show(iframe);
await show.whenReady();

const doc = show.getDocument();
const slides = await doc.getSlides();
if (!slides.length) throw new Error("Open a presentation with at least one slide.");
const shape = await slides[0].insertShape(ShapePreset.RECT, { x: 100, y: 100, width: 300, height: 120 });
await shape.insertText("Quarterly update");

const added = await doc.insertSlide();
await added.appendSlideNoteText("Speaker notes");

図形プリセットなどの共通定数(ShapePreset、LineDash、ShapeZOrder、Chart*)は flat export です。Presentation 専用の 定数は Show 名前空間にあります(例:Show.ShapeType、Show.SlideLayoutType)。

図形の型の絞り込み​

findShapes() と getShapes() は図形の種類の union を返します。往復通信のない同期的な型ガードで絞り込めます。

for (const s of await slides[0].getShapes()) {
if (s.isImage()) console.log("image", await s.getSize());
else if (s.isTable()) console.log("table", await s.getRowCount());
else if (s.isShape()) console.log("shape", await s.getText());
}

図形ハンドルのガード:isShape()、isImage()、isLine()、isGroup()、isChart()、isTable()、isDiagram()、isOleObject()、isControl()。

エラー​

失敗した操作は SDKError で reject され、Thinkfree Office の構造化された応答は error.data(error.data.error.code)にあります。エラーの 一覧はドキュメントツールとエラーを参照してください。

API リファレンス​

現在の SDK ビルドの Presentation ハンドルで使用できるオブジェクト型ごとに、リファレンスページが 1 つずつあります。SDK の型定義から 生成され、メソッドの概要表に続いて、メソッドごとの TypeScript シグネチャ、パラメーター、戻り値が記載されています。すべてのメソッドは Promise を 返します。以下の表またはサイドバーからオブジェクト型を選んでください。

オブジェクト型メソッド取得方法
Show.Document50app.getDocument()
Show.Slide60Document.duplicateSlide(), Document.duplicateSlides(), Document.findSlides(), …
Show.Shape117Document.findShapes(), Slide.duplicateShape(), Slide.duplicateShapes(), …
Show.Image69Slide.insertImage(), Slide.insertWebVideo()
Show.Line70-
Show.Group34Slide.groupShapes()
Show.Chart50Document.findCharts(), Slide.findCharts()
Show.Table53Document.findTables(), Slide.findTables(), Slide.insertTable()
Show.TableCell55Table.findCells(), Table.getCell(), Table.getCells(), …
Show.Comment14Document.findComments(), Slide.findComments(), Slide.getComments(), …
Show.Diagram35-
Show.OleObject35-
Show.Control35-

定数メンバーは Show.* ページにあります。