在C#裏面給PPT添加註釋

日常開會或者作總結報告的時候咱們一般都會用到PowerPoint演示文稿,咱們能夠在單個幻燈片或者所有幻燈片裏面添加註釋,這樣觀衆能夠從註釋內容裏面獲取更多的相關信息。html

有些朋友不清楚如何在幻燈片裏面添加註釋,下面我跟你們分享一下如何在C#裏面爲幻燈片添加註釋。ide

在這裏我使用了一個免費控件——Free Spire.Presentation,有興趣的朋友能夠下載使用。 spa

 

須要添加的命名空間:component

using Spire.Presentation; 
using System.Drawing;

 

詳細步驟和代碼片斷以下:orm

 

步驟1新建一個Presentation對象,從系統裏面加載Presentation文件。htm

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

 

步驟2調用CommentAuthorList.AddAuthor(author name, string initials) 方法來添加做者註釋。對象

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

 

步驟3調用Call presentation.Slides[].AddComment() 方法來給某一張特定幻燈片添加註解。註釋的類包含不少信息,像添加註釋的做者、添加註釋的時間、添加註釋的位置和註釋的內容。blog

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

 

步驟4保存並從新打開Presentation演示文稿。get

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

 

效果圖:string

所有代碼:

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");
        }
    }
}
相關文章
相關標籤/搜索