How to use a pre-defined Multilevel List Style

Do you want to: Ask a how-to question

Hi!

Using document builder, how can I use this pre-defined multilevel list to create headings?

Thank you for your time!

Hello @mrmikept

How you would like to use it? Please share some more information on the result you’d like to achieve.

Hi @Constantine

I want to used it as a header listing for the sections for the document, like so:

Is there any way I can select that specific style within document builder? I want to use the multilevel heading list.

Thank you!

Thanks, I see now. I am checking this scenario out. Please await for my feedback.

1 Like

Hello again @mrmikept

Unfortunately, I did not found any methods related to the multilevel list, so based on this query we registered an enhancement to implement them. For now, I only see the option to create custom numbering and specifically define style for necessary items.

Hi @Constantine,

That’s unfortunate :frowning:

I’ll try to create the custom numbering and define it into a style and I’ll let you know what I’ve achieved!

1 Like

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)

I’ve noticed that in the document editor, you can simply select the text and update the style using the selection, as shown in the first image:

This action effectively updates the style with the numbering, as demonstrated in the second image:

If there are no errors in my document builder script, is it possible to perform this style update programmatically using the document builder?

It seems to be mostly related to the style, isn’t it? Please start a new topic with these questions to avoid mixing up several queries in a single one.