Cách thêm nhận xét vào PowerPoint trong .NET

Cách thêm nhận xét vào PowerPoint trong .NET

Aspose.Slides FOSS for .NET hỗ trợ hai cơ chế chú thích:

  • Nhận xét theo luồng: gắn vào một slide ở vị trí cụ thể, hiển thị trong ngăn Xem xét của PowerPoint
  • Ghi chú thuyết trình: văn bản theo từng slide hiển thị trong Chế độ Thuyết trình và ngăn Ghi chú

Điều kiện tiên quyết

dotnet add package Aspose.Slides.Foss

Thêm nhận xét

Nhận xét thuộc về đối tượng author. Tạo một tác giả trước, sau đó thêm nhận xét qua 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);

Tọa độ PointF tính bằng inch từ góc trên bên trái của slide. Nhiều lần gọi AddComment() tạo ra một chuỗi nhận xét theo luồng dưới cùng một tác giả.


Nhiều tác giả và nhận xét

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);

Đọc nhận xét từ tệp hiện có

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}");
    }
}

Thêm ghi chú thuyết trình vào slide

Ghi chú thuyết trình được thêm qua 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);

Thêm ghi chú vào nhiều slide

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);

Kiểm tra xem ghi chú đã tồn tại chưa

NotesSlideManager.NotesSlide trả về null nếu chưa tạo slide ghi chú:

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");
}

Xem thêm

 Tiếng Việt