0

I made a list with custom numbering but numbering itself gets a different style from paragraphs run. How can I make numbering have the same styles as paragraphs XWPFRun?

This is my numbering

XWPFNumbering numbering = document.CreateNumbering();

            var ct_abn = new CT_AbstractNum();
            var mlt = new CT_MultiLevelType();
            mlt.val = ST_MultiLevelType.multilevel;
            ct_abn.multiLevelType = mlt;
            ct_abn.lvl = new System.Collections.Generic.List<CT_Lvl> {
                new CT_Lvl {
                    ilvl = "0", start = new CT_DecimalNumber() {val = "1"}, numFmt = new CT_NumFmt() {val = ST_NumberFormat.@decimal},
                    lvlText = new CT_LevelText() {val = "%1."}, lvlJc = new CT_Jc() {val = ST_Jc.left},
                    pPr = new CT_PPr {ind = new CT_Ind {left = "360", hanging = 360}, }
                },
                new CT_Lvl {
                    ilvl = "1", start = new CT_DecimalNumber() {val = "1"}, numFmt = new CT_NumFmt() {val = ST_NumberFormat.@decimal},
                    lvlText = new CT_LevelText() {val = "%1.%2."}, lvlJc = new CT_Jc() {val = ST_Jc.left},
                    pPr = new CT_PPr {ind = new CT_Ind {left = "792", hanging = 792, firstLineSpecified = true}, }
                },
                new CT_Lvl {
                    ilvl = "2", start = new CT_DecimalNumber() {val = "1"}, numFmt = new CT_NumFmt() {val = ST_NumberFormat.@decimal},
                    lvlText = new CT_LevelText() {val = "%1.%2.%3."}, lvlJc = new CT_Jc() {val = ST_Jc.left},
                    pPr = new CT_PPr {ind = new CT_Ind {left = "792", hanging = 792}}
                },
           }

This is how it used:

            var paragraph = document.CreateParagraph();
            paragraph.Alignment = ParagraphAlignment.CENTER;
            paragraph.SetNumID(numId, "0"); // applying numbering with lvl = 0
            var run = paragraph.CreateRun();
            run.SetText("ТЕРМІНИ, ЩО ВЖИВАЮТЬСЯ В ГАРАНТІЙНИХ УМОВАХ");
            run.IsBold = true;
            run.FontFamily = "Times New Roman";
            run.FontSize = 12;

And here's what I get: paragraph itself has correct styles but a number has different

enter image description here

I will appreciate any help

Skyglar
  • 135
  • 3
  • 12

1 Answers1

1

If someone has the same problem, you should add your new style to the document and than use its StyleID to XWPFParagraph like this:

CT_Fonts ctFonts = new CT_Fonts();
ctFonts.ascii = "Times New Roman";

var styles = document.CreateStyles();
styles.AddStyle(
    new XWPFStyle(
        new CT_Style() {
            styleId = "FirstLvlStyle",
            rPr = new CT_RPr() {rFonts = ctFonts, b = new CT_OnOff() {val = true}, szCs = new CT_HpsMeasure() {val = 24}}, // gives val / 2 font size
        })
 );
var paragraph = document.CreateParagraph();
paragraph.Style = "FirstLvlStyle"; // use your StyleId to apply your style
paragraph.SetNumID(numId, "0"); // applying numbering with lvl = 0

UPDATED

Or you can specify style that you want in numbering configuration pPr (Paragraph properties) or rPr (Run properties) like this:

var ct_abn = new CT_AbstractNum();
var mlt = new CT_MultiLevelType();
mlt.val = ST_MultiLevelType.multilevel;
ct_abn.multiLevelType = mlt;
ct_abn.lvl = new System.Collections.Generic.List<CT_Lvl> {
     new CT_Lvl {
         ilvl = "0", start = new CT_DecimalNumber() {val = "1"}, numFmt = new CT_NumFmt() {val = ST_NumberFormat.@decimal},
         lvlText = new CT_LevelText() {val = "%1."}, lvlJc = new CT_Jc() {val = ST_Jc.left},
         rPr = new CT_RPr {b = new CT_OnOff {val = true}}, //make text bold
         pPr = new CT_PPr {ind = new CT_Ind {left = "360", hanging = 360}}
     },
}
Skyglar
  • 135
  • 3
  • 12