Word.TableStyle class
Represents the TableStyle object.
- Extends
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/manage-custom-style.yaml
// Gets the table style properties and displays them in the form.
const styleName = (document.getElementById("style-name") as HTMLInputElement).value;
if (styleName == "") {
console.warn("Please input a table style name.");
return;
}
await Word.run(async (context) => {
const tableStyle: Word.TableStyle = context.document.getStyles().getByName(styleName).tableStyle;
tableStyle.load();
await context.sync();
if (tableStyle.isNullObject) {
console.warn(`There's no existing table style with the name '${styleName}'.`);
return;
}
console.log(tableStyle);
(document.getElementById("alignment") as HTMLInputElement).value = tableStyle.alignment;
(document.getElementById("allow-break-across-page") as HTMLInputElement).value = tableStyle.allowBreakAcrossPage.toString();
(document.getElementById("top-cell-margin") as HTMLInputElement).value = tableStyle.topCellMargin;
(document.getElementById("bottom-cell-margin") as HTMLInputElement).value = tableStyle.bottomCellMargin;
(document.getElementById("left-cell-margin") as HTMLInputElement).value = tableStyle.leftCellMargin;
(document.getElementById("right-cell-margin") as HTMLInputElement).value = tableStyle.rightCellMargin;
(document.getElementById("cell-spacing") as HTMLInputElement).value = tableStyle.cellSpacing;
});
Properties
| alignment | Specifies the table's alignment against the page margin. |
| allow |
Specifies whether lines in tables formatted with a style break across pages. |
| borders | Returns a |
| bottom |
Specifies the amount of space to add between the contents and the bottom borders of the cells. |
| cell |
Specifies the spacing (in points) between the cells in a table style. |
| column |
Specifies the number of columns in the banding when a style specifies odd- or even-column banding. |
| context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
| is |
Specifies whether Microsoft Word allows to break the specified table across pages. |
| left |
Specifies the amount of space to add between the contents and the left borders of the cells. |
| left |
Specifies the left indent value (in points) for the rows in the table style. |
| right |
Specifies the amount of space to add between the contents and the right borders of the cells. |
| row |
Specifies the number of rows to include in the banding when the style specifies odd- or even-row banding. |
| shading | Returns a |
| table |
Specifies the direction in which Microsoft Word orders cells in the table style. |
| top |
Specifies the amount of space to add between the contents and the top borders of the cells. |
Methods
| condition(condition |
Returns a |
| condition(condition |
Returns a |
| load(options) | Queues up a command to load the specified properties of the object. You must call |
| load(property |
Queues up a command to load the specified properties of the object. You must call |
| load(property |
Queues up a command to load the specified properties of the object. You must call |
| set(properties, options) | Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type. |
| set(properties) | Sets multiple properties on the object at the same time, based on an existing loaded object. |
| toJSON() | Overrides the JavaScript |
| track() | Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across |
| untrack() | Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You'll need to call |
Property Details
alignment
Specifies the table's alignment against the page margin.
alignment: Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified";
Property Value
Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified"
Remarks
allowBreakAcrossPage
Specifies whether lines in tables formatted with a style break across pages.
allowBreakAcrossPage: boolean;
Property Value
boolean
Remarks
borders
Returns a BorderUniversalCollection that represents all the borders for the table.
readonly borders: Word.BorderUniversalCollection;
Property Value
Remarks
bottomCellMargin
Specifies the amount of space to add between the contents and the bottom borders of the cells.
bottomCellMargin: number;
Property Value
number
Remarks
cellSpacing
Specifies the spacing (in points) between the cells in a table style.
cellSpacing: number;
Property Value
number
Remarks
columnStripe
Specifies the number of columns in the banding when a style specifies odd- or even-column banding.
columnStripe: number;
Property Value
number
Remarks
context
The request context associated with the object. This connects the add-in's process to the Office host application's process.
context: RequestContext;
Property Value
isBreakAcrossPagesAllowed
Specifies whether Microsoft Word allows to break the specified table across pages.
isBreakAcrossPagesAllowed: boolean;
Property Value
boolean
Remarks
leftCellMargin
Specifies the amount of space to add between the contents and the left borders of the cells.
leftCellMargin: number;
Property Value
number
Remarks
leftIndent
Specifies the left indent value (in points) for the rows in the table style.
leftIndent: number;
Property Value
number
Remarks
rightCellMargin
Specifies the amount of space to add between the contents and the right borders of the cells.
rightCellMargin: number;
Property Value
number
Remarks
rowStripe
Specifies the number of rows to include in the banding when the style specifies odd- or even-row banding.
rowStripe: number;
Property Value
number
Remarks
shading
Returns a ShadingUniversal object that refers to the shading formatting for the table style.
readonly shading: Word.Shading;
Property Value
Remarks
tableDirection
Specifies the direction in which Microsoft Word orders cells in the table style.
tableDirection: Word.TableDirection | "RightToLeft" | "LeftToRight";
Property Value
Word.TableDirection | "RightToLeft" | "LeftToRight"
Remarks
topCellMargin
Specifies the amount of space to add between the contents and the top borders of the cells.
topCellMargin: number;
Property Value
number
Remarks
Method Details
condition(conditionCode)
Returns a ConditionalStyle object that represents special style formatting for a portion of a table.
condition(conditionCode: Word.ConditionCode): Word.ConditionalStyle;
Parameters
- conditionCode
- Word.ConditionCode
The area of the table to which to apply the formatting.
Returns
Remarks
condition(conditionCode)
Returns a ConditionalStyle object that represents special style formatting for a portion of a table.
condition(conditionCode: "FirstRow" | "LastRow" | "OddRowBanding" | "EvenRowBanding" | "FirstColumn" | "LastColumn" | "OddColumnBanding" | "EvenColumnBanding" | "TopRightCell" | "TopLeftCell" | "BottomRightCell" | "BottomLeftCell"): Word.ConditionalStyle;
Parameters
- conditionCode
-
"FirstRow" | "LastRow" | "OddRowBanding" | "EvenRowBanding" | "FirstColumn" | "LastColumn" | "OddColumnBanding" | "EvenColumnBanding" | "TopRightCell" | "TopLeftCell" | "BottomRightCell" | "BottomLeftCell"
The area of the table to which to apply the formatting.
Returns
Remarks
load(options)
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(options?: Word.Interfaces.TableStyleLoadOptions): Word.TableStyle;
Parameters
Provides options for which properties of the object to load.
Returns
load(propertyNames)
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(propertyNames?: string | string[]): Word.TableStyle;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
load(propertyNamesAndPaths)
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Word.TableStyle;
Parameters
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.
Returns
set(properties, options)
Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.
set(properties: Interfaces.TableStyleUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- Word.Interfaces.TableStyleUpdateData
A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.
- options
- OfficeExtension.UpdateOptions
Provides an option to suppress errors if the properties object tries to set any read-only properties.
Returns
void
set(properties)
Sets multiple properties on the object at the same time, based on an existing loaded object.
set(properties: Word.TableStyle): void;
Parameters
- properties
- Word.TableStyle
Returns
void
toJSON()
Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that's passed to it.) Whereas the original Word.TableStyle object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.TableStyleData) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Word.Interfaces.TableStyleData;
Returns
track()
Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across .sync calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you need to add the object to the tracked object collection when the object was first created. If this object is part of a collection, you should also track the parent collection.
track(): Word.TableStyle;
Returns
untrack()
Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You'll need to call context.sync() before the memory release takes effect.
untrack(): Word.TableStyle;