CreateStyle

CreateStyle(sStyleName, [sType]) → { ApiStyle }

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:

Name Type Default Description
sStyleName string

The name of the style which will be created.

sType StyleType "paragraph"

The document element which the style will be applied to.

Returns:

Type
ApiStyle

Example

Copy code
builder.CreateFile("docx");
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);
builder.SaveFile("docx", "SetStyle.docx");
builder.CloseFile();

Resulting document