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:document>
    <w:body>
        <w:p>
            <w:pPr>
                <w:numPr>
                    <w:ilvl>X</w:ilvl>
                    <w:numId val="Y" />
numId leads to an NumberingInstance (num) in NumberingDefinitionsPart of MainDocumentPart of WordProcessingDocument.
//word/numbering.xml
    <w:numbering>
        <w:num w:numId="Y">
            <w:abstractNumId w:val="Z" />
abstractNumId leads to a AbstractNum (abstractNum)
//word/numbering.xml
    <w:numbering>
        <w:abstractNum w:abstractNumId="Z" >
            <w:lvl w:ilvl="X">
                ...
            </w:lvl>
        <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.
Remark
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