Word.ParagraphCollection class

Contains a collection of Word.Paragraph objects.

[ API set: WordApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

items

Gets the loaded child items in this collection.

Methods

getFirst()

Gets the first paragraph in this collection. Throws if the collection is empty.

[ API set: WordApi 1.3 ]

getFirstOrNullObject()

Gets the first paragraph in this collection. Returns a null object if the collection is empty.

[ API set: WordApi 1.3 ]

getLast()

Gets the last paragraph in this collection. Throws if the collection is empty.

[ API set: WordApi 1.3 ]

getLastOrNullObject()

Gets the last paragraph in this collection. Returns a null object if the collection is empty.

[ API set: WordApi 1.3 ]

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

toJSON()
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 are 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 needed to have added the object to the tracked object collection when the object was first created.

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 will need to call "context.sync()" before the memory release takes effect.

Property Details

items

Gets the loaded child items in this collection.

readonly items: Word.Paragraph[];
Property Value
Word.Paragraph[]

Method Details

getFirst()

Gets the first paragraph in this collection. Throws if the collection is empty.

[ API set: WordApi 1.3 ]

getFirst(): Word.Paragraph;
Returns
Word.Paragraph

getFirstOrNullObject()

Gets the first paragraph in this collection. Returns a null object if the collection is empty.

[ API set: WordApi 1.3 ]

getFirstOrNullObject(): Word.Paragraph;
Returns
Word.Paragraph

getLast()

Gets the last paragraph in this collection. Throws if the collection is empty.

[ API set: WordApi 1.3 ]

getLast(): Word.Paragraph;
Returns
Word.Paragraph

getLastOrNullObject()

Gets the last paragraph in this collection. Returns a null object if the collection is empty.

[ API set: WordApi 1.3 ]

getLastOrNullObject(): Word.Paragraph;
Returns
Word.Paragraph

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(option?: string | string[]): Word.ParagraphCollection;
Parameters
option
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns
Word.ParagraphCollection
Remarks

In addition to this signature, this method has the following signatures:

load(option?: { select?: string; expand?: string; }): Word.ParagraphCollection - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Word.ParagraphCollection - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

Examples

// This example shows how to get the paragraphs in the Word document
// along with their text and font size properties.
// 
// Run a batch operation against the Word object model.
Word.run(function (context) {

    // Create a proxy object for the paragraphs collection.
    var paragraphs = context.document.body.paragraphs;

    // Queue a commmand to load the text and font properties.
    // It is best practice to always specify the property set. Otherwise, all properties are
    // returned in on the object.
    context.load(paragraphs, 'text, font/size');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    return context.sync().then(function () {

    // Insert code that works with the paragraphs loaded by context.load().
    })
})
.catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});

toJSON()

toJSON(): Word.Interfaces.ParagraphCollectionData;
Returns
Word.Interfaces.ParagraphCollectionData

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 are 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 needed to have added the object to the tracked object collection when the object was first created.

track(): Word.ParagraphCollection;
Returns
Word.ParagraphCollection

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 will need to call "context.sync()" before the memory release takes effect.

untrack(): Word.ParagraphCollection;
Returns
Word.ParagraphCollection