C # how to extract the text in the SmartArt text and comments in the PPT,

Source: Internet
Author: User

C # how to extract the text in the SmartArt text and comments in the PPT,

Text Extraction is often encountered in work and study. In the previous article, we have already described how to extract the text in the text box in the PPT. In this article, this section describes how to extract the text in SmartArt and comments in the PPT document using C # code language. Similarly, Spire. PPT for. NET needs to be used in the program. before writing code, install it and add the reference dll file to the project program.

1.Extract SmartArtText in

Original file:

A SmartArt image is inserted in Slide 2, containing text content.

1 using Spire. presentation. diagrams; 2 using System. drawing; 3 using System. text; 4 using System. IO; 5 using Spire. presentation; 6 7 namespace ExtractTextFromSmartArt_PPT 8 {9 class Program10 {11 static void Main (string [] args) 12 {13 // initialize a Presentation class instance, and load 14 Presentation ppt = new Presentation (); 15 ppt. loadFromFile (@ "C: \ Users \ Administrator \ Desktop \ Sample.pptx"); 16 // create a StringBuilder object 17 StringBuilder st = new StringBuilder (); 18 // traverse the SmartArt Graph 19 for (int I = 0; I <ppt. slides. count; I ++) 20 {21 for (int j = 0; j <ppt. slides [I]. shapes. count; j ++) 22 {23 if (ppt. slides [I]. shapes [j] is ISmartArt) 24 {25 ISmartArt smartArt = ppt. slides [I]. shapes [j] as ISmartArt; 26 for (int k = 0; k <smartArt. nodes. count; k ++) 27 {28 st. append (smartArt. nodes [k]. textFrame. text); 29} 30} 31} 32} 33 // write the Text to the TXT File 34 File. writeAllText ("Result.txt", st. toString (); 35} 36} 37}

The extracted text is shown in:

 

2.Extract text from comments

Original file:

In Slide 1, Insert comments, including text content

1 using System; 2 using System. text; 3 using Spire. presentation; 4 using System. IO; 5 6 namespace ExtractTextFromComment_PPT 7 {8 class Program 9 {10 static void Main (string [] args) 11 {12 // instantiate a Presentation class, load the file 13 Presentation ppt = new Presentation (); 14 ppt. loadFromFile (@ "C: \ Users \ Administrator \ Desktop \ comment.pptx"); 15 // create a StringBuilder object 16 StringBuilder str = new StringBuilder (); 17 // obtain all comments 18 Comment [] comments = ppt In the first slide. slides [0]. comments; 19 // traverse the annotation content 20 for (int I = 0; I <comments. length; I ++) 21 {22 str. append (comments [I]. text + "\ r \ n"); 23} 24 // write the Text to the TXT document 25 File. writeAllText ("TextFromComment.txt", str. toString (); 26} 27} 28}

 

The above method is to extract the text in the PPT SmartArt and comments for your reference. I hope it will help you. Thank you for reading!

 

(This article is complete)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.