SetWidth
Sets the preferred width to the current table.
Tables are created with the ApiTable#SetWidth method properties set by default, which always override the ApiTablePr#SetWidth method properties. That is why there is no use to try and apply ApiTablePr#SetWidth. We recommend you to use the ApiTablePr#SetWidth method instead.
Parameters:
Name |
Type |
Default |
Description |
sType |
TableWidth
|
|
Type of the width value from one of the available width values types. |
nValue |
number
|
null |
The table width value measured in positive integers. |
Returns:
-
This method doesn't return any data.
Example
Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText("We set the table width to 100 percent:");
var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered - Accent 5"));
var oTable = Api.CreateTable(3, 3);
oTable.SetWidth("percent", 100);
oTable.SetStyle(oTableStyle);
oDocument.Push(oTable);
builder.SaveFile("docx", "SetWidth.docx");
builder.CloseFile();
Resulting document