Section Object (JavaScript API for Word)
Word 2016, Word for iPad, Word for Mac, Word Online
Represents a section in a Word document.
Properties
None
Relationships
| Relationship | Type | Description | Req. Set |
|---|---|---|---|
| body | Body | Gets the body object of the section. This does not include the headerfooter and other section metadata. Read-only. | 1.1 |
Methods
| Method | Return Type | Description | Req. Set |
|---|---|---|---|
| getFooter(type: string) | Body | Gets one of the section's footers. | 1.1 |
| getHeader(type: string) | Body | Gets one of the section's headers. | 1.1 |
| getNext() | Section | Gets the next section. Throws if this section is the last one. | 1.3 |
| getNextOrNullObject() | Section | Gets the next section. Returns a null object if this section is the last one. | 1.3 |
| load(param: object) | void | Fills the proxy object created in JavaScript layer with property and object values specified in the parameter. | 1.1 |
Method Details
getFooter(type: string)
Gets one of the section's footers.
Syntax
sectionObject.getFooter(type);
Parameters
| Parameter | Type | Description |
|---|---|---|
| type | string | Required. The type of footer to return. This value can be: 'primary', 'firstPage' or 'evenPages'. Possible values are: Primary Returns the header or footer on all pages of a section, with the first page or odd pages excluded if they are different.,FirstPage Returns the header or footer on the first page of a section.,EvenPages Returns all headers or footers on even-numbered pages of a section. |
Returns
Examples
// Run a batch operation against the Word object model.
Word.run(function (context) {
// Create a proxy sectionsCollection object.
var mySections = context.document.sections;
// Queue a commmand to load the sections.
context.load(mySections, 'body/style');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
// Create a proxy object the primary footer of the first section.
// Note that the footer is a body object.
var myFooter = mySections.items[0].getFooter("primary");
// Queue a command to insert text at the end of the footer.
myFooter.insertText("This is a footer.", Word.InsertLocation.end);
// Queue a command to wrap the header in a content control.
myFooter.insertContentControl();
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log("Added a footer to the first section.");
});
});
})
.catch(function (error) {
console.log('Error: ' + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
getHeader(type: string)
Gets one of the section's headers.
Syntax
sectionObject.getHeader(type);
Parameters
| Parameter | Type | Description |
|---|---|---|
| type | string | Required. The type of header to return. This value can be: 'primary', 'firstPage' or 'evenPages'. Possible values are: Primary Returns the header or footer on all pages of a section, with the first page or odd pages excluded if they are different.,FirstPage Returns the header or footer on the first page of a section.,EvenPages Returns all headers or footers on even-numbered pages of a section. |
Returns
Examples
// Run a batch operation against the Word object model.
Word.run(function (context) {
// Create a proxy sectionsCollection object.
var mySections = context.document.sections;
// Queue a commmand to load the sections.
context.load(mySections, 'body/style');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
// Create a proxy object the primary header of the first section.
// Note that the header is a body object.
var myHeader = mySections.items[0].getHeader("primary");
// Queue a command to insert text at the end of the header.
myHeader.insertText("This is a header.", Word.InsertLocation.end);
// Queue a command to wrap the header in a content control.
myHeader.insertContentControl();
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log("Added a header to the first section.");
});
});
})
.catch(function (error) {
console.log('Error: ' + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
getNext()
Gets the next section. Throws if this section is the last one.
Syntax
sectionObject.getNext();
Parameters
None
Returns
getNextOrNullObject()
Gets the next section. Returns a null object if this section is the last one.
Syntax
sectionObject.getNextOrNullObject();
Parameters
None
Returns
load(param: object)
Fills the proxy object created in JavaScript layer with property and object values specified in the parameter.
Syntax
object.load(param);
Parameters
| Parameter | Type | Description |
|---|---|---|
| param | object | Optional. Accepts parameter and relationship names as delimited string or an array. Or, provide loadOption object. |
Returns
void