Get Started
Usage API
More information

ApiStyle

new ApiStyle()

Class representing a style.

Methods

Name Description
GetClassType

Returns a type of the ApiStyle class.

GetConditionalTableStyle

Returns a set of formatting properties which will be conditionally applied to the parts of a table that match the requirement specified in the sType parameter.

GetName

Returns a name of the current style.

GetParaPr

Returns the paragraph properties of the current style.

GetTableCellPr

Returns the table cell properties of the current style.

GetTablePr

Returns the table properties of the current style.

GetTableRowPr

Returns the table row properties of the current style.

GetTextPr

Returns the text properties of the current style.

GetType

Returns a type of the current style.

SetBasedOn

Specifies the reference to the parent style which this style inherits from in the style hierarchy.

SetName

Sets a name of the current style.

ToJSON

Converts the ApiStyle object into the JSON object.

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered - Accent 5"));
oTableStyle.SetName("My Custom Style");
var oTableStyleName = oTableStyle.GetName();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText("Table style name = " + oTableStyleName);
var oTable = Api.CreateTable(2, 2);
oTable.SetWidth("percent", 100);
var oTablePr = oTableStyle.GetTablePr();
oTablePr.SetTableInd(0);
oTablePr.SetTableCellMarginTop(720);
oTablePr.SetTableCellMarginLeft(120);
oTablePr.SetTableCellMarginRight(120);
oTablePr.SetTableCellMarginBottom(0);
oDocument.Push(oTable);
oTable.SetStyle(oTableStyle);
oTable.SetTableLook(true, true, true, true, true, true);
oTableStyle.GetConditionalTableStyle("topLeftCell").GetTableCellPr().SetShd("clear", 255, 0, 0);
oTableStyle.GetConditionalTableStyle("topRightCell").GetTableCellPr().SetShd("clear", 0, 255, 0);
oTableStyle.GetConditionalTableStyle("bottomLeftCell").GetTableCellPr().SetShd("clear", 0, 0, 255);
oTableStyle.GetConditionalTableStyle("bottomRightCell").GetTableCellPr().SetShd("clear", 255, 255, 0);
builder.SaveFile("docx", "ApiStyle.docx");
builder.CloseFile();

Resulting document