C#如何提取PPT中 SmartArt文本和批註中的文本

來源:互聯網
上載者:User

標籤:.net   c#   ppt   批註   提取文本   

提取文本的情況在工作和學習中常會遇到,在前面的文章中,已經講述了如何提取PPT中文字框裡的文本,在本篇文章中,將介紹如何使用C#代碼語言提取PPT文檔中SmartArt和批註中的文本。同樣的,程式裡面需要使用到 Free Spire.PPT for .NET,在編寫代碼前,需先安裝,並添引用dll檔案到項目程式中,同時也要添加到命名空間。

1.提取SmartArt中的文本

原始檔案:

650) this.width=650;" src="https://s1.51cto.com/oss/201711/09/e5592c7e7e9792816ed7d2650a9e288f.png" style="float:none;" title="21.png" alt="e5592c7e7e9792816ed7d2650a9e288f.png" />

(在投影片2中插入了SmartArt圖形,包含常值內容)

using Spire.Presentation.Diagrams;using System.Drawing;using System.Text;using System.IO;using Spire.Presentation; namespaceExtractTextFromSmartArt_PPT{    classProgram    {        staticvoid Main(string[] args)        {            //初始化一個Presentation類執行個體,並載入文檔            Presentation ppt = newPresentation();            ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\Sample.pptx");            //建立一個StringBuilder對象            StringBuilder st = newStringBuilder();            //遍曆文檔中的SmartArt圖形            for (int i = 0; i <ppt.Slides.Count; i++)            {                for (int j = 0; j <ppt.Slides[i].Shapes.Count; j++)                {                    if(ppt.Slides[i].Shapes[j] isISmartArt)                    {                       ISmartArt smartArt = ppt.Slides[i].Shapes[j] asISmartArt;                       for (int k = 0; k < smartArt.Nodes.Count; k++)                       {                           st.Append(smartArt.Nodes[k].TextFrame.Text);                        }                    }                }            }            //將文本寫入TXT文檔            File.WriteAllText("Result.txt", st.ToString());        }    }}


效果樣本如:

650) this.width=650;" src="https://s1.51cto.com/oss/201711/09/362631ddecdc0579887bd9b3db14f094.png" style="float:none;" title="22.png" alt="362631ddecdc0579887bd9b3db14f094.png" />


2.提取批註中的文本


原檔案:

650) this.width=650;" src="https://s1.51cto.com/oss/201711/09/195746d7b43e7f699440fa1c62266cbd.png" style="float:none;" title="23.png" alt="195746d7b43e7f699440fa1c62266cbd.png" />

在投影片1中,插入了批註,包含常值內容

using System;using System.Text;using Spire.Presentation;using System.IO; namespaceExtractTextFromComment_PPT{    classProgram    {        staticvoid Main(string[] args)        {            //執行個體化一個Presentation類,並載入文檔            Presentation ppt = newPresentation();           ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\comment.pptx");            //建立一個StringBuilder對象            StringBuilder str = newStringBuilder();            //擷取第一張投影片中的所有批註            Comment[] comments =ppt.Slides[0].Comments;            //遍曆批註內容            for (int i = 0; i <comments.Length; i++)            {               str.Append(comments[i].Text + "\r\n");            }            //將文本寫入TXT文檔            File.WriteAllText("TextFromComment.txt", str.ToString());        }    }}

效果樣本:

650) this.width=650;" src="https://s1.51cto.com/oss/201711/09/38321bc1893888785c2f77bcbcfece8e.png" style="float:none;" title="24.png" alt="38321bc1893888785c2f77bcbcfece8e.png" />


以上方法是提取PPT SmartArt和批註中文本的實現方法,供參考,希望能對您有所協助,感謝閱讀!

 

(本文完)


本文出自 “E-iceblue” 部落格,請務必保留此出處http://eiceblue.blog.51cto.com/13438008/1980186

C#如何提取PPT中 SmartArt文本和批註中的文本

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.