wordpress hit counter
Re: How to identify a necessary table located in DOCX via OpenXML SDK? - WordprocessingML - Formats - OpenXML Developer

Re: How to identify a necessary table located in DOCX via OpenXML SDK?

Formats

Discussions about working with different Open XML Formats

How to identify a necessary table located in DOCX via OpenXML SDK?

  • rated by 0 users
  • This post has 2 Replies |
  • 2 Followers
  • I have 5 tables in  a DOCX file. The file may be modified by end user via moving one of this table to the end of the file. My question is whether its possible to attach a kind of name to the table in initial version of the file or not? If it's possible, I'd like to know how to mark this table.

  • FindTheTable.rar

    While creating the table you can give a name(or caption) for the table using TableProperties.

    If you have done this, you can get this table using the following code.

    using WordP = DocumentFormat.OpenXml.Wordprocessing;
    ........ 
    ........ 

       List<WordP.Table> tables = null;

     
                using (WordprocessingDocument wordDoc = WordprocessingDocument.Open("sample.docx"true))
                {
                    tables = new List<WordP.Table>(wordDoc.MainDocumentPart.Document.Body.Elements<WordP.Table>());
                    tables.ForEach(table =>                 
                    {
                        WordP.TableProperties tblProperties = table.GetFirstChild<WordP.TableProperties>();
                        if (tblProperties != null) 
                        {
                            WordP.TableCaption caption = tblProperties.GetFirstChild<WordP.TableCaption>();
                            if (caption != null) 
                            {
                                if (caption.Val.HasValue && caption.Val.Value.Equals("Table2Cross3"))                            
                                {
                                    // you have got your table. process the rest.
                                }
                            }
                        }
                    });
                }
    ..........

    I have shared the solution. Please have a look and let me know if you face any problem.

  • its working, good job

Page 1 of 1 (3 items)