Excel.CommentCollection class
ブックの一部であるコメント オブジェクトのコレクションを表します。
- Extends
注釈
プロパティ
context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
items | このコレクション内に読み込まれた子アイテムを取得します。 |
メソッド
add(cell |
指定したセルで、指定した内容の新しいコメントを作成します。 指定 |
add(cell |
指定したセルで、指定した内容の新しいコメントを作成します。 指定 |
get |
コレクションに含まれるコメントの数を取得します。 |
get |
ID に基づいてコレクションからコメントを取得します。 |
get |
位置に基づいてコレクションからコメントを取得します。 |
get |
指定したセルからコメントを取得します。 セルにコメントがない場合は、エラーがスローされます。 |
get |
指定された応答が接続されているコメントを取得します。 |
get |
ID に基づいてコレクションからコメントを取得します。 コメント オブジェクトが存在しない場合、このメソッドは プロパティが に設定されたオブジェクトを |
load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
toJSON() | API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript |
イベント
on |
コメントが追加されたときに発生します。 |
on |
コメント コレクション内のコメントまたは返信が変更されたときに発生します (応答が削除されたときなど)。 |
on |
コメント コレクションでコメントが削除されたときに発生します。 |
プロパティの詳細
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
items
メソッドの詳細
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]
戻り値
注釈
例
// 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]
戻り値
注釈
getCount()
コレクションに含まれるコメントの数を取得します。
getCount(): OfficeExtension.ClientResult<number>;
戻り値
OfficeExtension.ClientResult<number>
注釈
getItem(commentId)
ID に基づいてコレクションからコメントを取得します。
getItem(commentId: string): Excel.Comment;
パラメーター
- commentId
-
string
コメントの識別子。
戻り値
注釈
getItemAt(index)
位置に基づいてコレクションからコメントを取得します。
getItemAt(index: number): Excel.Comment;
パラメーター
- index
-
number
取得するオブジェクトのインデックス値。 0 を起点とする番号になります。
戻り値
注釈
getItemByCell(cellAddress)
指定したセルからコメントを取得します。 セルにコメントがない場合は、エラーがスローされます。
getItemByCell(cellAddress: Range | string): Excel.Comment;
パラメーター
- cellAddress
-
Excel.Range | string
コメントがオンになっているセル。 オブジェクトまたは文字列を Range
指定できます。 文字列の場合は、シート名を含む完全なアドレスを含む必要があります。 指定 InvalidArgument
された範囲が 1 つのセルより大きい場合、エラーがスローされます。
戻り値
注釈
getItemByReplyId(replyId)
指定された応答が接続されているコメントを取得します。
getItemByReplyId(replyId: string): Excel.Comment;
パラメーター
- replyId
-
string
コメント応答の識別子。
戻り値
注釈
getItemOrNullObject(commentId)
ID に基づいてコレクションからコメントを取得します。 コメント オブジェクトが存在しない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObject
true
返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
getItemOrNullObject(commentId: string): Excel.Comment;
パラメーター
- commentId
-
string
コメントの識別子。
戻り値
注釈
load(options)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync()
を呼び出す必要があります。
load(options?: Excel.Interfaces.CommentCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.CommentCollection;
パラメーター
読み込むオブジェクトのプロパティのオプションを提供します。
戻り値
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>;
イベントの種類
注釈
例
// 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>;
イベントの種類
注釈
例
// 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>;
イベントの種類
注釈
例
// 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}`);
});
}
Office Add-ins
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示