Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Now that I've understood what you want exactly, here's how you should go about solving your problem.</p> <p>First of all I'd recommend you download the Open XML Productivity tool from <a href="http://www.microsoft.com/en-in/download/details.aspx?id=30425" rel="nofollow noreferrer">here</a>. Once you know what underlying xml looks like for a file, it becomes really easy to tackle the problem.</p> <pre><code>&lt;w:p w:rsidR="004265BF" w:rsidP="00AD13B6" w:rsidRDefault="00AD13B6"&gt; &lt;w:pPr&gt; &lt;w:pStyle w:val="ListParagraph" /&gt; &lt;w:numPr&gt; &lt;w:ilvl w:val="0" /&gt; &lt;w:numId w:val="2" /&gt; &lt;/w:numPr&gt; &lt;/w:pPr&gt; &lt;w:r&gt; &lt;w:t&gt;Requirements&lt;/w:t&gt; &lt;/w:r&gt; &lt;/w:p&gt; &lt;w:p w:rsidR="00AD13B6" w:rsidP="00AD13B6" w:rsidRDefault="00AD13B6"&gt; &lt;w:pPr&gt; &lt;w:pStyle w:val="ListParagraph" /&gt; &lt;w:numPr&gt; &lt;w:ilvl w:val="1" /&gt; &lt;w:numId w:val="2" /&gt; &lt;/w:numPr&gt; &lt;/w:pPr&gt; &lt;w:r&gt; &lt;w:t&gt;Performance&lt;/w:t&gt; &lt;/w:r&gt; &lt;/w:p&gt; </code></pre> <p>Above you can see the XML for the just a few paragraphs. Each Paragraph has its corresponding and that contains .</p> <p>Each word document contains many different XML files that act as references to the styles and values that are used throughout the document body. For outlines, there's Numbering.xml.</p> <p>Each numId here refers to an AbstractNumId in numbering.xml and that in turn refers to abstractNum in the same file. You can get your Outline number from there.</p> <p>I know it might sound tedious, but this is the only way it can be done.</p> <p><img src="https://i.stack.imgur.com/PrRAM.jpg" alt="Open Xml Productivity Tool Snapshot">.</p> <p>All the best! </p> <pre><code>using (WordprocessingDocument doc = WordprocessingDocument.Open("word-wrP.docx", true)) { Body body = doc.MainDocumentPart.Document.Body; //Documents' numbering definition Numbering num = doc.MainDocumentPart.NumberingDefinitionsPart.Numbering; //Get all paragraphs in the document IEnumerable&lt;Paragraph&gt; paragraphs = doc.MainDocumentPart.Document.Body.OfType&lt;Paragraph&gt;(); foreach (Paragraph paragraph in paragraphs) { int tempLevel = 0; //Each paragraph has a reference to a numbering definition that is defined by the numbering ID NumberingId numId = paragraph.ParagraphProperties.NumberingProperties.NumberingId; //NumberingLevelReference defines the outline level or the "indent" of Numbering, index starts at Zero. NumberingLevelReference iLevel = paragraph.ParagraphProperties.NumberingProperties.NumberingLevelReference; //From the numbering reference we get the actual numbering definition to get start value of the outline etc etc. var firstOrDefault = num.Descendants&lt;NumberingInstance&gt;().FirstOrDefault(tag =&gt; tag.NumberID == (int)numId.Val); if (firstOrDefault != null) { var absNumId = firstOrDefault.GetFirstChild&lt;AbstractNumId&gt;(); AbstractNum absNum = num.OfType&lt;AbstractNum&gt;().FirstOrDefault(tag =&gt; tag.AbstractNumberId == (int)absNumId.Val); if (absNum != null) { StartNumberingValue start = absNum.OfType&lt;StartNumberingValue&gt;().FirstOrDefault(); // once you have the start value its just a matter of counting the paragraphs that have the same numberingId and from the Number //ingLevel you can calculate the actual values that correspond to each paragraph. if (start != null) startValue = start.Val; } } else { Console.WriteLine("Failed!"); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload