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.Document | 50 | app.getDocument() |
Show.Slide | 60 | Document.duplicateSlide(), Document.duplicateSlides(), Document.findSlides(), … |
Show.Shape | 117 | Document.findShapes(), Slide.duplicateShape(), Slide.duplicateShapes(), … |
Show.Image | 69 | Slide.insertImage(), Slide.insertWebVideo() |
Show.Line | 70 | - |
Show.Group | 34 | Slide.groupShapes() |
Show.Chart | 50 | Document.findCharts(), Slide.findCharts() |
Show.Table | 53 | Document.findTables(), Slide.findTables(), Slide.insertTable() |
Show.TableCell | 55 | Table.findCells(), Table.getCell(), Table.getCells(), … |
Show.Comment | 14 | Document.findComments(), Slide.findComments(), Slide.getComments(), … |
Show.Diagram | 35 | - |
Show.OleObject | 35 | - |
Show.Control | 35 | - |
定数メンバーは Show.* ページにあります。