Featured Post

SQL Query in SharePoint

The "FullTextSqlQuery" object's constructor requires an object that has context but don't be fooled. This context will no...

Showing posts with label begin. Show all posts
Showing posts with label begin. Show all posts

Tuesday, December 10, 2013

Understanding word numbering restarts

In this post I am going to explain what changes in the xml markup when you restart a line number. In the following two pictures you can see how to restart a number and how it effects the numbers in the word document. In the first example I've used non styled numbering.









This is what the xml looks like before the restarting. Note the highlighted areas:
And this is what is looks like after restarting line 3. Note that the numId has changed for line 3 & 4.
What has also happened is that a new w:num has been created and along with that a new w:abstractNum.
If you use custom styled numbering the behaviour is the same however if you associate a custom styled number to a style and then apply that style to a paragraph the structure is somewhat different. In the below images I have applied this and I restarted the third line much the same as I did in the previous example.
 
This is what the xml looks like before the restarting. Note that there is no numbering associated to the paragraphs, only a style. 
This style is then associated to a number in the styles.xml file. You can see the xml for "Demo Style" in the image below.

This is what the document.xml looks like after restarting line 3. Note that only the third line has a change applied not the forth as well (which is what you saw in the previous example). Even though the paragraph is still associated to the style, a new number id has been associated as well.
Regarding the abstract numbering, in this case a new one was not created. Taking a look at the xml generated in numbering.xml you can see that the new numId "7" points to the same abstractNumId "2" as numId "4" (linked to Demo Style). What's also important is that a w:lvlOverride has been added to the new number as well.



Friday, December 6, 2013

Understanding word numbering manipulation

I've created a document with two types of numbering references. The first references a style which is linked to a number and the second is linked a style but has manual numbering assigned. I've added an image so you can see what this looks like in word. Note that to the front end user it looks like the only difference is the style.

However in the xml there is a slight difference. Here is an section of document.xml showing the xml for the first set of numbering. Note that the first two lines do not have any reference to a w:numId but the second two lines do. This is because the style "DemoStyle" has a reference to w:numId but only the first level. When I indented lines 3 & 4 they needed to be assigned a new numbering level/w:ilvl. Note that these paragraphs are linked to numId "1"
If you take a look at the styles.xml you will see that DemoStyle is also linked to numId "1"
Going onto the manually applied numbering see the xml below. You can see that the numbering has been assigned to all four paragraphs, not just the indented lines.
In the numbering.xml document you will find these numbering items as w:num nodes. These nodes allow multiple items to reference the same abstract number (not shown in this case but is possible).

The w:abstractNumId then references the w:abstractNum. This contains all the numbering information.
To access the numbering part in a document via OpenXml you can use the following code:

byte[] document = File.ReadAllBytes("C:\Demo Doc.docx");
using (MemoryStream memoryStream = new MemoryStream())
{
  memoryStream.Write(document, 0, document.Length);
  using (WordprocessingDocument wordprocessingDocument =     WordprocessingDocument.Open(memoryStream, true))
  {
     NumberingPart numberingPart  = wordprocessingDocument.MainDocumentPart.NumberingPart;
  }
}