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"));
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, 111, 61);
oTableStyle.GetConditionalTableStyle("topRightCell").GetTableCellPr().SetShd("clear", 51, 51, 51);
oTableStyle.GetConditionalTableStyle("bottomLeftCell").GetTableCellPr().SetShd("clear", 128, 128, 128);
oTableStyle.GetConditionalTableStyle("bottomRightCell").GetTableCellPr().SetShd("clear", 255, 213, 191);
builder.SaveFile("docx", "ApiStyle.docx");
builder.CloseFile();

Resulting document