Home  >  Article  >  Backend Development  >  Code sharing for adding comments to PPT documents in C#

Code sharing for adding comments to PPT documents in C#

黄舟
黄舟Original
2017-03-25 11:40:081459browse

We usually use PowerPoint presentations when holding meetings or making summary reports. We can add comments to a single slide or all slides, so that the audience can get more relevant information from the comment content, as needed Friends can refer to

We usually use PowerPoint presentations when holding meetings or making summary reports. We can add comments to a single slide or all slides, so that the audience can get more information from the comments. Lots of relevant information.

Some friends don’t know how to add comments to slides. Let me share with you how to add comments to slides in C#.

Here I used a free control - Free Spire.Presentation. Friends who are interested can download and use it.

Namespace that needs to be added:

using Spire.Presentation;
using System.Drawing;

The detailed steps and code snippets are as follows:

Step 1: Create a new PresentationObject, load the Presentation file from the system.

Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx");

Step 2: Call the CommentAuthorList.AddAuthor(author name, string initials) method to add author comments.

ICommentAuthor author = presentation.CommentAuthors.AddAuthor("E-iceblue", "comment:");

Step 3: Call the Call presentation.Slides[].AddComment() method to add comments to a specific slide. The annotated class contains a lot of information, such as the author who added the annotation, the time when the annotation was added, the location where the annotation was added, and the content of the annotation.

presentation.Slides[1].AddComment(author, "This part is pretty important. 
Please pay attention to it", new System.Drawing.PointF(42, 4), DateTime.Now);

Step 4: Save and reopen the Presentation presentation.

presentation.SaveToFile("PPTwithcomment.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("PPTwithcomment.pptx");

Rendering:

All codes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Presentation;
 
namespace PPTComment
{
  class Program
  {
    static void Main(string[] args)
    {
      //create PPT document and load file
      Presentation presentation = new Presentation();
      presentation.LoadFromFile("sample.pptx");
      //comment author
      ICommentAuthor author = presentation.CommentAuthors.AddAuthor("E-iceblue", "comment:");
      //add comment
      presentation.Slides[1].AddComment(author, "This part is pretty important. Please pay attention to it", new System.Drawing.PointF(42, 4), DateTime.Now);
      //save the document
      presentation.SaveToFile("PPTwithcomment.pptx", FileFormat.Pptx2010);
      System.Diagnostics.Process.Start("PPTwithcomment.pptx");
    }
  }
}

The above is the detailed content of Code sharing for adding comments to PPT documents in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn