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 | テキスト範囲のフォント属性を表す |
| hyperlinks | この |
| length | この |
| paragraph |
テキスト範囲の段落形式を表します。 詳細については 、「PowerPoint.ParagraphFormat 」を参照してください。 |
| start | この |
| text | テキスト範囲のプレーン テキスト コンテンツを表します。 |
メソッド
| get |
この |
| get |
指定した範囲内の部分文字列の |
| load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| set |
指定したオプションを使用して、この |
| set |
現在のビューでこの |
| toJSON() | API オブジェクトが |
プロパティの詳細
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();
});
hyperlinks
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
この TextRangeに存在するハイパーリンクのコレクションを返します。
readonly hyperlinks: PowerPoint.HyperlinkScopedCollection;
プロパティ値
注釈
length
この TextRange が表す範囲の長さを取得または設定します。 負の値を設定した場合、または値が開始点から使用可能なテキストの長さより大きい場合は、 InvalidArgument 例外をスローします。
length: number;
プロパティ値
number
注釈
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");
await context.sync();
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}`);
});
start
この TextRange が表す範囲の開始位置の親テキスト フレームを基準にした 0 から始まるインデックスを取得または設定します。 負の値で設定した場合、または値がテキストの長さより大きい場合は、 InvalidArgument 例外をスローします。
start: number;
プロパティ値
number
注釈
text
メソッドの詳細
getParentTextFrame()
このTextRangeを保持する親PowerPoint.TextFrame オブジェクトを返します。
getParentTextFrame(): PowerPoint.TextFrame;
戻り値
注釈
getSubstring(start, length)
指定した範囲内の部分文字列の TextRange オブジェクトを返します。
getSubstring(start: number, length?: number): PowerPoint.TextRange;
パラメーター
- start
-
number
テキスト範囲から取得する最初の文字の 0 から始まるインデックス。
- length
-
number
省略可能。 新しいテキスト範囲で返される文字数。 length を省略すると、テキスト範囲の最後の段落の先頭から末尾までのすべての文字が返されます。
戻り値
注釈
load(options)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(options?: PowerPoint.Interfaces.TextRangeLoadOptions): PowerPoint.TextRange;
パラメーター
読み込むオブジェクトのプロパティのオプションを提供します。
戻り値
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 は読み込むナビゲーション プロパティを指定するコンマ区切りの文字列です。
戻り値
setHyperlink(options)
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
指定したオプションを使用して、この TextRange のハイパーリンクを設定します。 これにより、この TextRange上のすべての既存のハイパーリンクが削除されます。
setHyperlink(options?: PowerPoint.HyperlinkAddOptions): PowerPoint.Hyperlink;
パラメーター
- options
- PowerPoint.HyperlinkAddOptions
省略可能。 ハイパーリンクのオプション。
戻り値
新しく作成された PowerPoint.Hyperlink オブジェクト。
注釈
setSelected()
現在のビューでこの TextRange を選択します。
setSelected(): void;
戻り値
void
注釈
[ API セット: PowerPointApi 1.5 ]
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml
// Selects the first 10 characters of the selected shape.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
await context.sync();
if (shapeCount.value !== 1) {
console.warn("You must select only one shape with text in it.");
return;
}
const shape: PowerPoint.Shape = shapes.getItemAt(0);
const textFrame: PowerPoint.TextFrame = shape.textFrame.load("textRange,hasText");
await context.sync();
if (textFrame.hasText != true) {
console.warn("You must select only one shape with text in it.");
return;
}
const textRange: PowerPoint.TextRange = textFrame.textRange;
textRange.load("text");
await context.sync();
if (textRange.text.length < 10) {
console.warn("You must select only one shape with at least 10 characters in it.");
return;
}
const textRange10 = textRange.getSubstring(0, 10);
textRange10.setSelected();
await context.sync();
});
...
// Sets the range selection to the range that was saved previously.
await PowerPoint.run(async (context) => {
const slide1: PowerPoint.Slide = context.presentation.slides.getItem(savedTextSlideSelection[0]);
const shape1: PowerPoint.Shape = slide1.shapes.getItem(savedTextShapeSelection[0]);
const textRange: PowerPoint.TextRange = shape1.textFrame.textRange.getSubstring(
savedTextTextRangeStart,
savedTextTextRangeLength,
);
textRange.setSelected();
await context.sync();
});
toJSON()
API オブジェクトがJSON.stringify()に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (JSON.stringify、それに渡されるオブジェクトの toJSON メソッドを呼び出します)。元の PowerPoint.TextRange オブジェクトは API オブジェクトですが、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( PowerPoint.Interfaces.TextRangeData として型指定) を返します。
toJSON(): PowerPoint.Interfaces.TextRangeData;