Share via


Word.Range class

文書内の連続した領域を表します。

Extends

注釈

[ API セット: WordApi 1.1 ]

プロパティ

contentControls

範囲内のコンテンツ コントロール オブジェクトのコレクションを取得します。

context

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

font

範囲のテキスト形式を取得します。 これを使用して、フォント名、サイズ、色、およびその他のプロパティを取得および設定します。

inlinePictures

範囲に含まれるインライン画像オブジェクトのコレクションを取得します。

paragraphs

範囲内の段落オブジェクトのコレクションを取得します。

parentContentControl

範囲を含む現在サポートされているコンテンツ コントロールを取得します。 ItemNotFound親コンテンツ コントロールがない場合は、エラーをスローします。

style

範囲のスタイル名を指定します。 カスタム スタイルとローカライズされたスタイルの名前には、このプロパティを使用します。 ロケール間で移植可能な組み込みスタイルを使用するには、"styleBuiltIn" プロパティを参照してください。

text

範囲のテキストを取得します。

メソッド

clear()

範囲オブジェクトの内容をクリアします。 ユーザーは、消去された内容を元に戻す操作を実行できます。

delete()

文書から範囲と、その範囲の内容を削除します。

getHtml()

範囲オブジェクトの HTML 表現を取得します。 Web ページまたは HTML ビューアーでレンダリングされた場合、書式設定は、ドキュメントの書式設定と完全に一致しませんが、近い形式になります。 このメソッドは、異なるプラットフォーム (Windows、Mac、web 上のWordなど) 上の同じドキュメントに対してまったく同じ HTML を返しません。 正確な忠実性、またはプラットフォーム間の整合性が必要な場合は、返された XML を使用 Range.getOoxml() して HTML に変換します。

getOoxml()

Range オブジェクトの OOXML 表記を取得します。

insertBreak(breakType, insertLocation)

メイン文書の指定した位置に、区切りを挿入します。

insertContentControl(contentControlType)

Range オブジェクトをコンテンツ コントロールでラップします。

insertFileFromBase64(base64File, insertLocation)

指定した位置に文書を挿入します。

insertHtml(html, insertLocation)

指定した位置に HTML を挿入します。

insertInlinePictureFromBase64(base64EncodedImage, insertLocation)

指定された位置に画像を挿入します。

insertOoxml(ooxml, insertLocation)

指定した位置に OOXML を挿入します。

insertParagraph(paragraphText, insertLocation)

指定した位置に、段落を挿入します。

insertText(text, insertLocation)

指定した位置にテキストを挿入します。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

search(searchText, searchOptions)

範囲オブジェクトのスコープで、指定した SearchOptions を使用して検索を実行します。 検索結果は、範囲オブジェクトのコレクションです。

select(selectionMode)

範囲を選択して、その範囲に Word の UI を移動します。

select(selectionModeString)

範囲を選択して、その範囲に Word の UI を移動します。

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクトまたは同じ型の別の API オブジェクトを渡すことができます。

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

toJSON()

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

track()

ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを呼び出しで .sync 使用していて、".run" バッチのシーケンシャル実行の外部で使用していて、プロパティを設定するとき、またはオブジェクトのメソッドを呼び出すときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。

untrack()

前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に を呼び出す context.sync() 必要があります。

プロパティの詳細

contentControls

範囲内のコンテンツ コントロール オブジェクトのコレクションを取得します。

readonly contentControls: Word.ContentControlCollection;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

context

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

context: RequestContext;

プロパティ値

font

範囲のテキスト形式を取得します。 これを使用して、フォント名、サイズ、色、およびその他のプロパティを取得および設定します。

readonly font: Word.Font;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

inlinePictures

範囲に含まれるインライン画像オブジェクトのコレクションを取得します。

readonly inlinePictures: Word.InlinePictureCollection;

プロパティ値

注釈

[ API セット: WordApi 1.2 ]

paragraphs

範囲内の段落オブジェクトのコレクションを取得します。

readonly paragraphs: Word.ParagraphCollection;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

重要: 要件セット 1.1 と 1.2 の場合、この範囲内に完全に含まれるテーブル内の段落は返されません。 要件セット 1.3 から、そのようなテーブル内の段落も返されます。

parentContentControl

範囲を含む現在サポートされているコンテンツ コントロールを取得します。 ItemNotFound親コンテンツ コントロールがない場合は、エラーをスローします。

readonly parentContentControl: Word.ContentControl;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-checkbox-content-control.yaml

// Toggles the isChecked property of the first checkbox content control found in the selection.
await Word.run(async (context) => {
  const selectedRange = context.document.getSelection();
  let selectedContentControl = selectedRange
    .getContentControls({
      types: [Word.ContentControlType.checkBox]
    })
    .getFirstOrNullObject();
  selectedContentControl.load("id,checkboxContentControl/isChecked");

  await context.sync();

  if (selectedContentControl.isNullObject) {
    const parentContentControl = selectedRange.parentContentControl;
    parentContentControl.load("id,type,checkboxContentControl/isChecked");
    await context.sync();

    if (parentContentControl.isNullObject || parentContentControl.type !== Word.ContentControlType.checkBox) {
      console.warn("No checkbox content control is currently selected.");
      return;
    } else {
      selectedContentControl = parentContentControl;
    }
  }

  const isCheckedBefore = selectedContentControl.checkboxContentControl.isChecked;
  console.log("isChecked state before:", `id: ${selectedContentControl.id} ... isChecked: ${isCheckedBefore}`);
  selectedContentControl.checkboxContentControl.isChecked = !isCheckedBefore;
  selectedContentControl.load("id,checkboxContentControl/isChecked");
  await context.sync();

  console.log(
    "isChecked state after:",
    `id: ${selectedContentControl.id} ... isChecked: ${selectedContentControl.checkboxContentControl.isChecked}`
  );
});

style

範囲のスタイル名を指定します。 カスタム スタイルとローカライズされたスタイルの名前には、このプロパティを使用します。 ロケール間で移植可能な組み込みスタイルを使用するには、"styleBuiltIn" プロパティを参照してください。

style: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.1 ]

text

範囲のテキストを取得します。

readonly text: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.1 ]

メソッドの詳細

clear()

範囲オブジェクトの内容をクリアします。 ユーザーは、消去された内容を元に戻す操作を実行できます。

clear(): void;

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to clear the contents of the proxy range object.
    range.clear();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Cleared the selection (range object)');
});

delete()

文書から範囲と、その範囲の内容を削除します。

delete(): void;

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to delete the range object.
    range.delete();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Deleted the selection (range object)');
});

getHtml()

範囲オブジェクトの HTML 表現を取得します。 Web ページまたは HTML ビューアーでレンダリングされた場合、書式設定は、ドキュメントの書式設定と完全に一致しませんが、近い形式になります。 このメソッドは、異なるプラットフォーム (Windows、Mac、web 上のWordなど) 上の同じドキュメントに対してまったく同じ HTML を返しません。 正確な忠実性、またはプラットフォーム間の整合性が必要な場合は、返された XML を使用 Range.getOoxml() して HTML に変換します。

getHtml(): OfficeExtension.ClientResult<string>;

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to get the HTML of the current selection.
    const html = range.getHtml();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('The HTML read from the document was: ' + html.value);
});

getOoxml()

Range オブジェクトの OOXML 表記を取得します。

getOoxml(): OfficeExtension.ClientResult<string>;

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to get the OOXML of the current selection.
    const ooxml = range.getOoxml();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('The OOXML read from the document was:  ' + ooxml.value);
});

insertBreak(breakType, insertLocation)

メイン文書の指定した位置に、区切りを挿入します。

insertBreak(breakType: Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line", insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): void;

パラメーター

breakType

Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line"

必須。 追加する中断の種類。

insertLocation

before | after | "Before" | "After"

必須です。 値は 'Before' または 'After' である必要があります。

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to insert a page break after the selected text.
    range.insertBreak(Word.BreakType.page, Word.InsertLocation.after);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Inserted a page break after the selected text.');
});

insertContentControl(contentControlType)

Range オブジェクトをコンテンツ コントロールでラップします。

insertContentControl(contentControlType?: Word.ContentControlType.richText | Word.ContentControlType.plainText | Word.ContentControlType.checkBox | "RichText" | "PlainText" | "CheckBox"): Word.ContentControl;

パラメーター

contentControlType

richText | plainText | checkBox | "RichText" | "PlainText" | "CheckBox"

省略可能。 挿入するコンテンツ コントロールの種類。 'RichText'、'PlainText'、または 'CheckBox' である必要があります。 既定値は "RichText" です。

戻り値

注釈

[ API セット: WordApi 1.1 ]

注: パラメーターは contentControlType WordApi 1.5 で導入されました。 PlainText WordApi 1.5 でサポートが追加されました。 CheckBox WordApi 1.7 でサポートが追加されました。

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/90-scenarios/doc-assembly.yaml

// Simulates creation of a template. First searches the document for instances of the string "Contractor",
// then changes the format  of each search result,
// then wraps each search result within a content control,
// finally sets a tag and title property on each content control.
await Word.run(async (context) => {
    const results = context.document.body.search("Contractor");
    results.load("font/bold");

    // Check to make sure these content controls haven't been added yet.
    const customerContentControls = context.document.contentControls.getByTag("customer");
    customerContentControls.load("text");
    await context.sync();

  if (customerContentControls.items.length === 0) {
    for (let i = 0; i < results.items.length; i++) { 
        results.items[i].font.bold = true;
        let cc = results.items[i].insertContentControl();
        cc.tag = "customer";  // This value is used in the next step of this sample.
        cc.title = "Customer Name " + i;
    }
  }
    await context.sync();
});

insertFileFromBase64(base64File, insertLocation)

指定した位置に文書を挿入します。

insertFileFromBase64(base64File: string, insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"): Word.Range;

パラメーター

base64File

string

必須です。 .docx ファイルの Base64 でエンコードされたコンテンツ。

insertLocation

Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"

必須です。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

注: 挿入するドキュメントに ActiveX コントロールが含まれている場合 (フォーム フィールドの可能性があります)、挿入はサポートされません。 このようなフォーム フィールドを、シナリオに適したコンテンツ コントロールまたはその他のオプションに置き換えることを検討してください。

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to insert base64 encoded .docx at the beginning of the range.
    // You'll need to implement getBase64() to make this work.
    range.insertFileFromBase64(getBase64(), Word.InsertLocation.start);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Added base64 encoded text to the beginning of the range.');
});

insertHtml(html, insertLocation)

指定した位置に HTML を挿入します。

insertHtml(html: string, insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"): Word.Range;

パラメーター

html

string

必須です。 挿入する HTML。

insertLocation

Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"

必須です。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to insert HTML in to the beginning of the range.
    range.insertHtml('<strong>This is text inserted with range.insertHtml()</strong>', Word.InsertLocation.start);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('HTML added to the beginning of the range.');
});

insertInlinePictureFromBase64(base64EncodedImage, insertLocation)

指定された位置に画像を挿入します。

insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"): Word.InlinePicture;

パラメーター

base64EncodedImage

string

必須です。 挿入する Base64 でエンコードされたイメージ。

insertLocation

Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"

必須です。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.2 ]

insertOoxml(ooxml, insertLocation)

指定した位置に OOXML を挿入します。

insertOoxml(ooxml: string, insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"): Word.Range;

パラメーター

ooxml

string

必須です。 挿入する OOXML を指定します。

insertLocation

Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"

必須です。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to insert OOXML in to the beginning of the range.
    range.insertOoxml("<pkg:package xmlns:pkg='http://schemas.microsoft.com/office/2006/xmlPackage'><pkg:part pkg:name='/_rels/.rels' pkg:contentType='application/vnd.openxmlformats-package.relationships+xml' pkg:padding='512'><pkg:xmlData><Relationships xmlns='http://schemas.openxmlformats.org/package/2006/relationships'><Relationship Id='rId1' Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' Target='word/document.xml'/></Relationships></pkg:xmlData></pkg:part><pkg:part pkg:name='/word/document.xml' pkg:contentType='application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'><pkg:xmlData><w:document xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' ><w:body><w:p><w:pPr><w:spacing w:before='360' w:after='0' w:line='480' w:lineRule='auto'/><w:rPr><w:color w:val='70AD47' w:themeColor='accent6'/><w:sz w:val='28'/></w:rPr></w:pPr><w:r><w:rPr><w:color w:val='70AD47' w:themeColor='accent6'/><w:sz w:val='28'/></w:rPr><w:t>This text has formatting directly applied to achieve its font size, color, line spacing, and paragraph spacing.</w:t></w:r></w:p></w:body></w:document></pkg:xmlData></pkg:part></pkg:package>", Word.InsertLocation.start);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('OOXML added to the beginning of the range.');
});

// Read "Create better add-ins for Word with Office Open XML" for guidance on working with OOXML.
// https://learn.microsoft.com/office/dev/add-ins/word/create-better-add-ins-for-word-with-office-open-xml

insertParagraph(paragraphText, insertLocation)

指定した位置に、段落を挿入します。

insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Paragraph;

パラメーター

paragraphText

string

必須です。 挿入する段落テキスト。

insertLocation

before | after | "Before" | "After"

必須です。 値は 'Before' または 'After' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to insert the paragraph after the range.
    range.insertParagraph('Content of a new paragraph', Word.InsertLocation.after);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Paragraph added to the end of the range.');
});

insertText(text, insertLocation)

指定した位置にテキストを挿入します。

insertText(text: string, insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"): Word.Range;

パラメーター

text

string

必須です。 挿入するテキスト。

insertLocation

Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"

必須です。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to insert the paragraph at the end of the range.
    range.insertText('New text inserted into the range.', Word.InsertLocation.end);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Text added to the end of the range.');
});

load(options)

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

load(options?: Word.Interfaces.RangeLoadOptions): Word.Range;

パラメーター

options
Word.Interfaces.RangeLoadOptions

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

戻り値

load(propertyNames)

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

load(propertyNames?: string | string[]): Word.Range;

パラメーター

propertyNames

string | string[]

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

戻り値

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Word.Range;

パラメーター

propertyNamesAndPaths

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

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

戻り値

search(searchText, searchOptions)

範囲オブジェクトのスコープで、指定した SearchOptions を使用して検索を実行します。 検索結果は、範囲オブジェクトのコレクションです。

search(searchText: string, searchOptions?: Word.SearchOptions | {
            ignorePunct?: boolean;
            ignoreSpace?: boolean;
            matchCase?: boolean;
            matchPrefix?: boolean;
            matchSuffix?: boolean;
            matchWholeWord?: boolean;
            matchWildcards?: boolean;
        }): Word.RangeCollection;

パラメーター

searchText

string

必須です。 検索テキスト。

searchOptions

Word.SearchOptions | { ignorePunct?: boolean; ignoreSpace?: boolean; matchCase?: boolean; matchPrefix?: boolean; matchSuffix?: boolean; matchWholeWord?: boolean; matchWildcards?: boolean; }

省略可能。 検索のオプション。

戻り値

注釈

[ API セット: WordApi 1.1 ]

select(selectionMode)

範囲を選択して、その範囲に Word の UI を移動します。

select(selectionMode?: Word.SelectionMode): void;

パラメーター

selectionMode
Word.SelectionMode

省略可能。 選択モードは、'Select'、'Start'、または 'End' である必要があります。 'Select' が既定値です。

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to get the current selection and then
    // create a proxy range object with the results.
    const range = context.document.getSelection();

    // Queue a command to insert HTML in to the beginning of the range.
    range.insertHtml('<strong>This is text inserted with range.insertHtml()</strong>', Word.InsertLocation.start);

    // Queue a command to select the HTML that was inserted.
    range.select();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Selected the range.');
});

select(selectionModeString)

範囲を選択して、その範囲に Word の UI を移動します。

select(selectionModeString?: "Select" | "Start" | "End"): void;

パラメーター

selectionModeString

"Select" | "Start" | "End"

省略可能。 選択モードは、'Select'、'Start'、または 'End' である必要があります。 'Select' が既定値です。

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクトまたは同じ型の別の API オブジェクトを渡すことができます。

set(properties: Interfaces.RangeUpdateData, options?: OfficeExtension.UpdateOptions): void;

パラメーター

properties
Word.Interfaces.RangeUpdateData

メソッドが呼び出されるオブジェクトのプロパティに等形的に構造化されたプロパティを持つ JavaScript オブジェクト。

options
OfficeExtension.UpdateOptions

properties オブジェクトが読み取り専用プロパティを設定しようとした場合にエラーを抑制するオプションを提供します。

戻り値

void

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

set(properties: Word.Range): void;

パラメーター

properties
Word.Range

戻り値

void

toJSON()

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

toJSON(): Word.Interfaces.RangeData;

戻り値

track()

ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを呼び出しで .sync 使用していて、".run" バッチのシーケンシャル実行の外部で使用していて、プロパティを設定するとき、またはオブジェクトのメソッドを呼び出すときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。

track(): Word.Range;

戻り値

untrack()

前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に を呼び出す context.sync() 必要があります。

untrack(): Word.Range;

戻り値