How to use a pre-defined Multilevel List Style

Hi @Constantine,

I attempted to create a custom Numbering and apply it to the Heading 1, Heading 2 and Heading 3. However, I noticed that while Heading 1 works as expected, the Heading 2 and Heading 3 styles are being created without the Numbering for some reason. Am I missing something?

In the previous image, you can see that the headings 1, 1.1, 1.1.1, 2, and 2.1 were generated using the document builder. However, when I try to use the newly created styles in the document editor, the numbering in Heading 2 and Heading 3 does not appear.

Interestingly, in the document editor’s styles menu, the numbering is visible in the name of the Heading 1 Style, barely visible although. This behavior, however, does not apply to the other headings for some reason.

Below, you’ll find a document builder sample along with the generated document:

// create a text document file in the .docx format with ONLYOFFICE Document Builder
builder.CreateFile("docx")

var oDocument = Api.GetDocument();

//---------------- Create the custom style to use in sections titles ----------------//
var oNumbering = oDocument.CreateNumbering("numbered"); // This need to be created here for the use of the section components

var oNumLvl0 = oNumbering.GetLevel(0);
var sFormatString = "%1";
oNumLvl0.SetCustomType("decimal", sFormatString, "right");

var oNumLvl1 = oNumbering.GetLevel(1);
var sFormatString1 = "%1.%2";
oNumLvl1.SetCustomType("decimal", sFormatString1, "right");

var oNumLvl2 = oNumbering.GetLevel(2);
var sFormatString2 = "%1.%2.%3";
oNumLvl2.SetCustomType("decimal", sFormatString2, "right");

// Heading 1
var oHeadingLvl1Style = oDocument.CreateStyle("Heading 1", "paragraph");
var oTextPr = oHeadingLvl1Style.GetTextPr();
oTextPr.SetBold(true);
oTextPr.SetColor(0, 0, 0, false);
oTextPr.SetFontSize(28);
oTextPr.SetFontFamily("FreeSans");

var oParaPr = oHeadingLvl1Style.GetParaPr();
oParaPr.SetOutlineLvl(0);
oParaPr.SetNumPr(oNumbering, 0);

// Heading 2
var oHeadingLvl2Style = oDocument.CreateStyle("Heading 2", "paragraph");
var oTextPr = oHeadingLvl2Style.GetTextPr();
oTextPr.SetBold(true);
oTextPr.SetColor(0, 0, 0, false);
oTextPr.SetFontSize(24);
oTextPr.SetFontFamily("FreeSans");

var oParaPr = oHeadingLvl2Style.GetParaPr();
oParaPr.SetOutlineLvl(0);
oParaPr.SetNumPr(oNumbering, 1);

// Heading 3
var oHeadingLvl3Style = oDocument.CreateStyle("Heading 3", "paragraph");
var oTextPr = oHeadingLvl3Style.GetTextPr();
oTextPr.SetBold(true);
oTextPr.SetColor(0, 0, 0, false);
oTextPr.SetFontSize(22);
oTextPr.SetFontFamily("FreeSans");

var oParaPr = oHeadingLvl3Style.GetParaPr();
oParaPr.SetOutlineLvl(2);
oParaPr.SetNumPr(oNumbering, 2);

// Adding sections

var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Heading 1 title (generated)");
oParagraph.SetStyle(oHeadingLvl1Style)
oParagraph.SetNumbering(oNumLvl0);
oParagraph.SetIndLeft(550);

oDocument.Push(oParagraph);

var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Heading 2 title (generated)");
oParagraph.SetStyle(oHeadingLvl2Style)
oParagraph.SetNumbering(oNumLvl1);
oParagraph.SetIndLeft(550);
oDocument.Push(oParagraph);

var oParagraph = Api.CreateParagraph();
oParagraph.AddText("This is some demonstrative paragraph just to fill out the page.");
oDocument.Push(oParagraph);

var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Heading 3 title (generated)");
oParagraph.SetStyle(oHeadingLvl3Style)
oParagraph.SetNumbering(oNumLvl2);
oParagraph.SetIndLeft(550);
oDocument.Push(oParagraph);

var oParagraph = Api.CreateParagraph();
oParagraph.AddText("This is some demonstrative paragraph just to fill out the page.");
oDocument.Push(oParagraph);

var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Heading 1 title (generated)");
oParagraph.SetStyle(oHeadingLvl1Style)
oParagraph.SetNumbering(oNumLvl0);
oParagraph.SetIndLeft(550);
oDocument.Push(oParagraph);

var oParagraph = Api.CreateParagraph();
oParagraph.AddText("This is some demonstrative paragraph just to fill out the page.");
oDocument.Push(oParagraph);

var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Heading 2 title (generated)");
oParagraph.SetStyle(oHeadingLvl2Style)
oParagraph.SetNumbering(oNumLvl1);
oParagraph.SetIndLeft(550);
oDocument.Push(oParagraph);

var oParagraph = Api.CreateParagraph();
oParagraph.AddText("This is some demonstrative paragraph just to fill out the page.");
oDocument.Push(oParagraph);

// save the resulting text document as a file in the .docx format with the 'example.docx' name
builder.SaveFile("docx", "example.docx")

// close the text document file and finish work with ONLYOFFICE Document Builder
builder.CloseFile()

HeadingExample.docx (26.3 KB)