In Microsoft PowerPoint, a comment is a note that you can attach to a phrase or paragraph on a slide. Viewing comments added by the author, readers can learn more information about the content. Likewise, readers can also add comments to provide reviews or feedbacks to the author. In this article, you will learn how to programmatically add or remove comments in a PowerPoint slide using Spire.Presentation for .NET.
Install Spire.Presentation for .NET
To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Presentation
Add Comments to a Presentation Slide
The detailed steps are as follows:
- Create a Presentation instance.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Get CommentAuthor List using Presentation.CommentAuthors property.
- Add the author of the comment using CommentAuthorList.AddAuthor() method.
- Get a specified slide using Presentation.Slides[] property, and then add a comment to the slide using ISlide.AddComment(ICommentAuthor, String, PointF, DateTime) method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; using System; namespace AddComment { class Program { static void Main(string[] args) { //Create a Presentation instance Presentation presentation = new Presentation(); //Load a PowerPoint document presentation.LoadFromFile(@"D:\Files\Test.pptx"); //Add the author of the comment ICommentAuthor author = presentation.CommentAuthors.AddAuthor("E-iceblue", "comment:"); //Add a comment to the specified slide presentation.Slides[0].AddComment(author, "Summary of Spire.Presentation functions", new System.Drawing.PointF(25, 22), DateTime.Now); //Save the document presentation.SaveToFile("comment.pptx", FileFormat.Pptx2010); } } }
Remove Comments from a Presentation Slide
The detailed steps are as follows:
- Create a Presentation instance.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Get a specified slide using Presentation.Slides[] property.
- Remove comment from the specified slide using ISlide.DeleteComment(Comment) method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; namespace RemoveComment { class Program { static void Main(string[] args) { //Create a Presentation instance Presentation presentation = new Presentation(); //Load a PowerPoint document presentation.LoadFromFile("comment.pptx"); //Get the first slide ISlide slide = presentation.Slides[0]; //Remove comment from the specified slide slide.DeleteComment(slide.Comments[0]); //Save the document presentation.SaveToFile("RemoveComment.pptx", FileFormat.Pptx2010); } } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.