locating ang extracting images inside word table

Home Forums WordprocessingML locating ang extracting images inside word table

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  Eric White 8 years, 4 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3580

    vgurunathaprasad
    Participant

    Hi,

    I am using the following code to locate image in a table.

    using (var document = WordprocessingDocument.Open(fileName, true)) {
                    var docPart = document.MainDocumentPart;
                    var doc = docPart.Document;
    
                    DocumentFormat.OpenXml.Wordprocessing.Table myTable = doc.Body.Descendants<DocumentFormat.OpenXml.Wordprocessing.Table>().First();
    
                    List<Paragraph> paras = myTable.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().ToList();
                    
                    foreach (Paragraph p in paras) {
                        string d = p.InnerXml;
                        if (d.Contains("w:drawing")) { 
                            Console.WriteLine("this paragraph contains image"); 
                            
                           //Need Code to extract the image inside the <w:drawing> element
    
                        }
                        else Console.WriteLine("this paragraph does not contains image");
                    }
                }

    Is this the right way.

    One more thing: I want to extract the image in that paragraph whenever the code finds one

    Thanks in advance.

    #3595

    Eric White
    Keymaster

    Hi,

    Personally, I would use an XML parser to find all of the descendant w:drawing elements. I would not use the strongly-typed OM of the Open-Xml-Sdk for this. I would use LINQ to XML for this.

    Your code will work, but looking through text of XML for specific patterns probably isn’t the best way to proceed.

    -Eric

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.