จัดการความคิดเห็นในงานนำเสนอด้วย C++
ภาพรวม
บทความนี้อธิบายวิธีการจัดการความคิดเห็นในงานนำเสนอด้วย Aspose.Slides โดยแสดงประเภทที่เกี่ยวข้องกับความคิดเห็นหลักและสาธิตวิธีการเพิ่มความคิดเห็นลงในสไลด์, เข้าถึงความคิดเห็นที่มีอยู่, ทำงานกับการตอบกลับ, ใช้ความคิดเห็นสมัยใหม่, และลบความคิดเห็นออกจากงานนำเสนอ
ตัวอย่างมุ่งเน้นไปที่สถานการณ์การตรวจทานและการทำงานร่วมกันทั่วไปใน PowerPoint เช่น การกำหนดความเห็นให้กับผู้เขียน, การอ่านเนื้อหาและเมตาดาต้าของความคิดเห็น, การสร้างโซ่การตอบกลับ, และการลบความเห็นทั้งหมดหรือการลบความเห็นที่เลือก
ใน PowerPoint, ความคิดเห็นจะแสดงเป็นบันทึกหรือคำอธิบายบนสไลด์ เมื่อคลิกที่ความคิดเห็น, เนื้อหาหรือข้อความของมันจะปรากฏขึ้น
ทำไมต้องเพิ่มความคิดเห็นในงานนำเสนอ?
คุณอาจต้องการใช้ความคิดเห็นเพื่อให้ข้อเสนอแนะหรือสื่อสารกับเพื่อนร่วมงานเมื่อคุณตรวจทานงานนำเสนอ
เพื่อให้คุณสามารถใช้ความคิดเห็นในงานนำเสนอ PowerPoint, Aspose.Slides for C++ มีให้
- The Presentation class, ซึ่งประกอบด้วยคอลเลกชันของผู้เขียน (จากเมธอด get_CommentAuthors()). ผู้เขียนจะเพิ่มความคิดเห็นลงในสไลด์
- The ICommentCollection interface, ซึ่งประกอบด้วยคอลเลกชันของความคิดเห็นสำหรับผู้เขียนแต่ละคน
- The IComment class, ซึ่งประกอบด้วยข้อมูลของผู้เขียนและความคิดเห็นของพวกเขา: ผู้ที่เพิ่มความคิดเห็น, เวลาเพิ่มความคิดเห็น, ตำแหน่งของความคิดเห็น, เป็นต้น
- The CommentAuthor class, ซึ่งประกอบด้วยข้อมูลของผู้เขียนแต่ละคน: ชื่อผู้เขียน, ชื่อย่อ, ความคิดเห็นที่เชื่อมโยงกับชื่อผู้เขียน, เป็นต้น
เพิ่มความคิดเห็นในสไลด์
โค้ด C++ นี้แสดงวิธีเพิ่มความคิดเห็นในสไลด์ของงานนำเสนอ PowerPoint:
// สร้างตัวอย่างของคลาส Presentation
auto presentation = System::MakeObject<Presentation>();
// เพิ่มสไลด์เปล่า
presentation->get_Slides()->AddEmptySlide(presentation->get_LayoutSlides()->idx_get(0));
// เพิ่มผู้เขียน
auto author = presentation->get_CommentAuthors()->AddAuthor(u"Jawad", u"MF");
// ตั้งค่าตำแหน่งสำหรับความคิดเห็น
PointF point;
point.set_X(0.2f);
point.set_Y(0.2f);
// เข้าถึง ISlide 1
auto slide1 = presentation->get_Slides()->idx_get(0);
// เข้าถึง ISlide 2
auto slide2 = presentation->get_Slides()->idx_get(1);
// เพิ่มความคิดเห็นสไลด์สำหรับผู้เขียนบนสไลด์ 1
author->get_Comments()->AddComment(u"Hello Jawad, this is slide comment", slide1, point, DateTime::get_Now());
// เพิ่มความคิดเห็นสไลด์สำหรับผู้เขียนบนสไลด์ 2
author->get_Comments()->AddComment(u"Hello Jawad, this is second slide comment", slide2, point, DateTime::get_Now());
// เมื่อส่งค่า null เป็นอาร์กิวเมนต์, ความคิดเห็นจากผู้เขียนทั้งหมดจะถูกนำมาที่สไลด์ที่เลือก
auto comments = slide1->GetSlideComments(author);
// เข้าถึงความคิดเห็นที่ตำแหน่ง 0 สำหรับสไลด์ 1
String str = comments[0]->get_Text();
presentation->Save(u"Comments_out.pptx", SaveFormat::Pptx);
if (comments->GetLength(0) > 0)
{
// เลือกคอลเลกชันความคิดเห็นของผู้เขียนที่ตำแหน่ง 0
auto commentCollection = comments[0]->get_Author()->get_Comments();
String Comment = commentCollection->idx_get(0)->get_Text();
}
เข้าถึงความคิดเห็นในสไลด์
โค้ด C++ นี้แสดงวิธีเข้าถึงความคิดเห็นที่มีอยู่บนสไลด์ของงานนำเสนอ PowerPoint:
// สร้างอินสแตนซ์ของคลาส Presentation
auto presentation = System::MakeObject<Presentation>(u"Comments1.pptx");
for (auto&& commentAuthor : presentation->get_CommentAuthors())
{
auto author = System::ExplicitCast<CommentAuthor>(commentAuthor);
for (auto&& comment1 : System::IterateOver(author->get_Comments()))
{
SmartPtr<Comment> comment = System::ExplicitCast<Comment>(comment1);
Console::WriteLine(String(u"ISlide :")
+ comment->get_Slide()->get_SlideNumber()
+ u" has comment: " + comment->get_Text()
+ u" with Author: " + comment->get_Author()->get_Name()
+ u" posted on time :" + comment->get_CreatedTime() + u"\n");
}
}
ตอบกลับความคิดเห็น
ความเห็นแม่คือความเห็นหลักหรือความเห็นต้นฉบับในลำดับชั้นของความคิดเห็นหรือการตอบกลับ โดยใช้คุณสมบัติ ParentComment (จากอินเทอร์เฟส IComment) คุณสามารถตั้งหรือรับความเห็นแม่ได้
โค้ด C++ นี้แสดงวิธีเพิ่มความคิดเห็นและรับการตอบกลับต่อความคิดเห็น:
auto pres = System::MakeObject<Presentation>();
// เข้าถึง ISlide 1
auto slide1 = pres->get_Slides()->idx_get(0);
// เพิ่มความคิดเห็น
auto author1 = pres->get_CommentAuthors()->AddAuthor(u"Author_1", u"A.A.");
auto comment1 = author1->get_Comments()->AddComment(u"comment1", slide1, PointF(10.0f, 10.0f), DateTime::get_Now());
// เพิ่มการตอบกลับให้กับ comment1
auto author2 = pres->get_CommentAuthors()->AddAuthor(u"Autror_2", u"B.B.");
auto reply1 = author2->get_Comments()->AddComment(u"reply 1 for comment 1", slide1, PointF(10.0f, 10.0f), DateTime::get_Now());
reply1->set_ParentComment(comment1);
// เพิ่มการตอบกลับอีกรายการให้กับ comment1
auto reply2 = author2->get_Comments()->AddComment(u"reply 2 for comment 1", slide1, PointF(10.0f, 10.0f), DateTime::get_Now());
reply2->set_ParentComment(comment1);
// เพิ่มการตอบกลับให้กับการตอบกลับที่มีอยู่
auto subReply = author1->get_Comments()->AddComment(u"subreply 3 for reply 2", slide1, PointF(10.0f, 10.0f), DateTime::get_Now());
subReply->set_ParentComment(reply2);
auto comment2 = author2->get_Comments()->AddComment(u"comment 2", slide1, PointF(10.0f, 10.0f), DateTime::get_Now());
auto comment3 = author2->get_Comments()->AddComment(u"comment 3", slide1, PointF(10.0f, 10.0f), DateTime::get_Now());
auto reply3 = author1->get_Comments()->AddComment(u"reply 4 for comment 3", slide1, PointF(10.0f, 10.0f), DateTime::get_Now());
reply3->set_ParentComment(comment3);
// แสดงลำดับความสำคัญของความคิดเห็นบนคอนโซล
auto comments = slide1->GetSlideComments(nullptr);
for (int32_t 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::Write(u"{0} : {1}", comments[i]->get_Author()->get_Name(), comments[i]->get_Text());
Console::WriteLine();
}
pres->Save(u"parent_comment.pptx", SaveFormat::Pptx);
// ลบ comment1 และการตอบกลับทั้งหมดของมัน
comment1->Remove();
pres->Save(u"remove_comment.pptx", SaveFormat::Pptx);
Attention
- เมื่อเมธอด Remove (จากอินเทอร์เฟส IComment) ถูกใช้เพื่อลบความเห็น, การตอบกลับของความเห็นนั้นก็จะถูกลบด้วย
- ถ้าการตั้งค่า ParentComment ทำให้เกิดการอ้างอิงแบบวนรอบ, จะขว้างข้อยกเวลาด PptxEditException
เพิ่มความคิดเห็นสมัยใหม่
ในปี 2021, Microsoft ได้นำเสนอ modern comments ใน PowerPoint คุณลักษณะ modern comments ช่วยปรับปรุงการทำงานร่วมกันใน PowerPoint อย่างมีนัยสำคัญ ผ่าน modern comments ผู้ใช้ PowerPoint สามารถทำการแก้ไขความคิดเห็น, ผูกความคิดเห็นกับวัตถุและข้อความ, และมีปฏิสัมพันธ์ได้ง่ายกว่าที่เคย
ใน Aspose Slides for C++ 21.11 เราได้เพิ่มการสนับสนุน modern comments โดยเพิ่มคลาส ModernComment เมธอด AddModernComment และ InsertModernComment ถูกเพิ่มเข้าไปในคลาส CommentCollection
โค้ด C++ นี้แสดงวิธีเพิ่มความคิดเห็นสมัยใหม่ในสไลด์ของงานนำเสนอ PowerPoint:
auto pres = System::MakeObject<Presentation>();
// เข้าถึง ISlide 1
auto slide1 = pres->get_Slides()->idx_get(0);
auto newAuthor = pres->get_CommentAuthors()->AddAuthor(u"Some Author", u"SA");
auto modernComment = newAuthor->get_Comments()->AddModernComment(u"This is a modern comment", slide1, nullptr, PointF(100.0f, 100.0f), DateTime::get_Now());
pres->Save(u"pres.pptx", SaveFormat::Pptx);
ลบความคิดเห็น
ลบความคิดเห็นและผู้เขียนทั้งหมด
โค้ด C++ นี้แสดงวิธีลบความคิดเห็นและผู้เขียนทั้งหมดในงานนำเสนอ:
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;
auto presentation = System::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);
ลบความคิดเห็นเฉพาะ
โค้ด C++ นี้แสดงวิธีลบความคิดเห็นเฉพาะบนสไลด์:
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slides()->idx_get(0);
// เพิ่มความคิดเห็น...
auto author = presentation->get_CommentAuthors()->AddAuthor(u"Author", u"A");
author->get_Comments()->AddComment(u"comment 1", slide, PointF(0.2f, 0.2f), System::DateTime::get_Now());
author->get_Comments()->AddComment(u"comment 2", slide, PointF(0.3f, 0.2f), System::DateTime::get_Now());
// ลบความคิดเห็นทั้งหมดที่มีข้อความ "comment 1"
for (auto commentAuthor : presentation->get_CommentAuthors())
{
auto toRemove = System::MakeObject<System::Collections::Generic::List<System::SharedPtr<IComment>>>();
for (auto comment : slide->GetSlideComments(commentAuthor))
{
if (comment->get_Text() == u"comment 1")
{
toRemove->Add(comment);
}
}
for (auto comment : toRemove)
{
commentAuthor->get_Comments()->Remove(comment);
}
}
presentation->Save(u"pres.pptx", SaveFormat::Pptx);
คำถามที่พบบ่อย
Aspose.Slides รองรับสถานะเช่น ‘resolved’ สำหรับความคิดเห็นสมัยใหม่หรือไม่?
ใช่. Modern comments มีเมธอด get_Status และ set_Status คุณสามารถอ่านและตั้งค่าสถานะของความคิดเห็น (เช่น ทำเครื่องหมายว่า resolved) ได้ และสถานะนี้จะถูกบันทึกในไฟล์และ PowerPoint จะรับรู้
รองรับการสนทนาแบบเธรด (โซ่การตอบกลับ) หรือไม่, และมีขีดจำกัดการซ้อนกันหรือไม่?
รองรับ. ความคิดเห็นแต่ละรายการสามารถอ้างอิงถึง parent comment ทำให้สามารถสร้างโซ่การตอบกลับได้โดยไม่จำกัดระดับความลึกเฉพาะ
ตำแหน่งของเครื่องหมายความคิดเห็นบนสไลด์กำหนดในระบบพิกัดใด?
ตำแหน่งถูกเก็บเป็นจุดเชิงลอยในระบบพิกัดของสไลด์ ซึ่งทำให้คุณสามารถวางเครื่องหมายความคิดเห็นได้อย่างแม่นยำตามที่ต้องการ