วิธีเพิ่มความคิดเห็นใน PowerPoint ด้วย .NET

วิธีเพิ่มความคิดเห็นใน PowerPoint ด้วย .NET

Aspose.Slides FOSS for .NET รองรับกลไกการทำหมายเหตุสองแบบ:

  • Threaded comments: แนบกับสไลด์ในตำแหน่งเฉพาะ, มองเห็นได้ในแผง Review ของ PowerPoint
  • Speaker notes: ข้อความต่อสไลด์ที่มองเห็นได้ในโหมด Presenter View และแผง Notes

ข้อกำหนดเบื้องต้น

dotnet add package Aspose.Slides.Foss

เพิ่มความคิดเห็น

ความคิดเห็นเป็นของอ็อบเจ็กต์ author. สร้างผู้เขียนก่อน แล้วเพิ่มความคิดเห็นผ่าน author.Comments:

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Drawing;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();

// Create a comment author with name and initials
var author = prs.CommentAuthors.AddAuthor("Jane Smith", "JS");

var slide = prs.Slides[0];

// Add a comment at (2.0, 2.0) inches from the slide top-left corner
author.Comments.AddComment(
    "Please review the figures on this slide",
    slide,
    new PointF(2.0f, 2.0f),
    DateTime.Now
);

prs.Save("commented.pptx", SaveFormat.Pptx);

พิกัด PointF อยู่ใน นิ้ว จากมุมซ้ายบนของสไลด์ การเรียกใช้ AddComment() หลายครั้งจะสร้างสายความคิดเห็นแบบเชือกภายใต้ผู้เขียนเดียวกัน.


ผู้เขียนหลายคนและความคิดเห็น

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Drawing;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var author1 = prs.CommentAuthors.AddAuthor("Alice Brown", "AB");
var author2 = prs.CommentAuthors.AddAuthor("Bob Davis", "BD");

var slide = prs.Slides[0];

author1.Comments.AddComment(
    "Initial draft: needs revision",
    slide, new PointF(1.0f, 1.0f), DateTime.Now
);
author2.Comments.AddComment(
    "Approved after changes",
    slide, new PointF(3.0f, 1.0f), DateTime.Now
);

prs.Save("multi-author.pptx", SaveFormat.Pptx);

อ่านความคิดเห็นจากไฟล์ที่มีอยู่

using Aspose.Slides.Foss;

using var prs = new Presentation("commented.pptx");
foreach (var author in prs.CommentAuthors)
{
    Console.WriteLine($"Author: {author.Name} ({author.Initials})");
    foreach (var comment in author.Comments)
    {
        Console.WriteLine($"  Slide: {comment.Text}");
    }
}

เพิ่มบันทึกผู้พูดลงในสไลด์

บันทึกของผู้พูดถูกเพิ่มผ่าน slide.NotesSlideManager:

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var slide = prs.Slides[0];
slide.Shapes.AddAutoShape(
    ShapeType.Rectangle, 50, 50, 600, 300
).AddTextFrame("Main slide content");

// Create the notes slide and write text
var notes = slide.NotesSlideManager.AddNotesSlide();
notes.NotesTextFrame.Text =
    "Mention the Q3 revenue increase. Emphasize the 24% YoY growth.";

prs.Save("with-notes.pptx", SaveFormat.Pptx);

เพิ่มบันทึกย่อให้หลายสไลด์

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

string[] noteTexts = {
    "Opening: introduce the agenda and set expectations.",
    "Key metrics: emphasize Q4 results and growth trajectory.",
    "Closing: summarize and call to action.",
};

using var prs = new Presentation();
var layout = prs.Slides[0].LayoutSlide;
prs.Slides.AddEmptySlide(layout);
prs.Slides.AddEmptySlide(layout);

for (int i = 0; i < prs.Slides.Count; i++)
{
    var slide = prs.Slides[i];
    slide.Shapes.AddAutoShape(
        ShapeType.Rectangle, 50, 50, 600, 300
    ).AddTextFrame($"Slide {i + 1}");

    var n = slide.NotesSlideManager.AddNotesSlide();
    n.NotesTextFrame.Text = noteTexts[i];
}

prs.Save("all-notes.pptx", SaveFormat.Pptx);

ตรวจสอบว่าบันทึกมีอยู่แล้วหรือไม่

NotesSlideManager.NotesSlide จะคืนค่า null หากไม่มีสไลด์บันทึกที่สร้างขึ้น:

using Aspose.Slides.Foss;

using var prs = new Presentation("existing.pptx");
for (int i = 0; i < prs.Slides.Count; i++)
{
    var existing = prs.Slides[i].NotesSlideManager.NotesSlide;
    if (existing != null)
        Console.WriteLine($"Slide {i + 1}: {existing.NotesTextFrame.Text[..60]}");
    else
        Console.WriteLine($"Slide {i + 1}: no notes");
}

ดูเพิ่มเติม

 ภาษาไทย