CreateStyle

function CreateStyle(sStyleName: string = null, sType: StyleType = "paragraph"): ApiStyle

Description

Creates a new style with the specified type and name. If there is a style with the same name it will be replaced with a new one.

Parameters

sStyleNamestringdefault: null

The name of the style which will be created.

sTypeStyleTypedefault: "paragraph"

The document element which the style will be applied to.

Returns

ApiStyle

Try It

var oDocument = Api.GetDocument();
var oHeading1Style = oDocument.CreateStyle("Heading 1", "paragraph");
var oParaPr = oHeading1Style.GetParaPr();
oParaPr.SetKeepNext(true);
oParaPr.SetKeepLines(true);
oParaPr.SetSpacingAfter(240);
var oTextPr = oHeading1Style.GetTextPr();
oTextPr.SetColor(0xff, 0x68, 0x00, false);
oTextPr.SetFontSize(40);
oTextPr.SetFontFamily("Calibri Light");
var oParagraph = oDocument.GetElement(0);
oParagraph.SetStyle(oHeading1Style);
oParagraph.AddText("This is a heading with a style created above");
oParagraph = Api.CreateParagraph();
oParagraph.AddText("This is just a text.");
oDocument.Push(oParagraph);

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).