Androidでプレゼンテーションコメントを管理する
PowerPoint では、コメントはスライド上のメモや注釈として表示されます。コメントをクリックすると、その内容やメッセージが表示されます。
プレゼンテーションにコメントを追加する理由
プレゼンテーションをレビューする際、フィードバックを提供したり同僚とやり取りしたりするためにコメントを使用したくなることがあります。
PowerPoint プレゼンテーションでコメントを使用できるように、Aspose.Slides for Android via Java は以下を提供します
- The Presentation クラスは、著者のコレクション(ICommentAuthorCollection インターフェイス)を含みます。著者はスライドにコメントを追加します。
- The ICommentCollection インターフェイスは、個々の著者のコメントコレクションを含みます。
- The IComment クラスは、著者とそのコメントに関する情報(コメントを追加した人物、追加された日時、コメントの位置など)を含みます。
- The CommentAuthor クラスは、個々の著者に関する情報(著者名、イニシャル、著者名に関連付けられたコメントなど)を含みます。
スライドコメントの追加
以下の Java コードは、PowerPoint プレゼンテーションのスライドにコメントを追加する方法を示します:
// Presentation クラスのインスタンスを作成
Presentation pres = new Presentation();
try {
// 空のスライドを追加
pres.getSlides().addEmptySlide(pres.getLayoutSlides().get_Item(0));
// 著者を追加
ICommentAuthor author = pres.getCommentAuthors().addAuthor("Jawad", "MF");
// コメントの位置を設定
Point2D.Float point = new Point2D.Float(0.2f, 0.2f);
// スライド1の著者用スライドコメントを追加
author.getComments().addComment("Hello Jawad, this is slide comment", pres.getSlides().get_Item(0), point, new Date());
// スライド2の著者用スライドコメントを追加
author.getComments().addComment("Hello Jawad, this is second slide comment", pres.getSlides().get_Item(1), point, new Date());
// ISlide 1 にアクセス
ISlide slide = pres.getSlides().get_Item(0);
// 引数に null を渡すと、すべての著者のコメントが選択したスライドに取得されます
IComment[] Comments = slide.getSlideComments(author);
// スライド1のインデックス0のコメントにアクセス
String str = Comments[0].getText();
pres.save("Comments_out.pptx", SaveFormat.Pptx);
if (Comments.length > 0)
{
// インデックス0の著者のコメントコレクションを取得
ICommentCollection commentCollection = Comments[0].getAuthor().getComments();
String Comment = commentCollection.get_Item(0).getText();
}
} finally {
if (pres != null) pres.dispose();
}
スライドコメントへのアクセス
以下の Java コードは、PowerPoint プレゼンテーションのスライド上に既存のコメントにアクセスする方法を示します:
// Presentation クラスのインスタンスを作成
Presentation pres = new Presentation("Comments1.pptx");
try {
for (ICommentAuthor commentAuthor : pres.getCommentAuthors())
{
CommentAuthor author = (CommentAuthor) commentAuthor;
for (IComment comment1 : author.getComments())
{
Comment comment = (Comment) comment1;
System.out.println("ISlide :" + comment.getSlide().getSlideNumber() + " has comment: " + comment.getText() +
" with Author: " + comment.getAuthor().getName() + " posted on time :" + comment.getCreatedTime() + "\n");
}
}
} finally {
if (pres != null) pres.dispose();
}
コメントへの返信
親コメントは、コメントや返信の階層で最上位または元となるコメントです。getParentComment または setParentComment メソッド(IComment インターフェイス)を使用して、親コメントを取得または設定できます。
以下の Java コードは、コメントを追加し、それへの返信を取得する方法を示します:
Presentation pres = new Presentation();
try {
// コメントを追加します
ICommentAuthor author1 = pres.getCommentAuthors().addAuthor("Author_1", "A.A.");
IComment comment1 = author1.getComments().addComment("comment1", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date());
// comment1 に対する返信を追加します
ICommentAuthor author2 = pres.getCommentAuthors().addAuthor("Autror_2", "B.B.");
IComment reply1 = author2.getComments().addComment("reply 1 for comment 1", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date());
reply1.setParentComment(comment1);
// comment1 に対する別の返信を追加します
IComment reply2 = author2.getComments().addComment("reply 2 for comment 1", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date());
reply2.setParentComment(comment1);
// 既存の返信に対するサブ返信を追加します
IComment subReply = author1.getComments().addComment("subreply 3 for reply 2", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date());
subReply.setParentComment(reply2);
IComment comment2 = author2.getComments().addComment("comment 2", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date());
IComment comment3 = author2.getComments().addComment("comment 3", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date());
IComment reply3 = author1.getComments().addComment("reply 4 for comment 3", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date());
reply3.setParentComment(comment3);
// コンソールにコメント階層を表示します
ISlide slide = pres.getSlides().get_Item(0);
IComment[] comments = slide.getSlideComments(null);
for (int i = 0; i < comments.length; i++)
{
IComment comment = comments[i];
while (comment.getParentComment() != null)
{
System.out.print("\t");
comment = comment.getParentComment();
}
System.out.println(comments[i].getAuthor().getName() + " : " + comments[i].getText());
System.out.println();
}
pres.save("parent_comment.pptx",SaveFormat.Pptx);
// comment1 とそれへのすべての返信を削除します
comment1.remove();
pres.save("remove_comment.pptx",SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
Attention
- Remove メソッド(IComment インターフェイス)を使用してコメントを削除すると、そのコメントへの返信も削除されます。
- setParentComment 設定で循環参照が発生した場合、PptxEditException がスローされます。
モダンコメントの追加
2021 年に、Microsoft は PowerPoint に モダンコメント を導入しました。モダンコメント機能は、PowerPoint におけるコラボレーションを大幅に向上させます。モダンコメントを使用すると、PowerPoint ユーザーはコメントを解決したり、オブジェクトやテキストにコメントを固定したり、従来よりもはるかに簡単にやり取りできるようになります。
Aspose.Slides は ModernComment クラスによりモダンコメントをサポートします。addModernComment および insertModernComment メソッドが CommentCollection クラスに追加されました。
以下の Java コードは、PowerPoint プレゼンテーションのスライドにモダンコメントを追加する方法を示します:
Presentation pres = new Presentation();
try {
ICommentAuthor newAuthor = pres.getCommentAuthors().addAuthor("Some Author", "SA");
IModernComment modernComment = newAuthor.getComments().addModernComment("This is a modern comment", pres.getSlides().get_Item(0), null, new Point2D.Float(100, 100), new Date());
pres.save("pres.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
コメントの削除
すべてのコメントと著者を削除
以下の Java コードは、プレゼンテーション内のすべてのコメントと著者を削除する方法を示します:
Presentation presentation = new Presentation("example.pptx");
try {
// プレゼンテーションからすべてのコメントを削除します
for (ICommentAuthor author : presentation.getCommentAuthors())
{
author.getComments().clear();
}
// すべての著者を削除します
presentation.getCommentAuthors().clear();
presentation.save("example_out.pptx", SaveFormat.Pptx);
} finally {
if (presentation != null) presentation.dispose();
}
特定のコメントを削除
以下の Java コードは、スライド上の特定のコメントを削除する方法を示します:
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
// コメントを追加します...
ICommentAuthor author = presentation.getCommentAuthors().addAuthor("Author", "A");
author.getComments().addComment("comment 1", slide, new Point2D.Float(0.2f, 0.2f), new Date());
author.getComments().addComment("comment 2", slide, new Point2D.Float(0.3f, 0.2f), new Date());
// 「comment 1」というテキストを含むすべてのコメントを削除します
for (ICommentAuthor commentAuthor : presentation.getCommentAuthors())
{
ArrayList<IComment> toRemove = new ArrayList<IComment>();
for (IComment comment : slide.getSlideComments(commentAuthor))
{
if (comment.getText().equals("comment 1"))
{
toRemove.add(comment);
}
}
for (IComment comment : toRemove)
{
commentAuthor.getComments().remove(comment);
}
}
presentation.save("pres.pptx", SaveFormat.Pptx);
} finally {
if (presentation != null) presentation.dispose();
}
よくある質問
Aspose.Slides はモダンコメントに「解決済み」などのステータスをサポートしていますか?
はい。 Modern comments は setStatus メソッドを提供しています。コメントの状態(例: 解決済みとしてマーク)を書き込むことができ、この状態はファイルに保存され、PowerPoint で認識されます。
スレッド化されたディスカッション(返信チェーン)はサポートされていますか?また、ネストの上限はありますか?
はい。 各コメントは parent comment を参照できるため、任意の返信チェーンを構築できます。API では特定のネスト深さの上限は明示されていません。
スライド上のコメントマーカーの位置はどの座標系で定義されていますか?
位置はスライドの座標系での浮動小数点ポイントとして保存されます。これにより、コメントマーカーを必要な場所に正確に配置できます。