在 C++ 中管理簡報註解
概觀
本文說明如何使用 Aspose.Slides for C++ 來管理簡報註解。它會介紹與註解相關的主要類型,並示範如何向投影片新增註解、存取現有註解、操作回覆與現代註解,以及如何從簡報中刪除註解。
這些範例涵蓋 PowerPoint 中常見的審閱與協作情境,例如將註解指派給作者、讀取註解文字與中繼資料、建立回覆鏈,以及移除選取的註解或全部註解。
在 PowerPoint 中,註解會以投影片上的批註形式呈現。選取註解時會顯示其文字與相關討論。
若要在開啟簡報時請求顯示或隱藏註解(而不變更註解本身),請參閱 在開啟簡報時顯示或隱藏註解。
為何要在簡報中加入註解?
您可以在審閱簡報時使用註解提供回饋,並與同事協同合作。
Aspose.Slides for C++ 提供以下用於處理註解的 API:
- Presentation 類別,可存取簡報的註解作者。
- ICommentCollection 介面,代表與個別作者相關的註解集合。
- IComment 介面,提供註解的資訊,包括作者、建立時間、位置與文字。
- CommentAuthor 類別,提供作者資訊,包括姓名、縮寫與其相關的註解。
新增投影片註解
此範例建立兩張投影片,並使用 AddAuthor 註冊一位註解作者。它使用 AddComment 在每張投影片上放置一個註解,然後使用 GetSlideComments 取得該作者在第一張投影片的註解。主控台會兩次顯示第一個註解的文字,示範透過投影片與作者兩種方式存取,且儲存的簡報會同時包含這兩個註解。
#include <DOM/IComment.h>
#include <DOM/ICommentAuthor.h>
#include <DOM/ICommentAuthorCollection.h>
#include <DOM/ICommentCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <drawing/point_f.h>
#include <system/console.h>
#include <system/date_time.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
auto presentation = MakeObject<Presentation>();
auto firstSlide = presentation->get_Slide(0);
auto secondSlide = presentation->get_Slides()->AddEmptySlide(presentation->get_LayoutSlide(0));
auto author = presentation->get_CommentAuthors()->AddAuthor(u"Jawad", u"MF");
auto position = PointF(0.2f, 0.2f);
auto createdTime = DateTime::get_Now();
author->get_Comments()->AddComment(u"Hello Jawad, this is a slide comment", firstSlide, position, createdTime);
author->get_Comments()->AddComment(u"Hello Jawad, this is the second slide comment", secondSlide, position, createdTime);
auto comments = firstSlide->GetSlideComments(author);
if (comments->get_Length() > 0)
{
auto firstComment = comments[0];
Console::WriteLine(firstComment->get_Text());
auto commentText = firstComment->get_Author()->get_Comments()->idx_get(0)->get_Text();
Console::WriteLine(commentText);
}
presentation->Save(u"Comments_out.pptx", SaveFormat::Pptx);
尋找或建立註解作者
當自動化審閱重複處理相同簡報時,請在新增作者之前先搜尋 get_CommentAuthors 回傳的集合。 FindByNameAndInitials 同時比對名稱與縮寫,並回傳符合的作者陣列,若無符合則回傳空陣列。相較之下, FindByName 僅依名稱搜尋,不考慮縮寫。若以已存在於集合中的名稱與縮寫呼叫 AddAuthor,會拋出例外。
此範例需要一個至少包含一張投影片的簡報檔案。於兩次迭代中,它會重複使用第一個符合條件的作者,或在結果為空時才建立新作者。如果有多個符合項目,則選取陣列的第一個元素,且不會合併或移除其他作者。接著它會以選取的作者呼叫 AddComment,並儲存簡報。第二次迭代會開啟第一次的輸出檔並重複此操作。
#include <DOM/ICommentAuthor.h>
#include <DOM/ICommentAuthorCollection.h>
#include <DOM/ICommentCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <drawing/point_f.h>
#include <system/date_time.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
const String authorName = u"Reviewer";
const String authorInitials = u"RV";
auto inputFile = String(u"input.pptx");
auto position = PointF(20.0f, 20.0f);
for (auto pass = 1; pass <= 2; pass++)
{
auto presentation = MakeObject<Presentation>(inputFile);
auto matches = presentation->get_CommentAuthors()->FindByNameAndInitials(authorName, authorInitials);
auto author = matches->get_Length() > 0 ? matches[0] : presentation->get_CommentAuthors()->AddAuthor(authorName, authorInitials);
author->get_Comments()->AddComment(u"Please review this slide.", presentation->get_Slide(0), position, DateTime::get_Now());
auto outputFile = String::Format(u"review_pass_{0}.pptx", pass);
presentation->Save(outputFile, SaveFormat::Pptx);
inputFile = outputFile;
}
第二次迭代會再新增一個註解,但不會新增另一位作者,也不會移除現有的註解。最終檔案 review_pass_2.pptx 會同時包含新註解與任何原始註解。重複使用作者不會去除重複的註解:若要避免重複新增相同註解,請在新增前自行實作重複偵測。
存取投影片註解
此範例開啟現有簡報,讀取由 get_CommentAuthors 回傳的集合。對於每位作者,它會遍歷由 get_Comments 回傳的集合,並印出投影片編號、註解文字、作者姓名與建立時間。輸入的簡報必須包含註解才能在主控台產生輸出。
#include <DOM/IComment.h>
#include <DOM/ICommentAuthor.h>
#include <DOM/ICommentAuthorCollection.h>
#include <DOM/ICommentCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <system/console.h>
using namespace Aspose::Slides;
using namespace System;
auto presentation = MakeObject<Presentation>(u"Comments1.pptx");
for (auto&& author : presentation->get_CommentAuthors())
{
for (auto&& comment : author->get_Comments())
{
Console::WriteLine(u"Slide: {0}", comment->get_Slide()->get_SlideNumber());
Console::WriteLine(u"Comment: {0}", comment->get_Text());
Console::WriteLine(u"Author: {0}", comment->get_Author()->get_Name());
Console::WriteLine(u"Posted at: {0}", comment->get_CreatedTime());
Console::WriteLine();
}
}
回覆註解
父註解是回覆階層頂端的原始註解。 IComment 介面的 get_ParentComment 與 set_ParentComment 方法可取得或設定註解的父項。
此範例建立兩位作者的註解,並使用 set_ParentComment 來建立回覆,包含回覆另一個回覆。將 nullptr 傳遞給 GetSlideComments 會取得所有作者的註解;主控台會依照回覆層級的深度縮排每筆條目。範例會儲存完整的討論,對第一個根註解呼叫 Remove,並儲存第二個簡報,該簡報已移除該註解及其回覆。
#include <DOM/IComment.h>
#include <DOM/ICommentAuthor.h>
#include <DOM/ICommentAuthorCollection.h>
#include <DOM/ICommentCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <drawing/point_f.h>
#include <system/console.h>
#include <system/date_time.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto position = PointF(10.0f, 10.0f);
auto createdTime = DateTime::get_Now();
auto originalAuthor = presentation->get_CommentAuthors()->AddAuthor(u"Author_1", u"A.A.");
auto rootComment = originalAuthor->get_Comments()->AddComment(u"comment 1", slide, position, createdTime);
auto reviewer = presentation->get_CommentAuthors()->AddAuthor(u"Author_2", u"B.B.");
auto firstReply = reviewer->get_Comments()->AddComment(u"reply 1 for comment 1", slide, position, createdTime);
firstReply->set_ParentComment(rootComment);
auto secondReply = reviewer->get_Comments()->AddComment(u"reply 2 for comment 1", slide, position, createdTime);
secondReply->set_ParentComment(rootComment);
auto subReply = originalAuthor->get_Comments()->AddComment(u"subreply 3 for reply 2", slide, position, createdTime);
subReply->set_ParentComment(secondReply);
reviewer->get_Comments()->AddComment(u"comment 2", slide, position, createdTime);
auto separateComment = reviewer->get_Comments()->AddComment(u"comment 3", slide, position, createdTime);
auto separateReply = originalAuthor->get_Comments()->AddComment(u"reply 4 for comment 3", slide, position, createdTime);
separateReply->set_ParentComment(separateComment);
auto comments = slide->GetSlideComments(nullptr);
for (auto i = 0; i < comments->get_Length(); i++)
{
auto comment = comments[i];
while (comment->get_ParentComment() != nullptr)
{
Console::Write(u"\t");
comment = comment->get_ParentComment();
}
Console::WriteLine(u"{0}: {1}", comments[i]->get_Author()->get_Name(), comments[i]->get_Text());
}
presentation->Save(u"parent_comment.pptx", SaveFormat::Pptx);
rootComment->Remove();
presentation->Save(u"remove_comment.pptx", SaveFormat::Pptx);
Warning
- 使用 IComment 介面的 Remove 方法刪除註解時,該註解的所有回覆也會一併被刪除。
- 若 set_ParentComment 方法造成循環參照,則會拋出 PptxEditException。
新增現代註解
現代註解可以與投影片本身、特定圖形,或 AutoShape 內的文字範圍關聯。 ICommentCollection::AddModernComment 方法接受一個 IShape 參數,此外還需要投影片與註解標記的座標。
當形狀參數傳入 nullptr 時,註解為投影片層級的註解。其標記位置由提供的座標決定,但不會與特定圖形關聯,因此 IModernComment::get_Shape 會回傳 nullptr。若提供 IShape 則註解會錨定於該圖形。座標仍然定義註解標記在投影片上的位置,而圖形關聯可透過 IModernComment::get_Shape 取得。
將現代註解錨定於圖形
此範例呼叫 AddModernComment 兩次:一次傳入 nullptr 形狀以建立投影片層級註解,另一次傳入矩形作為錨點。呼叫 get_Shape 會對投影片層級註解的 null 檢查印出 True,對錨定的註解則印出 Revenue title。兩個註解皆會隨簡報一起儲存。
#include <DOM/IAutoShape.h>
#include <DOM/ICommentAuthor.h>
#include <DOM/ICommentAuthorCollection.h>
#include <DOM/ICommentCollection.h>
#include <DOM/IModernComment.h>
#include <DOM/IShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/point_f.h>
#include <system/console.h>
#include <system/date_time.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto author = presentation->get_CommentAuthors()->AddAuthor(u"Reviewer", u"RV");
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50.0f, 50.0f, 300.0f, 80.0f);
shape->set_Name(u"Revenue title");
shape->get_TextFrame()->set_Text(u"Quarterly revenue");
auto createdTime = DateTime::get_Now();
auto slideCommentPosition = PointF(20.0f, 20.0f);
auto shapeCommentPosition = PointF(60.0f, 60.0f);
auto slideComment = author->get_Comments()->AddModernComment(u"Review the overall slide layout.", slide, nullptr, slideCommentPosition, createdTime);
auto shapeComment = author->get_Comments()->AddModernComment(u"Check this title.", slide, shape, shapeCommentPosition, createdTime);
Console::WriteLine(slideComment->get_Shape() == nullptr);
auto shapeAnchor = shapeComment->get_Shape();
if (shapeAnchor != nullptr)
{
Console::WriteLine(shapeAnchor->get_Name());
}
presentation->Save(u"modern_comments.pptx", SaveFormat::Pptx);
將註解錨定於不同類型的圖形
任何實作了 IShape 的投影片物件皆可作為圖形錨點。常見範例包括 IAutoShape、IPictureFrame、IGroupShape、IConnector,以及如圖表等 IGraphicalObject 實例。
此範例使用 AddModernComment 為五種圖形類型各關聯一個註解:AutoShape、圖片框、群組、連接線與圖表。圖片使用內嵌影像資料,無需外部影像檔案。每個註解都有獨立的標記位置,儲存的簡報會保留所有五種圖形的關聯。
#include <DOM/Chart/ChartType.h>
#include <DOM/IChart.h>
#include <DOM/IAutoShape.h>
#include <DOM/ICommentAuthor.h>
#include <DOM/ICommentAuthorCollection.h>
#include <DOM/ICommentCollection.h>
#include <DOM/IConnector.h>
#include <DOM/IGroupShape.h>
#include <DOM/IImageCollection.h>
#include <DOM/IPictureFrame.h>
#include <DOM/IPPImage.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/point_f.h>
#include <system/convert.h>
#include <system/date_time.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto author = presentation->get_CommentAuthors()->AddAuthor(u"Reviewer", u"RV");
auto createdTime = DateTime::get_Now();
auto autoShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20.0f, 20.0f, 180.0f, 60.0f);
autoShape->get_TextFrame()->set_Text(u"AutoShape");
auto autoShapeCommentPosition = PointF(30.0f, 30.0f);
author->get_Comments()->AddModernComment(u"Comment on an AutoShape.", slide, autoShape, autoShapeCommentPosition, createdTime);
auto imageBase64 = u"iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVR4nGP8//8/AwMDEwMDAwMDAwAkBgMB/DXemwAAAABJRU5ErkJggg==";
auto imageData = Convert::FromBase64String(imageBase64);
auto image = presentation->get_Images()->AddImage(imageData);
auto pictureFrame = slide->get_Shapes()->AddPictureFrame(ShapeType::Rectangle, 220.0f, 20.0f, 120.0f, 80.0f, image);
auto pictureCommentPosition = PointF(230.0f, 30.0f);
author->get_Comments()->AddModernComment(u"Comment on a picture.", slide, pictureFrame, pictureCommentPosition, createdTime);
auto groupShape = slide->get_Shapes()->AddGroupShape();
groupShape->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 0.0f, 0.0f, 80.0f, 40.0f);
groupShape->get_Shapes()->AddAutoShape(ShapeType::Ellipse, 100.0f, 0.0f, 80.0f, 40.0f);
auto groupCommentPosition = PointF(40.0f, 150.0f);
author->get_Comments()->AddModernComment(u"Comment on a group.", slide, groupShape, groupCommentPosition, createdTime);
auto connector = slide->get_Shapes()->AddConnector(ShapeType::StraightConnector1, 220.0f, 150.0f, 140.0f, 40.0f);
auto connectorCommentPosition = PointF(240.0f, 150.0f);
author->get_Comments()->AddModernComment(u"Comment on a connector.", slide, connector, connectorCommentPosition, createdTime);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 400.0f, 20.0f, 250.0f, 180.0f);
auto chartCommentPosition = PointF(420.0f, 40.0f);
author->get_Comments()->AddModernComment(u"Comment on a graphical object.", slide, chart, chartCommentPosition, createdTime);
presentation->Save(u"modern_comment_shape_types.pptx", SaveFormat::Pptx);
將註解錨定於文字並設定其狀態
對於與 IAutoShape 關聯的現代註解, IModernComment::get_TextSelectionStart 與 IModernComment::set_TextSelectionStart 控制文字框中選取文字的起始位置。同理, IModernComment::get_TextSelectionLength 與 IModernComment::set_TextSelectionLength 控制選取的長度。這兩組方法共同將註解與 AutoShape 內特定文字範圍關聯。
IModernComment::get_Status 與 IModernComment::set_Status 方法使用 ModernCommentStatus 列舉中的值:
NotDefined— 未定義特定的現代註解狀態。Active— 註解為活躍狀態。Resolved— 註解已解決。Closed— 註解已關閉。
此範例將現代註解錨定於矩形文字中的「quarterly revenue」字詞。它先計算文字的零基索引起始位置,傳遞給 set_TextSelectionStart,再以選取的字元數呼叫 set_TextSelectionLength。之後以 Resolved 呼叫 set_Status,儲存並重新開啟簡報。四個主控台檢查應各自印出 True,確認圖形錨點、文字範圍與狀態皆已保留。
#include <DOM/IAutoShape.h>
#include <DOM/IComment.h>
#include <DOM/ICommentAuthor.h>
#include <DOM/ICommentAuthorCollection.h>
#include <DOM/ICommentCollection.h>
#include <DOM/IModernComment.h>
#include <DOM/IShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/ModernCommentStatus.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/point_f.h>
#include <system/console.h>
#include <system/date_time.h>
#include <system/object_ext.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
const String outputFile = u"modern_comment_text_anchor.pptx";
const String shapeText = u"Review the quarterly revenue forecast.";
const String selectedText = u"quarterly revenue";
auto expectedSelectionStart = shapeText.IndexOf(selectedText);
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50.0f, 50.0f, 400.0f, 100.0f);
shape->set_Name(u"Forecast text");
shape->get_TextFrame()->set_Text(shapeText);
auto author = presentation->get_CommentAuthors()->AddAuthor(u"Reviewer", u"RV");
auto commentPosition = PointF(60.0f, 60.0f);
auto comment = author->get_Comments()->AddModernComment(u"Verify this forecast wording.", slide, shape, commentPosition, DateTime::get_Now());
comment->set_TextSelectionStart(expectedSelectionStart);
comment->set_TextSelectionLength(selectedText.get_Length());
comment->set_Status(ModernCommentStatus::Resolved);
presentation->Save(outputFile, SaveFormat::Pptx);
auto reopenedPresentation = MakeObject<Presentation>(outputFile);
auto reopenedSlide = reopenedPresentation->get_Slide(0);
auto reopenedComments = reopenedSlide->GetSlideComments(nullptr);
for (auto&& reopenedComment : reopenedComments)
{
auto modernComment = AsCast<IModernComment>(reopenedComment);
if (modernComment == nullptr)
{
continue;
}
auto shapeAnchor = modernComment->get_Shape();
auto shapeMatches = shapeAnchor != nullptr && shapeAnchor->get_Name() == u"Forecast text";
auto selectionStartMatches = modernComment->get_TextSelectionStart() == expectedSelectionStart;
auto selectionLengthMatches = modernComment->get_TextSelectionLength() == selectedText.get_Length();
auto statusMatches = modernComment->get_Status() == ModernCommentStatus::Resolved;
Console::WriteLine(u"Shape anchor preserved: {0}", shapeMatches);
Console::WriteLine(u"Text selection start preserved: {0}", selectionStartMatches);
Console::WriteLine(u"Text selection length preserved: {0}", selectionLengthMatches);
Console::WriteLine(u"Resolved status preserved: {0}", statusMatches);
}
檢查現有的現代註解
此範例需要一個已包含現代註解的簡報,並印出其文字、狀態與錨點細節。要檢查時,先判斷哪些註解實作了 IModernComment,然後檢查 IModernComment::get_Shape、IModernComment::get_TextSelectionStart、IModernComment::get_TextSelectionLength、以及 IModernComment::get_Status。nullptr 形狀表示投影片層級的註解。若錨點為 IAutoShape,文字選取方法會指出該文字框內的相關範圍。
#include <DOM/IAutoShape.h>
#include <DOM/IComment.h>
#include <DOM/IModernComment.h>
#include <DOM/IShape.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/ModernCommentStatus.h>
#include <DOM/Presentation.h>
#include <system/console.h>
#include <system/object_ext.h>
using namespace Aspose::Slides;
using namespace System;
auto presentation = MakeObject<Presentation>(u"comments.pptx");
for (auto&& slide : presentation->get_Slides())
{
auto comments = slide->GetSlideComments(nullptr);
for (auto&& comment : comments)
{
auto modernComment = AsCast<IModernComment>(comment);
if (modernComment == nullptr)
{
continue;
}
Console::WriteLine(u"Slide: {0}", slide->get_SlideNumber());
Console::WriteLine(u"Text: {0}", modernComment->get_Text());
Console::WriteLine(u"Status: {0}", modernComment->get_Status());
auto shape = modernComment->get_Shape();
if (shape == nullptr)
{
Console::WriteLine(u"Anchor: slide level");
}
else
{
Console::WriteLine(u"Anchor shape: {0}", shape->get_Name());
Console::WriteLine(u"Anchor type: {0}", shape->GetType().get_Name());
auto autoShape = AsCast<IAutoShape>(shape);
if (autoShape != nullptr)
{
Console::WriteLine(u"Text selection start: {0}", modernComment->get_TextSelectionStart());
Console::WriteLine(u"Text selection length: {0}", modernComment->get_TextSelectionLength());
}
}
Console::WriteLine();
}
}
移除註解
Aspose.Slides for C++ 允許您移除簡報中全部的註解與其作者,或僅刪除選取的註解而保留其餘部分。以下範例示範兩種做法,並儲存更新後的簡報。
移除全部註解與註解作者
此範例開啟現有簡報,對每位作者呼叫 ICommentCollection::Clear,然後呼叫 ICommentAuthorCollection::Clear 以移除作者本身。儲存的簡報將不再包含任何註解或註解作者。請使用包含註解的簡報以觀察移除結果。
#include <DOM/ICommentAuthor.h>
#include <DOM/ICommentAuthorCollection.h>
#include <DOM/ICommentCollection.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>(u"example.pptx");
for (auto&& author : presentation->get_CommentAuthors())
{
author->get_Comments()->Clear();
}
presentation->get_CommentAuthors()->Clear();
presentation->Save(u"example_out.pptx", SaveFormat::Pptx);
移除特定註解
此範例在同一張投影片上建立兩個註解,並使用 GetSlideComments 依作者找出註解。它會收集文字等於「comment 1」的註解,然後呼叫 ICommentCollection::Remove,以避免在選取期間對集合進行變更。儲存的簡報僅保留「comment 2」。
#include <DOM/IComment.h>
#include <DOM/ICommentAuthor.h>
#include <DOM/ICommentAuthorCollection.h>
#include <DOM/ICommentCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <drawing/point_f.h>
#include <system/collections/list.h>
#include <system/date_time.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Drawing;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto author = presentation->get_CommentAuthors()->AddAuthor(u"Author", u"A");
auto createdTime = DateTime::get_Now();
auto firstCommentPosition = PointF(0.2f, 0.2f);
auto secondCommentPosition = PointF(0.3f, 0.2f);
author->get_Comments()->AddComment(u"comment 1", slide, firstCommentPosition, createdTime);
author->get_Comments()->AddComment(u"comment 2", slide, secondCommentPosition, createdTime);
for (auto&& commentAuthor : presentation->get_CommentAuthors())
{
auto commentsToRemove = MakeObject<List<SharedPtr<IComment>>>();
auto comments = slide->GetSlideComments(commentAuthor);
for (auto&& comment : comments)
{
if (comment->get_Text() == u"comment 1")
{
commentsToRemove->Add(comment);
}
}
for (auto&& comment : commentsToRemove)
{
commentAuthor->get_Comments()->Remove(comment);
}
}
presentation->Save(u"pres.pptx", SaveFormat::Pptx);
常見問與答
Aspose.Slides 是否支援現代註解的已解決狀態?
是的。IModernComment::get_Status 與 IModernComment::set_Status 使用 ModernCommentStatus 的值,其中包含 Resolved。此狀態會儲存在簡報中,重新開啟檔案後仍可讀取。
是否支援串聯討論(回覆鏈),且是否有限制巢狀深度?
支援。每個註解皆可參照其 parent comment,從而形成回覆鏈。API 未定義具體的巢狀深度限制。
註解標記在投影片上的位置是以哪種座標系統定義的?
標記位置採用投影片座標系統的浮點座標,讓您可以精確地將其放置於投影片上。