Word.Comment class

ドキュメント内のコメントを表します。

Extends

注釈

[ API セット: WordApi 1.4 ]

プロパティ

authorEmail

コメント作成者のメール アドレスを取得します。

authorName

コメント作成者の名前を取得します。

content

コメントの内容をプレーン テキストとして指定します。

contentRange

コメントのコンテンツ範囲を指定します。

context

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

creationDate

コメントの作成日を取得します。

id

コメントの ID を取得します。

replies

コメントに関連付けられている応答オブジェクトのコレクションを取得します。

resolved

コメント スレッドの状態を指定します。 を true に設定すると、コメント スレッドが解決されます。 true の値を取得すると、コメント スレッドが解決されます。

メソッド

delete()

コメントとその返信を削除します。

getRange()

コメントがあるメインドキュメント内の範囲を取得します。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

reply(replyText)

コメント スレッドの末尾に新しい応答を追加します。

set(properties, options)

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

set(properties)

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

toJSON()

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

track()

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

untrack()

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

プロパティの詳細

authorEmail

コメント作成者のメール アドレスを取得します。

readonly authorEmail: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.4 ]

authorName

コメント作成者の名前を取得します。

readonly authorName: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.4 ]

content

コメントの内容をプレーン テキストとして指定します。

content: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.4 ]

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

// Edits the first comment in the selected content.
await Word.run(async (context) => {
  const text = $("#edit-comment-text")
    .val()
    .toString();
  const comment = context.document
    .getSelection()
    .getComments()
    .getFirst();
  comment.content = text;

  // Load object for display in Script Lab console.
  comment.load();
  await context.sync();

  console.log("Comment content changed:");
  console.log(comment);
});

contentRange

コメントのコンテンツ範囲を指定します。

contentRange: Word.CommentContentRange;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

context

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

context: RequestContext;

プロパティ値

creationDate

コメントの作成日を取得します。

readonly creationDate: Date;

プロパティ値

Date

注釈

[ API セット: WordApi 1.4 ]

id

コメントの ID を取得します。

readonly id: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.4 ]

replies

コメントに関連付けられている応答オブジェクトのコレクションを取得します。

readonly replies: Word.CommentReplyCollection;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

resolved

コメント スレッドの状態を指定します。 を true に設定すると、コメント スレッドが解決されます。 true の値を取得すると、コメント スレッドが解決されます。

resolved: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi 1.4 ]

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

// Toggles Resolved status of the first comment in the selected content.
await Word.run(async (context) => {
  const comment = context.document
    .getSelection()
    .getComments()
    .getFirst();
  comment.load("resolved");
  await context.sync();

  // Toggle resolved status.
  // If the comment is active, set as resolved.
  // If it's resolved, set resolved to false.
  const toggleResolved: boolean = comment.resolved;
  comment.resolved = !toggleResolved;
  comment.load();
  await context.sync();

  console.log(`Comment Resolved status: ${comment.resolved}`);
  console.log(comment);
});

メソッドの詳細

delete()

コメントとその返信を削除します。

delete(): void;

戻り値

void

注釈

[ API セット: WordApi 1.4 ]

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

// Deletes the first comment in the selected content.
await Word.run(async (context) => {
  context.document
    .getSelection()
    .getComments()
    .getFirst()
    .delete();
  await context.sync();

  console.log("Comment deleted");
});

getRange()

コメントがあるメインドキュメント内の範囲を取得します。

getRange(): Word.Range;

戻り値

注釈

[ API セット: WordApi 1.4 ]

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

// Gets the range of the first comment in the selected content.
await Word.run(async (context) => {
  const range = context.document
    .getSelection()
    .getComments()
    .getFirst()
    .getRange();
  range.load("text");
  await context.sync();

  console.log(`Comment location: ${range.text}`);
});

load(options)

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

load(options?: Word.Interfaces.CommentLoadOptions): Word.Comment;

パラメーター

options
Word.Interfaces.CommentLoadOptions

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

戻り値

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

戻り値

load(propertyNamesAndPaths)

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

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

パラメーター

propertyNamesAndPaths

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

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

戻り値

reply(replyText)

コメント スレッドの末尾に新しい応答を追加します。

reply(replyText: string): Word.CommentReply;

パラメーター

replyText

string

必須です。 返信テキスト。

戻り値

注釈

[ API セット: WordApi 1.4 ]

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

// Replies to the first active comment in the selected content.
await Word.run(async (context) => {
  const text = $("#reply-text")
    .val()
    .toString();
  const comments = context.document.getSelection().getComments();
  comments.load("items");
  await context.sync();
  const firstActiveComment = comments.items.find((item) => item.resolved !== true);
  if (firstActiveComment) {
    const reply = firstActiveComment.reply(text);
    console.log("Reply added");
  } else {
    console.log("No active comment was found in the selection so couldn't reply.");
  }
});

set(properties, options)

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

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

パラメーター

properties
Word.Interfaces.CommentUpdateData

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

options
OfficeExtension.UpdateOptions

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

戻り値

void

set(properties)

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

set(properties: Word.Comment): void;

パラメーター

properties
Word.Comment

戻り値

void

toJSON()

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

toJSON(): Word.Interfaces.CommentData;

戻り値

track()

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

track(): Word.Comment;

戻り値

untrack()

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

untrack(): Word.Comment;

戻り値