PowerPoint.TextRange class

図形に結合するテキストや、テキストを操作するためのプロパティおよびメソッドが含まれます。

Extends

注釈

API セット: PowerPointApi 1.4

使用元

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml

// Sets the color of the selected text range to green.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  textRange.font.color = "green";
  await context.sync();
});

プロパティ

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

font

テキスト範囲のフォント属性を表す ShapeFont オブジェクトを返します。

paragraphFormat

テキスト範囲の段落形式を表します。 詳細については 、「PowerPoint.ParagraphFormat 」を参照してください。

text

テキスト範囲のプレーン テキスト コンテンツを表します。

メソッド

getSubstring(start, length)

指定した範囲内の部分文字列の TextRange オブジェクトを返します。

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

toJSON()

API オブジェクトがJSON.stringify()に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (JSON.stringify、それに渡されるオブジェクトの toJSON メソッドを呼び出します)。元の PowerPoint.TextRange オブジェクトは API オブジェクトですが、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( PowerPoint.Interfaces.TextRangeData として型指定) を返します。

プロパティの詳細

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

context: RequestContext;

プロパティ値

font

テキスト範囲のフォント属性を表す ShapeFont オブジェクトを返します。

readonly font: PowerPoint.ShapeFont;

プロパティ値

注釈

API セット: PowerPointApi 1.4

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml

// Sets the color of the selected text range to green.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  textRange.font.color = "green";
  await context.sync();
});

paragraphFormat

テキスト範囲の段落形式を表します。 詳細については 、「PowerPoint.ParagraphFormat 」を参照してください。

readonly paragraphFormat: PowerPoint.ParagraphFormat;

プロパティ値

注釈

API セット: PowerPointApi 1.4

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml

// Gets navigational (complex) properties of the selected text range.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  textRange.load("font,paragraphFormat/bulletFormat,paragraphFormat/horizontalAlignment");

  const parentTextFrame: PowerPoint.TextFrame = textRange.getParentTextFrame();
  const parentShape: PowerPoint.Shape = parentTextFrame.getParentShape();
  const parentSlide: PowerPoint.Slide = parentShape.getParentSlide();
  parentShape.load("id");
  parentSlide.load("id");
  await context.sync();

  console.log(`Selected text range found in parent shape with ID ${parentShape.id} on parentSlide with ID ${parentSlide.id}`);

  console.log("Font properties of selected text range:");
  console.log(`\tallCaps: ${textRange.font.allCaps}`);
  console.log(`\tbold: ${textRange.font.bold}`);
  console.log(`\tcolor: ${textRange.font.color}`);
  console.log(`\tdoubleStrikethrough: ${textRange.font.doubleStrikethrough}`);
  console.log(`\titalic: ${textRange.font.italic}`);
  console.log(`\tname: ${textRange.font.name}`);
  console.log(`\tsize: ${textRange.font.size}`);
  console.log(`\tsmallCaps: ${textRange.font.smallCaps}`);
  console.log(`\tstrikethrough: ${textRange.font.strikethrough}`);
  console.log(`\tsubscript: ${textRange.font.subscript}`);
  console.log(`\tsuperscript: ${textRange.font.superscript}`);
  console.log(`\tunderline: ${textRange.font.underline}`);

  console.log("Paragraph format properties of selected text range:");
  console.log(`\tbulletFormat.visible: ${textRange.paragraphFormat.bulletFormat.visible}`);
  console.log(`\thorizontalAlignment: ${textRange.paragraphFormat.horizontalAlignment}`);
});

text

テキスト範囲のプレーン テキスト コンテンツを表します。

text: string;

プロパティ値

string

注釈

API セット: PowerPointApi 1.4

メソッドの詳細

getSubstring(start, length)

指定した範囲内の部分文字列の TextRange オブジェクトを返します。

getSubstring(start: number, length?: number): PowerPoint.TextRange;

パラメーター

start

number

テキスト範囲から取得する最初の文字の 0 から始まるインデックス。

length

number

省略可能。 新しいテキスト範囲で返される文字数。 length を省略すると、テキスト範囲の最後の段落の先頭から末尾までのすべての文字が返されます。

返品

注釈

API セット: PowerPointApi 1.4

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(options?: PowerPoint.Interfaces.TextRangeLoadOptions): PowerPoint.TextRange;

パラメーター

options
PowerPoint.Interfaces.TextRangeLoadOptions

読み込むオブジェクトのプロパティのオプションを提供します。

返品

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames?: string | string[]): PowerPoint.TextRange;

パラメーター

propertyNames

string | string[]

読み込むプロパティを指定するコンマ区切り文字列または文字列の配列。

返品

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): PowerPoint.TextRange;

パラメーター

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列で、 propertyNamesAndPaths.expand は読み込むナビゲーション プロパティを指定するコンマ区切りの文字列です。

返品

toJSON()

API オブジェクトがJSON.stringify()に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (JSON.stringify、それに渡されるオブジェクトの toJSON メソッドを呼び出します)。元の PowerPoint.TextRange オブジェクトは API オブジェクトですが、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( PowerPoint.Interfaces.TextRangeData として型指定) を返します。

toJSON(): PowerPoint.Interfaces.TextRangeData;

返品