Excel.CommentCollection class

ブックの一部であるコメント オブジェクトのコレクションを表します。

Extends

プロパティ

context

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

items

このコレクション内に読み込まれた子アイテムを取得します。

メソッド

add(cellAddress, content, contentType)

指定したセルで、指定した内容の新しいコメントを作成します。 指定された範囲が 1 セルより大きい場合は、 InvalidArgument エラーがスローされます。

add(cellAddress, content, contentType)

指定したセルで、指定した内容の新しいコメントを作成します。 指定された範囲が 1 セルより大きい場合は、 InvalidArgument エラーがスローされます。

getCount()

コレクションに含まれるコメントの数を取得します。

getItem(commentId)

ID に基づいてコレクションからコメントを取得します。

getItemAt(index)

位置に基づいてコレクションからコメントを取得します。

getItemByCell(cellAddress)

指定したセルからコメントを取得します。 セルにコメントがない場合は、エラーがスローされます。

getItemByReplyId(replyId)

指定された応答が接続されているコメントを取得します。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Excel.CommentCollection オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.CommentCollectionData として型指定された) を返します。

イベント

onAdded

コメントが追加されたときに発生します。

onChanged

返信が削除された場合など、コメント コレクション内のコメントまたは返信が変更されたときに発生します。

onDeleted

コメント コレクションでコメントが削除されたときに発生します。

プロパティの詳細

context

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

context: RequestContext;

プロパティ値

items

このコレクション内に読み込まれた子アイテムを取得します。

readonly items: Excel.Comment[];

プロパティ値

メソッドの詳細

add(cellAddress, content, contentType)

指定したセルで、指定した内容の新しいコメントを作成します。 指定された範囲が 1 セルより大きい場合は、 InvalidArgument エラーがスローされます。

add(cellAddress: Range | string, content: CommentRichContent | string, contentType?: Excel.ContentType): Excel.Comment;

パラメーター

cellAddress

Excel.Range | string

コメントの追加先のセル。 これは、 Range オブジェクトまたは文字列を指定できます。 文字列の場合は、シート名を含む完全なアドレスを含める必要があります。 指定された範囲が 1 セルより大きい場合は、 InvalidArgument エラーがスローされます。

content

Excel.CommentRichContent | string

コメントの内容。 これは、文字列または CommentRichContent オブジェクトのいずれかです。 文字列はプレーン テキストに使用されます。 CommentRichContent オブジェクトを使用すると、メンションなどの他のコメント機能を使用できます。 [API セット: 文字列の場合は ExcelApi 1.10、CommentRichContent オブジェクトの場合は 1.11]

contentType
Excel.ContentType

省略可能。 コメントに含まれるコンテンツの種類。 既定値は enum ContentType.Plain です。 [API セット: 列挙型 ContentType.Plain の場合は ExcelApi 1.10、列挙型 ContentType.Mention の場合は 1.11]

返品

注釈

API セット: ExcelApi 1.10

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/12-comments-and-notes/comment-basics.yaml

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Comments");

    // Note that an InvalidArgument error will be thrown if multiple cells passed to `comment.add`.
    sheet.comments.add("A2", "TODO: add data.");
    await context.sync();
});

add(cellAddress, content, contentType)

指定したセルで、指定した内容の新しいコメントを作成します。 指定された範囲が 1 セルより大きい場合は、 InvalidArgument エラーがスローされます。

add(cellAddress: Range | string, content: CommentRichContent | string, contentType?: "Plain" | "Mention"): Excel.Comment;

パラメーター

cellAddress

Excel.Range | string

コメントの追加先のセル。 これは、 Range オブジェクトまたは文字列を指定できます。 文字列の場合は、シート名を含む完全なアドレスを含める必要があります。 指定された範囲が 1 セルより大きい場合は、 InvalidArgument エラーがスローされます。

content

Excel.CommentRichContent | string

コメントの内容。 これは、文字列または CommentRichContent オブジェクトのいずれかです。 文字列はプレーン テキストに使用されます。 CommentRichContent オブジェクトを使用すると、メンションなどの他のコメント機能を使用できます。 [API セット: 文字列の場合は ExcelApi 1.10、CommentRichContent オブジェクトの場合は 1.11]

contentType

"Plain" | "Mention"

省略可能。 コメントに含まれるコンテンツの種類。 既定値は enum ContentType.Plain です。 [API セット: 列挙型 ContentType.Plain の場合は ExcelApi 1.10、列挙型 ContentType.Mention の場合は 1.11]

返品

注釈

API セット: ExcelApi 1.10

getCount()

コレクションに含まれるコメントの数を取得します。

getCount(): OfficeExtension.ClientResult<number>;

返品

注釈

API セット: ExcelApi 1.10

getItem(commentId)

ID に基づいてコレクションからコメントを取得します。

getItem(commentId: string): Excel.Comment;

パラメーター

commentId

string

コメントの識別子。

返品

注釈

API セット: ExcelApi 1.10

getItemAt(index)

位置に基づいてコレクションからコメントを取得します。

getItemAt(index: number): Excel.Comment;

パラメーター

index

number

取得するオブジェクトのインデックス値。 0 を起点とする番号になります。

返品

注釈

API セット: ExcelApi 1.10

getItemByCell(cellAddress)

指定したセルからコメントを取得します。 セルにコメントがない場合は、エラーがスローされます。

getItemByCell(cellAddress: Range | string): Excel.Comment;

パラメーター

cellAddress

Excel.Range | string

コメントがあるセル。 これは、 Range オブジェクトまたは文字列を指定できます。 文字列の場合は、シート名を含む完全なアドレスを含める必要があります。 指定された範囲が 1 セルより大きい場合は、 InvalidArgument エラーがスローされます。

返品

注釈

API セット: ExcelApi 1.10

getItemByReplyId(replyId)

指定された応答が接続されているコメントを取得します。

getItemByReplyId(replyId: string): Excel.Comment;

パラメーター

replyId

string

コメント応答の識別子。

返品

注釈

API セット: ExcelApi 1.10

load(options)

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

load(options?: Excel.Interfaces.CommentCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.CommentCollection;

パラメーター

options

Excel.Interfaces.CommentCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions

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

返品

load(propertyNames)

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

load(propertyNames?: string | string[]): Excel.CommentCollection;

パラメーター

propertyNames

string | string[]

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

返品

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: OfficeExtension.LoadOption): Excel.CommentCollection;

パラメーター

propertyNamesAndPaths
OfficeExtension.LoadOption

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

返品

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Excel.CommentCollection オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.CommentCollectionData として型指定された) を返します。

toJSON(): Excel.Interfaces.CommentCollectionData;

返品

イベントの詳細

onAdded

コメントが追加されたときに発生します。

readonly onAdded: OfficeExtension.EventHandlers<Excel.CommentAddedEventArgs>;

イベントの種類

注釈

API セット: ExcelApi 1.12

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/events-comment-event-handler.yaml

await Excel.run(async (context) => {
    const comments = context.workbook.worksheets.getActiveWorksheet().comments;

    // Register the onAdded, onChanged, and onDeleted comment event handlers.
    comments.onAdded.add(commentAdded);
    comments.onChanged.add(commentChanged);
    comments.onDeleted.add(commentDeleted);

    await context.sync();

    console.log("Added event handlers for when comments are added, changed, or deleted.");
});

...

async function commentAdded(event: Excel.CommentAddedEventArgs) {
    // Retrieve the added comment using the comment ID.
    // Note: This function assumes only a single comment is added at a time.
    await Excel.run(async (context) => {
        const addedComment = context.workbook.comments.getItem(event.commentDetails[0].commentId);

        // Load the added comment's data.
        addedComment.load(["content", "authorName", "creationDate"]);

        await context.sync();

        // Print out the added comment's data.
        console.log(`A comment was added:`);
        console.log(`    ID: ${event.commentDetails[0].commentId}`);
        console.log(`    Comment content: ${addedComment.content}`);
        console.log(`    Comment author: ${addedComment.authorName}`);
        console.log(`    Creation date: ${addedComment.creationDate}`);
    });
}

onChanged

返信が削除された場合など、コメント コレクション内のコメントまたは返信が変更されたときに発生します。

readonly onChanged: OfficeExtension.EventHandlers<Excel.CommentChangedEventArgs>;

イベントの種類

注釈

API セット: ExcelApi 1.12

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/events-comment-event-handler.yaml

await Excel.run(async (context) => {
    const comments = context.workbook.worksheets.getActiveWorksheet().comments;

    // Register the onAdded, onChanged, and onDeleted comment event handlers.
    comments.onAdded.add(commentAdded);
    comments.onChanged.add(commentChanged);
    comments.onDeleted.add(commentDeleted);

    await context.sync();

    console.log("Added event handlers for when comments are added, changed, or deleted.");
});

...

async function commentChanged(event: Excel.CommentChangedEventArgs) {
    // Retrieve the changed comment using the comment ID.
    // Note: This function assumes only a single comment is changed at a time.
    await Excel.run(async (context) => {
        const changedComment = context.workbook.comments.getItem(event.commentDetails[0].commentId);

        // Load the changed comment's data.
        changedComment.load(["content", "authorName", "creationDate"]);

        await context.sync();

        // Print out the changed comment's data.
        console.log(`A comment was changed:`);
        console.log(`    ID: ${event.commentDetails[0].commentId}`);
        console.log(`    Updated comment content: ${changedComment.content}`);
        console.log(`    Comment author: ${changedComment.authorName}`);
        console.log(`    Creation date: ${changedComment.creationDate}`);
    });
}

onDeleted

コメント コレクションでコメントが削除されたときに発生します。

readonly onDeleted: OfficeExtension.EventHandlers<Excel.CommentDeletedEventArgs>;

イベントの種類

注釈

API セット: ExcelApi 1.12

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/events-comment-event-handler.yaml

await Excel.run(async (context) => {
    const comments = context.workbook.worksheets.getActiveWorksheet().comments;

    // Register the onAdded, onChanged, and onDeleted comment event handlers.
    comments.onAdded.add(commentAdded);
    comments.onChanged.add(commentChanged);
    comments.onDeleted.add(commentDeleted);

    await context.sync();

    console.log("Added event handlers for when comments are added, changed, or deleted.");
});

...

async function commentDeleted(event: Excel.CommentDeletedEventArgs) {
    // Print out the deleted comment's ID.
    // Note: This function assumes only a single comment is deleted at a time.
    await Excel.run(async (context) => {
        console.log(`A comment was deleted:`);
        console.log(`    ID: ${event.commentDetails[0].commentId}`);
    });
}