首頁  >  文章  >  後端開發  >  在C#裡面給PPT文檔實現添加註解的程式碼分享

在C#裡面給PPT文檔實現添加註解的程式碼分享

黄舟
黄舟原創
2017-03-25 11:40:081453瀏覽

平常開會或做總結報告的時候我們通常都會用到PowerPoint演示文稿,我們可以在單個幻燈片或全部幻燈片裡面添加註釋,這樣觀眾可以從註釋內容裡面獲取更多的相關信息,需要的朋友可以參考下

平常開會或做總結報告的時候我們通常都會用到PowerPoint演示文稿,我們可以在單個幻燈片或全部幻燈片裡面添加註釋,這樣觀眾可以從註釋內容裡面獲取更多的相關資訊。

有些朋友不清楚如何在投影片裡面加入註釋,下面我跟大家分享如何在C#裡面為投影片加入註解。

在這裡我使用了一個免費控制項-Free Spire.Presentation,有興趣的朋友可以下載使用。

需要新增的命名空間

using Spire.Presentation;
using System.Drawing;

詳細步驟與程式碼片段如下:

步驟1:新建一個Presentation物件,從系統裡面載入Presentation檔案。

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() 方法來為某一張特定投影片新增註解。註釋的類別包含許多訊息,像是添加註釋的作者、添加註釋的時間、添加註釋的位置和註釋的內容。

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簡報。

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

效果圖:

全部程式碼:

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

以上是在C#裡面給PPT文檔實現添加註解的程式碼分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn