Word.Field class

フィールドを表します。

Extends

注釈

[ API セット: WordApi 1.4 ]

重要: 挿入できるフィールドの詳細については、Wordを参照してください。要件セット 1.5 で導入された Range.insertField API。 フィールドの管理のサポートは、Word UI で使用できる内容と似ています。 ただし、Web 上のWord UI では、主にフィールドが読み取り専用としてのみサポートされていますが (「Word web のフィールド コード」を参照)Addin、フィールドは編集可能です。 より完全にサポートされる UI クライアントWordの詳細については、「Wordのフィールドの挿入、編集、表示」の冒頭にある製品リストを参照してください。

プロパティ

code

フィールドのコード命令を指定します。

context

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

data

"Addin" フィールドにデータを指定します。 フィールドが "Addin" フィールドでない場合は null であり、コードで設定しようとすると一般的な例外がスローされます。

kind

フィールドの種類を取得します。

locked

フィールドがロックされているかどうかを指定します。 true フィールドがロックされている場合は 。 false それ以外の場合は 。

parentBody

フィールドの親本文を取得します。

parentContentControl

フィールドを含むコンテンツ コントロールを取得します。 ItemNotFound親コンテンツ コントロールがない場合は、エラーをスローします。

parentContentControlOrNullObject

フィールドを含むコンテンツ コントロールを取得します。 親コンテンツ コントロールがない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

parentTable

フィールドを含むテーブルを取得します。 テーブルに ItemNotFound 含まれていない場合は、エラーをスローします。

parentTableCell

フィールドを含むテーブル セルを取得します。 テーブル セルに ItemNotFound 含まれていない場合は、エラーをスローします。

parentTableCellOrNullObject

フィールドを含むテーブル セルを取得します。 テーブル セルに含まれていない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

parentTableOrNullObject

フィールドを含むテーブルを取得します。 テーブルに含まれていない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

result

フィールドの結果データを取得します。

showCodes

指定したフィールドのフィールド コードを表示するかどうかを指定します。 true フィールド コードが表示される場合は 。 false それ以外の場合は 。

type

フィールドの型を取得します。

メソッド

delete()

フィールドを削除します。

getNext()

次のフィールドを取得します。 このフィールドが最後の ItemNotFound フィールドである場合は、エラーをスローします。

getNextOrNullObject()

次のフィールドを取得します。 このフィールドが最後のフィールドの場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

select(selectionMode)

フィールドを選択します。

select(selectionModeString)

フィールドを選択します。

set(properties, options)

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

set(properties)

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

toJSON()

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

track()

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

untrack()

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

updateResult()

フィールドを更新します。

プロパティの詳細

code

フィールドのコード命令を指定します。

code: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.4 ]

注: コードを設定する機能は、WordApi 1.5 で導入されました。

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml

// Gets the first field in the document.
await Word.run(async (context) => {
  const field = context.document.body.fields.getFirstOrNullObject();
  field.load(["code", "result", "locked", "type", "data", "kind"]);

  await context.sync();

  if (field.isNullObject) {
    console.log("This document has no fields.");
  } else {
    console.log("Code of first field: " + field.code);
    console.log("Result of first field: " + JSON.stringify(field.result));
    console.log("Type of first field: " + field.type);
    console.log("Is the first field locked? " + field.locked);
    console.log("Kind of the first field: " + field.kind);
  }
});

context

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

context: RequestContext;

プロパティ値

data

"Addin" フィールドにデータを指定します。 フィールドが "Addin" フィールドでない場合は null であり、コードで設定しようとすると一般的な例外がスローされます。

data: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.5 ]

kind

フィールドの種類を取得します。

readonly kind: Word.FieldKind | "None" | "Hot" | "Warm" | "Cold";

プロパティ値

Word.FieldKind | "None" | "Hot" | "Warm" | "Cold"

注釈

[ API セット: WordApi 1.5 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml

// Gets the first field in the document.
await Word.run(async (context) => {
  const field = context.document.body.fields.getFirstOrNullObject();
  field.load(["code", "result", "locked", "type", "data", "kind"]);

  await context.sync();

  if (field.isNullObject) {
    console.log("This document has no fields.");
  } else {
    console.log("Code of first field: " + field.code);
    console.log("Result of first field: " + JSON.stringify(field.result));
    console.log("Type of first field: " + field.type);
    console.log("Is the first field locked? " + field.locked);
    console.log("Kind of the first field: " + field.kind);
  }
});

locked

フィールドがロックされているかどうかを指定します。 true フィールドがロックされている場合は 。 false それ以外の場合は 。

locked: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi 1.5 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml

// Gets the first field in the selection and toggles between setting it to locked or unlocked.
await Word.run(async (context) => {
  var field = context.document.getSelection().fields.getFirstOrNullObject();
  field.load(["code", "result", "type", "locked"]);
  await context.sync();

  if (field.isNullObject) {
    console.log("The selection has no fields.");
  } else {
    console.log(`The first field in the selection is currently ${field.locked ? "locked" : "unlocked"}.`);
    field.locked = !field.locked;
    await context.sync();

    console.log(`The first field in the selection is now ${field.locked ? "locked" : "unlocked"}.`);
  }
});

parentBody

フィールドの親本文を取得します。

readonly parentBody: Word.Body;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml

// Gets the parent body of the first field in the document.
await Word.run(async (context) => {
  const field = context.document.body.fields.getFirstOrNullObject();
  field.load("parentBody/text");

  await context.sync();

  if (field.isNullObject) {
    console.log("This document has no fields.");
  } else {
    const parentBody = field.parentBody;
    console.log("Text of first field's parent body: " + JSON.stringify(parentBody.text));
  }
});

parentContentControl

フィールドを含むコンテンツ コントロールを取得します。 ItemNotFound親コンテンツ コントロールがない場合は、エラーをスローします。

readonly parentContentControl: Word.ContentControl;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

parentContentControlOrNullObject

フィールドを含むコンテンツ コントロールを取得します。 親コンテンツ コントロールがない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

readonly parentContentControlOrNullObject: Word.ContentControl;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

parentTable

フィールドを含むテーブルを取得します。 テーブルに ItemNotFound 含まれていない場合は、エラーをスローします。

readonly parentTable: Word.Table;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

parentTableCell

フィールドを含むテーブル セルを取得します。 テーブル セルに ItemNotFound 含まれていない場合は、エラーをスローします。

readonly parentTableCell: Word.TableCell;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

parentTableCellOrNullObject

フィールドを含むテーブル セルを取得します。 テーブル セルに含まれていない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

readonly parentTableCellOrNullObject: Word.TableCell;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

parentTableOrNullObject

フィールドを含むテーブルを取得します。 テーブルに含まれていない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

readonly parentTableOrNullObject: Word.Table;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

result

フィールドの結果データを取得します。

readonly result: Word.Range;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml

// Gets the first field in the document.
await Word.run(async (context) => {
  const field = context.document.body.fields.getFirstOrNullObject();
  field.load(["code", "result", "locked", "type", "data", "kind"]);

  await context.sync();

  if (field.isNullObject) {
    console.log("This document has no fields.");
  } else {
    console.log("Code of first field: " + field.code);
    console.log("Result of first field: " + JSON.stringify(field.result));
    console.log("Type of first field: " + field.type);
    console.log("Is the first field locked? " + field.locked);
    console.log("Kind of the first field: " + field.kind);
  }
});

showCodes

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

指定したフィールドのフィールド コードを表示するかどうかを指定します。 true フィールド コードが表示される場合は 。 false それ以外の場合は 。

showCodes: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi BETA (プレビューのみ) ]

type

フィールドの型を取得します。

readonly type: Word.FieldType | "Addin" | "AddressBlock" | "Advance" | "Ask" | "Author" | "AutoText" | "AutoTextList" | "BarCode" | "Bibliography" | "BidiOutline" | "Citation" | "Comments" | "Compare" | "CreateDate" | "Data" | "Database" | "Date" | "DisplayBarcode" | "DocProperty" | "DocVariable" | "EditTime" | "Embedded" | "EQ" | "Expression" | "FileName" | "FileSize" | "FillIn" | "FormCheckbox" | "FormDropdown" | "FormText" | "GotoButton" | "GreetingLine" | "Hyperlink" | "If" | "Import" | "Include" | "IncludePicture" | "IncludeText" | "Index" | "Info" | "Keywords" | "LastSavedBy" | "Link" | "ListNum" | "MacroButton" | "MergeBarcode" | "MergeField" | "MergeRec" | "MergeSeq" | "Next" | "NextIf" | "NoteRef" | "NumChars" | "NumPages" | "NumWords" | "OCX" | "Page" | "PageRef" | "Print" | "PrintDate" | "Private" | "Quote" | "RD" | "Ref" | "RevNum" | "SaveDate" | "Section" | "SectionPages" | "Seq" | "Set" | "Shape" | "SkipIf" | "StyleRef" | "Subject" | "Subscriber" | "Symbol" | "TA" | "TC" | "Template" | "Time" | "Title" | "TOA" | "TOC" | "UserAddress" | "UserInitials" | "UserName" | "XE" | "Empty" | "Others" | "Undefined";

プロパティ値

Word.FieldType | "Addin" | "AddressBlock" | "Advance" | "Ask" | "Author" | "AutoText" | "AutoTextList" | "BarCode" | "Bibliography" | "BidiOutline" | "Citation" | "Comments" | "Compare" | "CreateDate" | "Data" | "Database" | "Date" | "DisplayBarcode" | "DocProperty" | "DocVariable" | "EditTime" | "Embedded" | "EQ" | "Expression" | "FileName" | "FileSize" | "FillIn" | "FormCheckbox" | "FormDropdown" | "FormText" | "GotoButton" | "GreetingLine" | "Hyperlink" | "If" | "Import" | "Include" | "IncludePicture" | "IncludeText" | "Index" | "Info" | "Keywords" | "LastSavedBy" | "Link" | "ListNum" | "MacroButton" | "MergeBarcode" | "MergeField" | "MergeRec" | "MergeSeq" | "Next" | "NextIf" | "NoteRef" | "NumChars" | "NumPages" | "NumWords" | "OCX" | "Page" | "PageRef" | "Print" | "PrintDate" | "Private" | "Quote" | "RD" | "Ref" | "RevNum" | "SaveDate" | "Section" | "SectionPages" | "Seq" | "Set" | "Shape" | "SkipIf" | "StyleRef" | "Subject" | "Subscriber" | "Symbol" | "TA" | "TC" | "Template" | "Time" | "Title" | "TOA" | "TOC" | "UserAddress" | "UserInitials" | "UserName" | "XE" | "Empty" | "Others" | "Undefined"

注釈

[ API セット: WordApi 1.5 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml

// Gets the first field in the document.
await Word.run(async (context) => {
  const field = context.document.body.fields.getFirstOrNullObject();
  field.load(["code", "result", "locked", "type", "data", "kind"]);

  await context.sync();

  if (field.isNullObject) {
    console.log("This document has no fields.");
  } else {
    console.log("Code of first field: " + field.code);
    console.log("Result of first field: " + JSON.stringify(field.result));
    console.log("Type of first field: " + field.type);
    console.log("Is the first field locked? " + field.locked);
    console.log("Kind of the first field: " + field.kind);
  }
});

メソッドの詳細

delete()

フィールドを削除します。

delete(): void;

戻り値

void

注釈

[ API セット: WordApi 1.5 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml

// Deletes the first field in the document.
await Word.run(async (context) => {
  const field = context.document.body.fields.getFirstOrNullObject();
  field.load();

  await context.sync();

  if (field.isNullObject) {
    console.log("This document has no fields.");
  } else {
    field.delete();
    await context.sync();

    console.log("The first field in the document was deleted.");
  }
});

getNext()

次のフィールドを取得します。 このフィールドが最後の ItemNotFound フィールドである場合は、エラーをスローします。

getNext(): Word.Field;

戻り値

注釈

[ API セット: WordApi 1.4 ]

getNextOrNullObject()

次のフィールドを取得します。 このフィールドが最後のフィールドの場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

getNextOrNullObject(): Word.Field;

戻り値

注釈

[ API セット: WordApi 1.4 ]

load(options)

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

load(options?: Word.Interfaces.FieldLoadOptions): Word.Field;

パラメーター

options
Word.Interfaces.FieldLoadOptions

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

戻り値

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

戻り値

load(propertyNamesAndPaths)

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

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

パラメーター

propertyNamesAndPaths

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

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

戻り値

select(selectionMode)

フィールドを選択します。

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

パラメーター

selectionMode
Word.SelectionMode

オプション。 選択モードは、'Select'、'Start'、または 'End' である必要があります。 'Select' が既定値です。

戻り値

void

注釈

[ API セット: WordApi 1.5 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml

// Gets and updates the first field in the selection.
await Word.run(async (context) => {
  var field = context.document.getSelection().fields.getFirstOrNullObject();
  field.load(["code", "result", "type", "locked"]);

  await context.sync();

  if (field.isNullObject) {
    console.log("No field in selection.");
  } else {
    console.log("Before updating:");
    console.log("Code of first field: " + field.code);
    console.log("Result of first field: " + JSON.stringify(field.result));

    field.updateResult();
    field.select();
    await context.sync();

    field.load(["code", "result"]);
    await context.sync();

    console.log("After updating:");
    console.log("Code of first field: " + field.code);
    console.log("Result of first field: " + JSON.stringify(field.result));
  }
});

select(selectionModeString)

フィールドを選択します。

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

パラメーター

selectionModeString

"Select" | "Start" | "End"

オプション。 選択モードは、'Select'、'Start'、または 'End' である必要があります。 'Select' が既定値です。

戻り値

void

注釈

[ API セット: WordApi 1.5 ]

set(properties, options)

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

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

パラメーター

properties
Word.Interfaces.FieldUpdateData

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

options
OfficeExtension.UpdateOptions

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

戻り値

void

set(properties)

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

set(properties: Word.Field): void;

パラメーター

properties
Word.Field

戻り値

void

toJSON()

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

toJSON(): Word.Interfaces.FieldData;

戻り値

track()

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

track(): Word.Field;

戻り値

untrack()

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

untrack(): Word.Field;

戻り値

updateResult()

フィールドを更新します。

updateResult(): void;

戻り値

void

注釈

[ API セット: WordApi 1.5 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml

// Gets and updates the first field in the selection.
await Word.run(async (context) => {
  var field = context.document.getSelection().fields.getFirstOrNullObject();
  field.load(["code", "result", "type", "locked"]);

  await context.sync();

  if (field.isNullObject) {
    console.log("No field in selection.");
  } else {
    console.log("Before updating:");
    console.log("Code of first field: " + field.code);
    console.log("Result of first field: " + JSON.stringify(field.result));

    field.updateResult();
    field.select();
    await context.sync();

    field.load(["code", "result"]);
    await context.sync();

    console.log("After updating:");
    console.log("Code of first field: " + field.code);
    console.log("Result of first field: " + JSON.stringify(field.result));
  }
});