mardi 9 septembre 2014

Bulleting in MsWord openXml document, using OpenXml SDK: the basics.

As often the most important is the understanding of the model, here of the XML model.
This article is a simplifcation of Working with Numbered Lists in Open XML WordprocessingML.
Bulleting is a part of Numbering.
Numbering is a NumberingProperties (numPr) property in a ParagraphProperties property of a Paragraph from a Document object.
That is a hierarchy as follow:
                    <w:numId val="Y" />
numId leads to an NumberingInstance (num) in NumberingDefinitionsPart of MainDocumentPart of WordProcessingDocument.
        <w:num w:numId="Y">
            <w:abstractNumId w:val="Z" />
abstractNumId leads to a AbstractNum (abstractNum)
        <w:abstractNum w:abstractNumId="Z" >
            <w:lvl w:ilvl="X">
        <w:num w:numId="Y">
            <w:abstractNumId w:val="Z" />

It is now clear that to get the bullet properties we have to traverse from the NumberingProperties of the Paragraph comprising the text of the bullet. Then we go to the NumberingDefinitionsPart searching the corresponding numId, That give us an abstractNumId which, with the ilvl of the ParagraphProperties, give us the Level we seek.
If you have a ParagraphProperties at the Paragraph level, the Paragraph stays a bullet (because of Paragraph.NumberingProperties), but the values from Paragraph.ParagraphProperties prevail over those of NumberingProperties.

Aucun commentaire:

Enregistrer un commentaire