How C # Extracts text from SmartArt text and annotations in PPT

Source: Internet
Author: User

The extraction of text is often encountered in work and study, in the previous article, has described how to extract the text in the ppt Chinese box, in this article, will explain how to use the C # code language to extract the text of SmartArt and annotations in the PPT document. Similarly, the program needs to use the spire.ppt for. NET, before writing the code, you need to install, and add reference DLL files into the project program.

1. extracting text from a SmartArt

Original file:

A SmartArt graphic is inserted in slide 2, containing text content

1 usingSpire.Presentation.Diagrams;2 usingSystem.Drawing;3 usingSystem.Text;4 usingSystem.IO;5 usingspire.presentation;6 7 namespaceextracttextfromsmartart_ppt8 {9     class ProgramTen     { One         Static voidMain (string[] args) A         { -             //Initializes an instance of the presentation class and loads the document -Presentation ppt =NewPresentation (); thePpt. LoadFromFile (@"C:\Users\Administrator\Desktop\Sample.pptx"); -             //Create a new StringBuilder object -StringBuilder st =NewStringBuilder (); -             //Traverse a SmartArt graphic in a document +              for(inti =0; I < ppt. Slides.count; i++) -             { +                  for(intj =0; J < ppt. Slides[i]. Shapes.count; J + +) A                 { at                     if(PPT. Slides[i]. SHAPES[J] isIsmartart) -                     { -Ismartart smartArt = ppt. Slides[i]. SHAPES[J] asIsmartart; -                          for(intK =0; K < SmartArt.Nodes.Count; k++) -                         { - St. Append (Smartart.nodes[k]. Textframe.text); in                         } -                     } to                 } +             } -             //writing text to a TXT document theFile.writealltext ("Result.txt", St. ToString ()); *         } $     }Panax Notoginseng}

The extracted text is as follows:

2. extracting text from annotations

Original file:

on slide 1 , a comment is inserted that contains the text content

1 usingSystem;2 usingSystem.Text;3 usingspire.presentation;4 usingSystem.IO;5 6 namespaceextracttextfromcomment_ppt7 {8     class Program9     {Ten         Static voidMain (string[] args) One         { A             //instantiates a presentation class and loads the document -Presentation ppt =NewPresentation (); -Ppt. LoadFromFile (@"C:\Users\Administrator\Desktop\comment.pptx"); the             //Create a StringBuilder object -StringBuilder str =NewStringBuilder (); -             //get all annotations on the first slide -Comment[] comments = ppt. slides[0]. Comments; +             //Traverse Annotation Content -              for(inti =0; I < comments. Length; i++) +             { AStr. Append (Comments[i]. Text +"\ r \ n"); at             } -             //writing text to a TXT document -File.writealltext ("TextFromComment.txt", str. ToString ()); -         } -     } -}

The above method is to extract ppt SmartArt and annotated text in the implementation of the method for reference, I hope to help you, thank you for reading!

(End of this article)

How C # Extracts text from SmartArt text and annotations in PPT

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.