Comment
内容
[
隐藏
]Comment 类
表示幻灯片上的评论。
public class Comment : IComment
属性
| 名称 | 描述 |
|---|---|
| Author { get; } | 返回评论的作者。只读 ICommentAuthor。 |
| CreatedTime { get; set; } | 返回或设置评论创建的时间。将此属性设置为 MinValue 表示未设置评论时间。读/写 DateTime。 |
| ParentComment { get; set; } | 获取或设置父评论。读/写 IComment。 |
| Position { get; set; } | 返回或设置评论在幻灯片上的位置。读/写 PointF。 |
| Slide { get; } | 返回或设置评论的父幻灯片。只读 ISlide。 |
| Text { get; set; } | 返回或设置幻灯片评论的纯文本。读/写 String。 |
方法
| 名称 | 描述 |
|---|---|
| Remove() | 从父集合中删除评论及其所有回复。 |
示例
此示例演示如何在 PowerPoint 演示文稿的幻灯片上添加评论。
[C#]
// 实例化 Presentation 类
using (Presentation presentation = new Presentation())
{
// 添加空幻灯片
presentation.Slides.AddEmptySlide(presentation.LayoutSlides[0]);
// 添加作者
ICommentAuthor author = presentation.CommentAuthors.AddAuthor("Jawad", "MF");
// 设置评论的位置
PointF point = new PointF();
point.X = 0.2f;
point.Y = 0.2f;
// 为作者在第 1 张幻灯片添加评论
author.Comments.AddComment("Hello Jawad, this is slide comment", presentation.Slides[0], point, DateTime.Now);
// 为作者在第 2 张幻灯片添加评论
author.Comments.AddComment("Hello Jawad, this is second slide comment", presentation.Slides[1], point, DateTime.Now);
// 保存 PowerPoint 演示文稿文件
presentation.Save("Comments_out.pptx", SaveFormat.Pptx);
}
此示例演示如何访问 PowerPoint 演示文稿中幻灯片上的现有评论。
[C#]
// 实例化 Presentation 类
using (Presentation presentation = new Presentation("Comments1.pptx"))
{
// 遍历 CommentAuthors
foreach (var commentAuthor in presentation.CommentAuthors)
{
var author = (CommentAuthor) commentAuthor;
// 遍历 Comments
foreach (var comment1 in author.Comments)
{
var comment = (Comment) comment1;
Console.WriteLine("ISlide :" + comment.Slide.SlideNumber + " has comment: " + comment.Text + " with Author: " + comment.Author.Name + " posted on time :" + comment.CreatedTime + "\n");
}
}
}
此示例演示如何添加评论并获取其回复。
[C#]
// 实例化 Presentation 类
using (Presentation pres = new Presentation())
{
// 添加评论
ICommentAuthor author1 = pres.CommentAuthors.AddAuthor("Author_1", "A.A.");
IComment comment1 = author1.Comments.AddComment("comment1", pres.Slides[0], new PointF(10, 10), DateTime.Now);
// 为 comment1 添加回复
ICommentAuthor author2 = pres.CommentAuthors.AddAuthor("Autror_2", "B.B.");
IComment reply1 = author2.Comments.AddComment("reply 1 for comment 1", pres.Slides[0], new PointF(10, 10), DateTime.Now);
reply1.ParentComment = comment1;
// 为 comment1 添加另一个回复
IComment reply2 = author2.Comments.AddComment("reply 2 for comment 1", pres.Slides[0], new PointF(10, 10), DateTime.Now);
reply2.ParentComment = comment1;
// 为已有回复添加回复
IComment subReply = author1.Comments.AddComment("subreply 3 for reply 2", pres.Slides[0], new PointF(10, 10), DateTime.Now);
subReply.ParentComment = reply2;
IComment comment2 = author2.Comments.AddComment("comment 2", pres.Slides[0], new PointF(10, 10), DateTime.Now);
IComment comment3 = author2.Comments.AddComment("comment 3", pres.Slides[0], new PointF(10, 10), DateTime.Now);
IComment reply3 = author1.Comments.AddComment("reply 4 for comment 3", pres.Slides[0], new PointF(10, 10), DateTime.Now);
reply3.ParentComment = comment3;
// 在控制台显示评论层级
ISlide slide = pres.Slides[0];
var comments = slide.GetSlideComments(null);
for (int i = 0; i < comments.Length; i++)
{
IComment comment = comments[i];
while (comment.ParentComment != null)
{
Console.Write("\t");
comment = comment.ParentComment;
}
Console.Write("{0} : {1}", comments[i].Author.Name, comments[i].Text);
Console.WriteLine();
}
pres.Save("parent_comment.pptx",SaveFormat.Pptx);
// 删除 comment1 及其所有回复
comment1.Remove();
pres.Save("remove_comment.pptx", SaveFormat.Pptx);
}
另请参见
- 接口 IComment
- 命名空间 Aspose.Slides
- 程序集 Aspose.Slides