Excel.CommentCollection class

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Represents a collection of comment objects that are part of the workbook.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

Extends
OfficeExtension.ClientObject

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

items

Gets the loaded child items in this collection.

Methods

add(content, cellAddress, contentType)

Creates a new comment (comment thread) with the given content on the given cell. An InvalidArgument error is thrown if the provided range is larger than one cell.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

add(content, cellAddress, contentTypeString)

Creates a new comment (comment thread) with the given content on the given cell. An InvalidArgument error is thrown if the provided range is larger than one cell.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getCount()

Gets the number of comments in the collection.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItem(commentId)

Gets a comment from the collection based on its ID. Read-only.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItemAt(index)

Gets a comment from the collection based on its position.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItemByCell(cellAddress)

Gets the comment from the specifed cell.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItemByReplyId(replyId)

Gets a comment related to its reply ID in the collection.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(option)
toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.CommentCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.CommentCollectionData) that contains an "items" array with shallow copies of any loaded properties from the collection's items.

Property Details

context

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

items

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets the loaded child items in this collection.

readonly items: Excel.Comment[];

Property Value

Excel.Comment[]

Method Details

add(content, cellAddress, contentType)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates a new comment (comment thread) with the given content on the given cell. An InvalidArgument error is thrown if the provided range is larger than one cell.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

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

Parameters

content
string

The comment content.

cellAddress
Range | string

The cell to which the comment is added. This can be a Range object or a string. If it's a string, it must contain the full address, including the sheet name. An InvalidArgument error is thrown if the provided range is larger than one cell.

contentType
Excel.ContentType

Optional. The type of the comment content

Returns

Examples

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("TODO: add data.", "A2");
    await context.sync();
});

add(content, cellAddress, contentTypeString)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates a new comment (comment thread) with the given content on the given cell. An InvalidArgument error is thrown if the provided range is larger than one cell.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

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

Parameters

content
string

The comment content.

cellAddress
Range | string

The cell to which the comment is added. This can be a Range object or a string. If it's a string, it must contain the full address, including the sheet name. An InvalidArgument error is thrown if the provided range is larger than one cell.

contentTypeString
"Plain"

Optional. The type of the comment content

Returns

getCount()

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets the number of comments in the collection.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getCount(): OfficeExtension.ClientResult<number>;

Returns

OfficeExtension.ClientResult<number>

getItem(commentId)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets a comment from the collection based on its ID. Read-only.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItem(commentId: string): Excel.Comment;

Parameters

commentId
string

The identifier for the comment.

Returns

getItemAt(index)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets a comment from the collection based on its position.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItemAt(index: number): Excel.Comment;

Parameters

index
number

Index value of the object to be retrieved. Zero-indexed.

Returns

getItemByCell(cellAddress)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets the comment from the specifed cell.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

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

Parameters

cellAddress
Range | string

The cell which the comment is on. This can be a Range object or a string. If it's a string, it must contain the full address, including the sheet name. An InvalidArgument error is thrown if the provided range is larger than one cell.

Returns

getItemByReplyId(replyId)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets a comment related to its reply ID in the collection.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItemByReplyId(replyId: string): Excel.Comment;

Parameters

replyId
string

The identifier of comment reply.

Returns

load(option)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

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

Parameters

option
Excel.Interfaces.CommentCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions

Returns

Remarks

In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Excel.CommentCollection - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Excel.CommentCollection - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.CommentCollection - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

load(propertyNames)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

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

Parameters

propertyNames
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(option)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Parameters

option
OfficeExtension.LoadOption

Returns

toJSON()

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.CommentCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.CommentCollectionData) that contains an "items" array with shallow copies of any loaded properties from the collection's items.

toJSON(): Excel.Interfaces.CommentCollectionData;

Returns