Excel.CommentCollection class

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

Extends

注釈

[ API セット: ExcelApi 1.10 ]

プロパティ

context

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

items

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

メソッド

add(cellAddress, content, contentType)

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

add(cellAddress, content, contentTypeString)

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

getCount()

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

getItem(commentId)

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

getItemAt(index)

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

getItemByCell(cellAddress)

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

getItemByReplyId(replyId)

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

getItemOrNullObject(commentId)

ID に基づいてコレクションからコメントを取得します。 コメント オブジェクトが存在しない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

toJSON()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (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)

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

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

パラメーター

cellAddress

Excel.Range | string

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

content

Excel.CommentRichContent | string

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

contentType
Excel.ContentType

オプション。 コメントに含まれるコンテンツの種類。 既定値は enum です ContentType.Plain。 [Api set: ExcelApi 1.10 for Enum ContentType.Plain, 1.11 for Enum ContentType.Mention]

戻り値

注釈

[ API セット: ExcelApi 1.10 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/12-comment/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, contentTypeString)

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

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

パラメーター

cellAddress

Excel.Range | string

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

content

Excel.CommentRichContent | string

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

contentTypeString

"Plain" | "Mention"

オプション。 コメントに含まれるコンテンツの種類。 既定値は enum です ContentType.Plain。 [Api set: ExcelApi 1.10 for Enum ContentType.Plain, 1.11 for Enum ContentType.Mention]

戻り値

注釈

[ 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 指定できます。 文字列の場合は、シート名を含む完全なアドレスを含む必要があります。 指定 InvalidArgument された範囲が 1 つのセルより大きい場合、エラーがスローされます。

戻り値

注釈

[ API セット: ExcelApi 1.10 ]

getItemByReplyId(replyId)

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

getItemByReplyId(replyId: string): Excel.Comment;

パラメーター

replyId

string

コメント応答の識別子。

戻り値

注釈

[ API セット: ExcelApi 1.10 ]

getItemOrNullObject(commentId)

ID に基づいてコレクションからコメントを取得します。 コメント オブジェクトが存在しない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

getItemOrNullObject(commentId: string): Excel.Comment;

パラメーター

commentId

string

コメントの識別子。

戻り値

注釈

[ API セット: ExcelApi 1.14 ]

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 オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (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}`);
    });
}