none
How to read Multilevel Numbering format in Word 2007 document? RRS feed

  • Question

  • Hi,

    How to read Multilevel Numbering format using OpenXML SDK  and also is there any relation between the parent and child sequence like 4-->4.1-->4.1.1 and 4.1.2


    Selvam S

    Wednesday, December 9, 2015 12:49 PM

Answers

  • >>>how can i get this data. can u provide the Sample C# Code for the above scenario.

    According to your description, you could refer to below code:

    using DocumentFormat.OpenXml;
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml.Wordprocessing;
    
    public static List<string> GetNumberingData(string fileName)
    {
          List<string> numberings = new List<string>();
          using (var document = WordprocessingDocument.Open(fileName, false))
          {
                var docPart = document.MainDocumentPart;
                var doc = docPart.Document;
                Table myTable = doc.Body.Descendants<Table>().First();
    
                foreach (TableRow theRow in myTable.Elements<TableRow>())
                {
                     TableCell theCell = theRow.Elements<TableCell>().First();
                     Paragraph theParagraph = theCell.Elements<Paragraph>().First();
                     Run theRun = theParagraph.Elements<Run>().First();
                     numberings.Add(theRun.InnerText);
                }
           }
           return numberings;
    }
    

    Otherwise I suggest you could use the Open XML Productivity Tool released along with Open XML SDK 2.5 to open your word document, click "Reflect Code", then you would see the generated code in C#.

    For more information, click here to refer about Welcome to the Open XML SDK 2.5 for Office

    • Marked as answer by David_JunFeng Wednesday, December 23, 2015 2:37 PM
    Thursday, December 10, 2015 7:31 AM

All replies

  • You don't provide enough information - I can't understand exactly what you're asking.

    Perhaps these links will help you get going:

    https://msdn.microsoft.com/en-us/library/office/ee922775(v=office.14).aspx

    https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.numbering(v=office.14).aspx


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Wednesday, December 9, 2015 6:47 PM
    Moderator


  • The data shown in screen shot is my Content.

    Here,i can't able to get the numbering data (4.1.1, 4.1.2 ...). if i get all the content from the table using openxml c# code.


    how can i get this data. can u provide the Sample C# Code for the above scenario.

     

    Selvam S

    Thursday, December 10, 2015 5:32 AM
  • >>>how can i get this data. can u provide the Sample C# Code for the above scenario.

    According to your description, you could refer to below code:

    using DocumentFormat.OpenXml;
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml.Wordprocessing;
    
    public static List<string> GetNumberingData(string fileName)
    {
          List<string> numberings = new List<string>();
          using (var document = WordprocessingDocument.Open(fileName, false))
          {
                var docPart = document.MainDocumentPart;
                var doc = docPart.Document;
                Table myTable = doc.Body.Descendants<Table>().First();
    
                foreach (TableRow theRow in myTable.Elements<TableRow>())
                {
                     TableCell theCell = theRow.Elements<TableCell>().First();
                     Paragraph theParagraph = theCell.Elements<Paragraph>().First();
                     Run theRun = theParagraph.Elements<Run>().First();
                     numberings.Add(theRun.InnerText);
                }
           }
           return numberings;
    }
    

    Otherwise I suggest you could use the Open XML Productivity Tool released along with Open XML SDK 2.5 to open your word document, click "Reflect Code", then you would see the generated code in C#.

    For more information, click here to refer about Welcome to the Open XML SDK 2.5 for Office

    • Marked as answer by David_JunFeng Wednesday, December 23, 2015 2:37 PM
    Thursday, December 10, 2015 7:31 AM
  • Thank you David JunFeng, 

    I didn't notice the "Open XML Productivity Tool" until this thread. The tool is a perfect remedy for the incomplete document of Open XML SDK.

    Thursday, November 15, 2018 1:12 AM