Word.Paragraph class
Represents a single paragraph in a selection, range, content control, or document body.
- Extends
Remarks
Properties
alignment | Gets or sets the alignment for a paragraph. The value can be 'left', 'centered', 'right', or 'justified'. |
content |
Gets the collection of content control objects in the paragraph. Read-only. |
context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
endnotes | Gets the collection of endnotes in the paragraph. Read-only. |
fields | Gets the collection of fields in the paragraph. Read-only. |
first |
Gets or sets the value, in points, for a first line or hanging indent. Use a positive value to set a first-line indent, and use a negative value to set a hanging indent. |
font | Gets the text format of the paragraph. Use this to get and set font name, size, color, and other properties. Read-only. |
footnotes | Gets the collection of footnotes in the paragraph. Read-only. |
inline |
Gets the collection of InlinePicture objects in the paragraph. The collection does not include floating images. Read-only. |
is |
Indicates the paragraph is the last one inside its parent body. Read-only. |
is |
Checks whether the paragraph is a list item. Read-only. |
left |
Gets or sets the left indent value, in points, for the paragraph. |
line |
Gets or sets the line spacing, in points, for the specified paragraph. In the Word UI, this value is divided by 12. |
line |
Gets or sets the amount of spacing, in grid lines, after the paragraph. |
line |
Gets or sets the amount of spacing, in grid lines, before the paragraph. |
list | Gets the List to which this paragraph belongs. Throws an error if the paragraph is not in a list. Read-only. |
list |
Gets the ListItem for the paragraph. Throws an error if the paragraph is not part of a list. Read-only. |
list |
Gets the ListItem for the paragraph. Returns a null object if the paragraph is not part of a list. Read-only. |
list |
Gets the List to which this paragraph belongs. Returns a null object if the paragraph is not in a list. Read-only. |
outline |
Gets or sets the outline level for the paragraph. |
parent |
Gets the parent body of the paragraph. Read-only. |
parent |
Gets the content control that contains the paragraph. Throws an error if there isn't a parent content control. Read-only. |
parent |
Gets the content control that contains the paragraph. Returns a null object if there isn't a parent content control. Read-only. |
parent |
Gets the table that contains the paragraph. Throws an error if it is not contained in a table. Read-only. |
parent |
Gets the table cell that contains the paragraph. Throws an error if it is not contained in a table cell. Read-only. |
parent |
Gets the table cell that contains the paragraph. Returns a null object if it is not contained in a table cell. Read-only. |
parent |
Gets the table that contains the paragraph. Returns a null object if it is not contained in a table. Read-only. |
right |
Gets or sets the right indent value, in points, for the paragraph. |
space |
Gets or sets the spacing, in points, after the paragraph. |
space |
Gets or sets the spacing, in points, before the paragraph. |
style | Gets or sets the style name for the paragraph. Use this property for custom styles and localized style names. To use the built-in styles that are portable between locales, see the "styleBuiltIn" property. |
style |
Gets or sets the built-in style name for the paragraph. Use this property for built-in styles that are portable between locales. To use custom styles or localized style names, see the "style" property. |
table |
Gets the level of the paragraph's table. It returns 0 if the paragraph is not in a table. Read-only. |
text | Gets the text of the paragraph. Read-only. |
Methods
attach |
Lets the paragraph join an existing list at the specified level. Fails if the paragraph cannot join the list or if the paragraph is already a list item. |
clear() | Clears the contents of the paragraph object. The user can perform the undo operation on the cleared content. |
delete() | Deletes the paragraph and its content from the document. |
detach |
Moves this paragraph out of its list, if the paragraph is a list item. |
get |
Gets comments associated with the paragraph. |
get |
Gets an HTML representation of the paragraph object. When rendered in a web page or HTML viewer, the formatting will be a close, but not exact, match for of the formatting of the document. This method does not return the exact same HTML for the same document on different platforms (Windows, Mac, Word on the web, etc.). If you need exact fidelity, or consistency across platforms, use |
get |
Gets the next paragraph. Throws an error if the paragraph is the last one. |
get |
Gets the next paragraph. Returns a null object if the paragraph is the last one. |
get |
Gets the Office Open XML (OOXML) representation of the paragraph object. |
get |
Gets the previous paragraph. Throws an error if the paragraph is the first one. |
get |
Gets the previous paragraph. Returns a null object if the paragraph is the first one. |
get |
Gets the whole paragraph, or the starting or ending point of the paragraph, as a range. |
get |
Gets the whole paragraph, or the starting or ending point of the paragraph, as a range. |
get |
Gets reviewed text based on ChangeTrackingVersion selection. |
get |
Gets reviewed text based on ChangeTrackingVersion selection. |
get |
Gets the text ranges in the paragraph by using punctuation marks and/or other ending marks. |
insert |
Inserts a break at the specified location in the main document. |
insert |
Inserts a break at the specified location in the main document. |
insert |
Wraps the paragraph object with a rich text content control. |
insert |
Inserts a document into the paragraph at the specified location. |
insert |
Inserts a document into the paragraph at the specified location. |
insert |
Inserts HTML into the paragraph at the specified location. |
insert |
Inserts HTML into the paragraph at the specified location. |
insert |
Inserts a picture into the paragraph at the specified location. |
insert |
Inserts a picture into the paragraph at the specified location. |
insert |
Inserts OOXML into the paragraph at the specified location. |
insert |
Inserts OOXML into the paragraph at the specified location. |
insert |
Inserts a paragraph at the specified location. |
insert |
Inserts a paragraph at the specified location. |
insert |
Inserts a table with the specified number of rows and columns. |
insert |
Inserts a table with the specified number of rows and columns. |
insert |
Inserts text into the paragraph at the specified location. |
insert |
Inserts text into the paragraph at the specified location. |
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 |
search(search |
Performs a search with the specified SearchOptions on the scope of the paragraph object. The search results are a collection of range objects. |
select(selection |
Selects and navigates the Word UI to the paragraph. |
select(selection |
Selects and navigates the Word UI to the paragraph. |
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. |
split(delimiters, trim |
Splits the paragraph into child ranges by using delimiters. |
start |
Starts a new list with this paragraph. Fails if the paragraph is already a list item. |
toJSON() | Overrides the JavaScript |
track() | Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for |
untrack() | Release the memory associated with this object, if it has previously been tracked. This call is shorthand for |
Property Details
alignment
Gets or sets the alignment for a paragraph. The value can be 'left', 'centered', 'right', or 'justified'.
alignment: Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified";
Property Value
Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified"
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/paragraph-properties.yaml
await Word.run(async (context) => {
// Centers last paragraph alignment.
context.document.body.paragraphs.getLast().alignment = "Centered";
await context.sync();
});
contentControls
Gets the collection of content control objects in the paragraph. Read-only.
readonly contentControls: Word.ContentControlCollection;
Property Value
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
endnotes
Gets the collection of endnotes in the paragraph. Read-only.
readonly endnotes: Word.NoteItemCollection;
Property Value
Remarks
fields
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Gets the collection of fields in the paragraph. Read-only.
readonly fields: Word.FieldCollection;
Property Value
Remarks
firstLineIndent
Gets or sets the value, in points, for a first line or hanging indent. Use a positive value to set a first-line indent, and use a negative value to set a hanging indent.
firstLineIndent: number;
Property Value
number
Remarks
font
Gets the text format of the paragraph. Use this to get and set font name, size, color, and other properties. Read-only.
readonly font: Word.Font;
Property Value
Remarks
footnotes
Gets the collection of footnotes in the paragraph. Read-only.
readonly footnotes: Word.NoteItemCollection;
Property Value
Remarks
inlinePictures
Gets the collection of InlinePicture objects in the paragraph. The collection does not include floating images. Read-only.
readonly inlinePictures: Word.InlinePictureCollection;
Property Value
Remarks
isLastParagraph
Indicates the paragraph is the last one inside its parent body. Read-only.
readonly isLastParagraph: boolean;
Property Value
boolean
Remarks
isListItem
Checks whether the paragraph is a list item. Read-only.
readonly isListItem: boolean;
Property Value
boolean
Remarks
leftIndent
Gets or sets the left indent value, in points, for the paragraph.
leftIndent: number;
Property Value
number
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/paragraph-properties.yaml
await Word.run(async (context) => {
// Indents the first paragraph.
context.document.body.paragraphs.getFirst().leftIndent = 75; //units = points
return context.sync();
});
lineSpacing
Gets or sets the line spacing, in points, for the specified paragraph. In the Word UI, this value is divided by 12.
lineSpacing: number;
Property Value
number
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/paragraph-properties.yaml
await Word.run(async (context) => {
// Adjusts line spacing.
context.document.body.paragraphs.getFirst().lineSpacing = 20;
await context.sync();
});
lineUnitAfter
Gets or sets the amount of spacing, in grid lines, after the paragraph.
lineUnitAfter: number;
Property Value
number
Remarks
lineUnitBefore
Gets or sets the amount of spacing, in grid lines, before the paragraph.
lineUnitBefore: number;
Property Value
number
Remarks
list
Gets the List to which this paragraph belongs. Throws an error if the paragraph is not in a list. Read-only.
readonly list: Word.List;
Property Value
Remarks
listItem
Gets the ListItem for the paragraph. Throws an error if the paragraph is not part of a list. Read-only.
readonly listItem: Word.ListItem;
Property Value
Remarks
listItemOrNullObject
Gets the ListItem for the paragraph. Returns a null object if the paragraph is not part of a list. Read-only.
readonly listItemOrNullObject: Word.ListItem;
Property Value
Remarks
listOrNullObject
Gets the List to which this paragraph belongs. Returns a null object if the paragraph is not in a list. Read-only.
readonly listOrNullObject: Word.List;
Property Value
Remarks
outlineLevel
Gets or sets the outline level for the paragraph.
outlineLevel: number;
Property Value
number
Remarks
parentBody
Gets the parent body of the paragraph. Read-only.
readonly parentBody: Word.Body;
Property Value
Remarks
parentContentControl
Gets the content control that contains the paragraph. Throws an error if there isn't a parent content control. Read-only.
readonly parentContentControl: Word.ContentControl;
Property Value
Remarks
parentContentControlOrNullObject
Gets the content control that contains the paragraph. Returns a null object if there isn't a parent content control. Read-only.
readonly parentContentControlOrNullObject: Word.ContentControl;
Property Value
Remarks
parentTable
Gets the table that contains the paragraph. Throws an error if it is not contained in a table. Read-only.
readonly parentTable: Word.Table;
Property Value
Remarks
parentTableCell
Gets the table cell that contains the paragraph. Throws an error if it is not contained in a table cell. Read-only.
readonly parentTableCell: Word.TableCell;
Property Value
Remarks
parentTableCellOrNullObject
Gets the table cell that contains the paragraph. Returns a null object if it is not contained in a table cell. Read-only.
readonly parentTableCellOrNullObject: Word.TableCell;
Property Value
Remarks
parentTableOrNullObject
Gets the table that contains the paragraph. Returns a null object if it is not contained in a table. Read-only.
readonly parentTableOrNullObject: Word.Table;
Property Value
Remarks
rightIndent
Gets or sets the right indent value, in points, for the paragraph.
rightIndent: number;
Property Value
number
Remarks
spaceAfter
Gets or sets the spacing, in points, after the paragraph.
spaceAfter: number;
Property Value
number
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/paragraph-properties.yaml
await Word.run(async (context) => {
// Adjust space between paragraphs.
context.document.body.paragraphs.getFirst().spaceAfter = 20;
await context.sync();
});
spaceBefore
Gets or sets the spacing, in points, before the paragraph.
spaceBefore: number;
Property Value
number
Remarks
style
Gets or sets the style name for the paragraph. Use this property for custom styles and localized style names. To use the built-in styles that are portable between locales, see the "styleBuiltIn" property.
style: string;
Property Value
string
Remarks
styleBuiltIn
Gets or sets the built-in style name for the paragraph. Use this property for built-in styles that are portable between locales. To use custom styles or localized style names, see the "style" property.
styleBuiltIn: Word.Style | "Other" | "Normal" | "Heading1" | "Heading2" | "Heading3" | "Heading4" | "Heading5" | "Heading6" | "Heading7" | "Heading8" | "Heading9" | "Toc1" | "Toc2" | "Toc3" | "Toc4" | "Toc5" | "Toc6" | "Toc7" | "Toc8" | "Toc9" | "FootnoteText" | "Header" | "Footer" | "Caption" | "FootnoteReference" | "EndnoteReference" | "EndnoteText" | "Title" | "Subtitle" | "Hyperlink" | "Strong" | "Emphasis" | "NoSpacing" | "ListParagraph" | "Quote" | "IntenseQuote" | "SubtleEmphasis" | "IntenseEmphasis" | "SubtleReference" | "IntenseReference" | "BookTitle" | "Bibliography" | "TocHeading" | "TableGrid" | "PlainTable1" | "PlainTable2" | "PlainTable3" | "PlainTable4" | "PlainTable5" | "TableGridLight" | "GridTable1Light" | "GridTable1Light_Accent1" | "GridTable1Light_Accent2" | "GridTable1Light_Accent3" | "GridTable1Light_Accent4" | "GridTable1Light_Accent5" | "GridTable1Light_Accent6" | "GridTable2" | "GridTable2_Accent1" | "GridTable2_Accent2" | "GridTable2_Accent3" | "GridTable2_Accent4" | "GridTable2_Accent5" | "GridTable2_Accent6" | "GridTable3" | "GridTable3_Accent1" | "GridTable3_Accent2" | "GridTable3_Accent3" | "GridTable3_Accent4" | "GridTable3_Accent5" | "GridTable3_Accent6" | "GridTable4" | "GridTable4_Accent1" | "GridTable4_Accent2" | "GridTable4_Accent3" | "GridTable4_Accent4" | "GridTable4_Accent5" | "GridTable4_Accent6" | "GridTable5Dark" | "GridTable5Dark_Accent1" | "GridTable5Dark_Accent2" | "GridTable5Dark_Accent3" | "GridTable5Dark_Accent4" | "GridTable5Dark_Accent5" | "GridTable5Dark_Accent6" | "GridTable6Colorful" | "GridTable6Colorful_Accent1" | "GridTable6Colorful_Accent2" | "GridTable6Colorful_Accent3" | "GridTable6Colorful_Accent4" | "GridTable6Colorful_Accent5" | "GridTable6Colorful_Accent6" | "GridTable7Colorful" | "GridTable7Colorful_Accent1" | "GridTable7Colorful_Accent2" | "GridTable7Colorful_Accent3" | "GridTable7Colorful_Accent4" | "GridTable7Colorful_Accent5" | "GridTable7Colorful_Accent6" | "ListTable1Light" | "ListTable1Light_Accent1" | "ListTable1Light_Accent2" | "ListTable1Light_Accent3" | "ListTable1Light_Accent4" | "ListTable1Light_Accent5" | "ListTable1Light_Accent6" | "ListTable2" | "ListTable2_Accent1" | "ListTable2_Accent2" | "ListTable2_Accent3" | "ListTable2_Accent4" | "ListTable2_Accent5" | "ListTable2_Accent6" | "ListTable3" | "ListTable3_Accent1" | "ListTable3_Accent2" | "ListTable3_Accent3" | "ListTable3_Accent4" | "ListTable3_Accent5" | "ListTable3_Accent6" | "ListTable4" | "ListTable4_Accent1" | "ListTable4_Accent2" | "ListTable4_Accent3" | "ListTable4_Accent4" | "ListTable4_Accent5" | "ListTable4_Accent6" | "ListTable5Dark" | "ListTable5Dark_Accent1" | "ListTable5Dark_Accent2" | "ListTable5Dark_Accent3" | "ListTable5Dark_Accent4" | "ListTable5Dark_Accent5" | "ListTable5Dark_Accent6" | "ListTable6Colorful" | "ListTable6Colorful_Accent1" | "ListTable6Colorful_Accent2" | "ListTable6Colorful_Accent3" | "ListTable6Colorful_Accent4" | "ListTable6Colorful_Accent5" | "ListTable6Colorful_Accent6" | "ListTable7Colorful" | "ListTable7Colorful_Accent1" | "ListTable7Colorful_Accent2" | "ListTable7Colorful_Accent3" | "ListTable7Colorful_Accent4" | "ListTable7Colorful_Accent5" | "ListTable7Colorful_Accent6";
Property Value
Word.Style | "Other" | "Normal" | "Heading1" | "Heading2" | "Heading3" | "Heading4" | "Heading5" | "Heading6" | "Heading7" | "Heading8" | "Heading9" | "Toc1" | "Toc2" | "Toc3" | "Toc4" | "Toc5" | "Toc6" | "Toc7" | "Toc8" | "Toc9" | "FootnoteText" | "Header" | "Footer" | "Caption" | "FootnoteReference" | "EndnoteReference" | "EndnoteText" | "Title" | "Subtitle" | "Hyperlink" | "Strong" | "Emphasis" | "NoSpacing" | "ListParagraph" | "Quote" | "IntenseQuote" | "SubtleEmphasis" | "IntenseEmphasis" | "SubtleReference" | "IntenseReference" | "BookTitle" | "Bibliography" | "TocHeading" | "TableGrid" | "PlainTable1" | "PlainTable2" | "PlainTable3" | "PlainTable4" | "PlainTable5" | "TableGridLight" | "GridTable1Light" | "GridTable1Light_Accent1" | "GridTable1Light_Accent2" | "GridTable1Light_Accent3" | "GridTable1Light_Accent4" | "GridTable1Light_Accent5" | "GridTable1Light_Accent6" | "GridTable2" | "GridTable2_Accent1" | "GridTable2_Accent2" | "GridTable2_Accent3" | "GridTable2_Accent4" | "GridTable2_Accent5" | "GridTable2_Accent6" | "GridTable3" | "GridTable3_Accent1" | "GridTable3_Accent2" | "GridTable3_Accent3" | "GridTable3_Accent4" | "GridTable3_Accent5" | "GridTable3_Accent6" | "GridTable4" | "GridTable4_Accent1" | "GridTable4_Accent2" | "GridTable4_Accent3" | "GridTable4_Accent4" | "GridTable4_Accent5" | "GridTable4_Accent6" | "GridTable5Dark" | "GridTable5Dark_Accent1" | "GridTable5Dark_Accent2" | "GridTable5Dark_Accent3" | "GridTable5Dark_Accent4" | "GridTable5Dark_Accent5" | "GridTable5Dark_Accent6" | "GridTable6Colorful" | "GridTable6Colorful_Accent1" | "GridTable6Colorful_Accent2" | "GridTable6Colorful_Accent3" | "GridTable6Colorful_Accent4" | "GridTable6Colorful_Accent5" | "GridTable6Colorful_Accent6" | "GridTable7Colorful" | "GridTable7Colorful_Accent1" | "GridTable7Colorful_Accent2" | "GridTable7Colorful_Accent3" | "GridTable7Colorful_Accent4" | "GridTable7Colorful_Accent5" | "GridTable7Colorful_Accent6" | "ListTable1Light" | "ListTable1Light_Accent1" | "ListTable1Light_Accent2" | "ListTable1Light_Accent3" | "ListTable1Light_Accent4" | "ListTable1Light_Accent5" | "ListTable1Light_Accent6" | "ListTable2" | "ListTable2_Accent1" | "ListTable2_Accent2" | "ListTable2_Accent3" | "ListTable2_Accent4" | "ListTable2_Accent5" | "ListTable2_Accent6" | "ListTable3" | "ListTable3_Accent1" | "ListTable3_Accent2" | "ListTable3_Accent3" | "ListTable3_Accent4" | "ListTable3_Accent5" | "ListTable3_Accent6" | "ListTable4" | "ListTable4_Accent1" | "ListTable4_Accent2" | "ListTable4_Accent3" | "ListTable4_Accent4" | "ListTable4_Accent5" | "ListTable4_Accent6" | "ListTable5Dark" | "ListTable5Dark_Accent1" | "ListTable5Dark_Accent2" | "ListTable5Dark_Accent3" | "ListTable5Dark_Accent4" | "ListTable5Dark_Accent5" | "ListTable5Dark_Accent6" | "ListTable6Colorful" | "ListTable6Colorful_Accent1" | "ListTable6Colorful_Accent2" | "ListTable6Colorful_Accent3" | "ListTable6Colorful_Accent4" | "ListTable6Colorful_Accent5" | "ListTable6Colorful_Accent6" | "ListTable7Colorful" | "ListTable7Colorful_Accent1" | "ListTable7Colorful_Accent2" | "ListTable7Colorful_Accent3" | "ListTable7Colorful_Accent4" | "ListTable7Colorful_Accent5" | "ListTable7Colorful_Accent6"
Remarks
tableNestingLevel
Gets the level of the paragraph's table. It returns 0 if the paragraph is not in a table. Read-only.
readonly tableNestingLevel: number;
Property Value
number
Remarks
text
Gets the text of the paragraph. Read-only.
readonly text: string;
Property Value
string
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/get-paragraph-on-insertion-point.yaml
await Word.run(async (context) => {
// The collection of paragraphs of the current selection returns the full paragraphs contained in it.
let paragraph = context.document.getSelection().paragraphs.getFirst();
paragraph.load("text");
await context.sync();
console.log(paragraph.text);
});
Method Details
attachToList(listId, level)
Lets the paragraph join an existing list at the specified level. Fails if the paragraph cannot join the list or if the paragraph is already a list item.
attachToList(listId: number, level: number): Word.List;
Parameters
- listId
-
number
Required. The ID of an existing list.
- level
-
number
Required. The level in the list.
Returns
Remarks
clear()
Clears the contents of the paragraph object. The user can perform the undo operation on the cleared content.
clear(): void;
Returns
void
Remarks
Examples
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the paragraphs collection.
var paragraphs = context.document.body.paragraphs;
// Queue a command to load the style property for all of the paragraphs.
context.load(paragraphs, 'style');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
// Queue a command to clear the contents of the first paragraph.
paragraphs.items[0].clear();
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Cleared the contents of the first paragraph.');
});
delete()
Deletes the paragraph and its content from the document.
delete(): void;
Returns
void
Remarks
Examples
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the paragraphs collection.
var paragraphs = context.document.body.paragraphs;
// Queue a command to load the text property for all of the paragraphs.
context.load(paragraphs, 'text');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
// Queue a command to delete the first paragraph.
paragraphs.items[0].delete();
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Deleted the first paragraph.');
});
detachFromList()
Moves this paragraph out of its list, if the paragraph is a list item.
detachFromList(): void;
Returns
void
Remarks
getComments()
Gets comments associated with the paragraph.
getComments(): Word.CommentCollection;
Returns
Remarks
getHtml()
Gets an HTML representation of the paragraph object. When rendered in a web page or HTML viewer, the formatting will be a close, but not exact, match for of the formatting of the document. This method does not return the exact same HTML for the same document on different platforms (Windows, Mac, Word on the web, etc.). If you need exact fidelity, or consistency across platforms, use Paragraph.getOoxml()
and convert the returned XML to HTML.
getHtml(): OfficeExtension.ClientResult<string>;
Returns
OfficeExtension.ClientResult<string>
Remarks
Examples
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the paragraphs collection.
var paragraphs = context.document.body.paragraphs;
// Queue a command to load the style property for all of the paragraphs.
context.load(paragraphs, 'style');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
// Queue a set of commands to get the HTML of the first paragraph.
var html = paragraphs.items[0].getHtml();
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Paragraph HTML: ' + html.value);
});
getNext()
Gets the next paragraph. Throws an error if the paragraph is the last one.
getNext(): Word.Paragraph;
Returns
Remarks
getNextOrNullObject()
Gets the next paragraph. Returns a null object if the paragraph is the last one.
getNextOrNullObject(): Word.Paragraph;
Returns
Remarks
getOoxml()
Gets the Office Open XML (OOXML) representation of the paragraph object.
getOoxml(): OfficeExtension.ClientResult<string>;
Returns
OfficeExtension.ClientResult<string>
Remarks
Examples
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the paragraphs collection.
var paragraphs = context.document.body.paragraphs;
// Queue a command to load the style property for the top 2 paragraphs.
context.load(paragraphs, {select: 'style', top: 2} );
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
// Queue a set of commands to get the OOXML of the first paragraph.
var ooxml = paragraphs.items[0].getOoxml();
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Paragraph OOXML: ' + ooxml.value);
});
getPrevious()
Gets the previous paragraph. Throws an error if the paragraph is the first one.
getPrevious(): Word.Paragraph;
Returns
Remarks
getPreviousOrNullObject()
Gets the previous paragraph. Returns a null object if the paragraph is the first one.
getPreviousOrNullObject(): Word.Paragraph;
Returns
Remarks
Examples
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the paragraphs collection.
var paragraphs = context.document.body.paragraphs;
// Queue a command to load the text property for all of the paragraphs.
context.load(paragraphs, 'text');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
// Queue commands to create a proxy object for the next-to-last paragraph.
var indexOfLastParagraph = paragraphs.items.length - 1;
var precedingParagraph = paragraphs.items[indexOfLastParagraph].getPreviousOrNullObject();
// Queue a command to load the text of the preceding paragraph.
context.load(precedingParagraph, 'text');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
if (precedingParagraph.isNullObject) {
console.log('There are no paragraphs before the current one.');
} else {
console.log('The preceding paragraph is: ' + precedingParagraph.text);
}
});
getRange(rangeLocation)
Gets the whole paragraph, or the starting or ending point of the paragraph, as a range.
getRange(rangeLocation?: Word.RangeLocation): Word.Range;
Parameters
- rangeLocation
- Word.RangeLocation
Optional. The range location must be 'Whole', 'Start', 'End', 'After', or 'Content'.
Returns
Remarks
getRange(rangeLocationString)
Gets the whole paragraph, or the starting or ending point of the paragraph, as a range.
getRange(rangeLocationString?: "Whole" | "Start" | "End" | "Before" | "After" | "Content"): Word.Range;
Parameters
- rangeLocationString
-
"Whole" | "Start" | "End" | "Before" | "After" | "Content"
Optional. The range location must be 'Whole', 'Start', 'End', 'After', or 'Content'.
Returns
Remarks
getReviewedText(changeTrackingVersion)
Gets reviewed text based on ChangeTrackingVersion selection.
getReviewedText(changeTrackingVersion?: Word.ChangeTrackingVersion): OfficeExtension.ClientResult<string>;
Parameters
- changeTrackingVersion
- Word.ChangeTrackingVersion
Optional. The value must be 'Original' or 'Current'. The default is 'Current'.
Returns
OfficeExtension.ClientResult<string>
Remarks
getReviewedText(changeTrackingVersionString)
Gets reviewed text based on ChangeTrackingVersion selection.
getReviewedText(changeTrackingVersionString?: "Original" | "Current"): OfficeExtension.ClientResult<string>;
Parameters
- changeTrackingVersionString
-
"Original" | "Current"
Optional. The value must be 'Original' or 'Current'. The default is 'Current'.
Returns
OfficeExtension.ClientResult<string>
Remarks
getTextRanges(endingMarks, trimSpacing)
Gets the text ranges in the paragraph by using punctuation marks and/or other ending marks.
getTextRanges(endingMarks: string[], trimSpacing?: boolean): Word.RangeCollection;
Parameters
- endingMarks
-
string[]
Required. The punctuation marks and/or other ending marks as an array of strings.
- trimSpacing
-
boolean
Optional. Indicates whether to trim spacing characters (spaces, tabs, column breaks, and paragraph end marks) from the start and end of the ranges returned in the range collection. Default is false which indicates that spacing characters at the start and end of the ranges are included in the range collection.
Returns
Remarks
insertBreak(breakType, insertLocation)
Inserts a break at the specified location in the main document.
insertBreak(breakType: Word.BreakType, insertLocation: Word.InsertLocation): void;
Parameters
- breakType
- Word.BreakType
Required. The break type to add to the document.
- insertLocation
- Word.InsertLocation
Required. The value must be 'Before' or 'After'.
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/insert-line-and-page-breaks.yaml
Word.run(async (context) => {
context.document.body.paragraphs.getFirst().insertBreak(Word.BreakType.line, "After");
await context.sync();
console.log("success");
});
insertBreak(breakTypeString, insertLocation)
Inserts a break at the specified location in the main document.
insertBreak(breakTypeString: "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line", insertLocation: "Before" | "After" | "Start" | "End" | "Replace"): void;
Parameters
- breakTypeString
-
"Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line"
Required. The break type to add to the document.
- insertLocation
-
"Before" | "After" | "Start" | "End" | "Replace"
Required. The value must be 'Before' or 'After'.
Returns
void
Remarks
Examples
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the paragraphs collection.
var paragraphs = context.document.body.paragraphs;
// Queue a command to load the style property for the top 2 paragraphs.
// We never perform an empty load. We always must request a property.
context.load(paragraphs, {select: 'style', top: 2} );
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
// Queue a command to get the first paragraph.
var paragraph = paragraphs.items[0];
// Queue a command to insert a page break after the first paragraph.
paragraph.insertBreak(Word.BreakType.page, Word.InsertLocation.after);
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Inserted a page break after the paragraph.');
});
insertContentControl()
Wraps the paragraph object with a rich text content control.
insertContentControl(): Word.ContentControl;
Returns
Remarks
Examples
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the paragraphs collection.
var paragraphs = context.document.body.paragraphs;
// Queue a command to load the style property for the top 2 paragraphs.
// We never perform an empty load. We always must request a property.
context.load(paragraphs, {select: 'style', top: 2} );
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
// Queue a command to get the first paragraph.
var paragraph = paragraphs.items[0];
// Queue a command to wrap the first paragraph in a rich text content control.
paragraph.insertContentControl();
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Wrapped the first paragraph in a content control.');
});
insertFileFromBase64(base64File, insertLocation)
Inserts a document into the paragraph at the specified location.
insertFileFromBase64(base64File: string, insertLocation: Word.InsertLocation): Word.Range;
Parameters
- base64File
-
string
Required. The base64 encoded content of a .docx file.
- insertLocation
- Word.InsertLocation
Required. The value must be 'Replace', 'Start', or 'End'.
Returns
Remarks
insertFileFromBase64(base64File, insertLocationString)
Inserts a document into the paragraph at the specified location.
insertFileFromBase64(base64File: string, insertLocationString: "Before" | "After" | "Start" | "End" | "Replace"): Word.Range;
Parameters
- base64File
-
string
Required. The base64 encoded content of a .docx file.
- insertLocationString
-
"Before" | "After" | "Start" | "End" | "Replace"
Required. The value must be 'Replace', 'Start', or 'End'.
Returns
Remarks
insertHtml(html, insertLocation)
Inserts HTML into the paragraph at the specified location.
insertHtml(html: string, insertLocation: Word.InsertLocation): Word.Range;
Parameters
- html
-
string
Required. The HTML to be inserted in the paragraph.
- insertLocation
- Word.InsertLocation
Required. The value must be 'Replace', 'Start', or 'End'.
Returns
Remarks
Examples
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the paragraphs collection.
var paragraphs = context.document.body.paragraphs;
// Queue a command to load the style property for the top 2 paragraphs.
// We never perform an empty load. We always must request a property.
context.load(paragraphs, {select: 'style', top: 2} );
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
// Queue a command to get the first paragraph.
var paragraph = paragraphs.items[0];
// Queue a command to insert HTML content at the end of the first paragraph.
paragraph.insertHtml('<strong>Inserted HTML.</strong>', Word.InsertLocation.end);
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Inserted HTML content at the end of the first paragraph.');
});
insertHtml(html, insertLocationString)
Inserts HTML into the paragraph at the specified location.
insertHtml(html: string, insertLocationString: "Before" | "After" | "Start" | "End" | "Replace"): Word.Range;
Parameters
- html
-
string
Required. The HTML to be inserted in the paragraph.
- insertLocationString
-
"Before" | "After" | "Start" | "End" | "Replace"
Required. The value must be 'Replace', 'Start', or 'End'.
Returns
Remarks
insertInlinePictureFromBase64(base64EncodedImage, insertLocation)
Inserts a picture into the paragraph at the specified location.
insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: Word.InsertLocation): Word.InlinePicture;
Parameters
- base64EncodedImage
-
string
Required. The base64 encoded image to be inserted.
- insertLocation
- Word.InsertLocation
Required. The value must be 'Replace', 'Start', or 'End'.
Returns
Remarks
Examples
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the paragraphs collection.
var paragraphs = context.document.body.paragraphs;
// Queue a command to load the style property for all of the paragraphs.
context.load(paragraphs, 'style');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
// Queue a command to get the first paragraph.
var paragraph = paragraphs.items[0];
var b64encodedImg = "iVBORw0KGgoAAAANSUhEUgAAAB4AAAANCAIAAAAxEEnAAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACFSURBVDhPtY1BEoQwDMP6/0+XgIMTBAeYoTqso9Rkx1zG+tNj1H94jgGzeNSjteO5vtQQuG2seO0av8LzGbe3anzRoJ4ybm/VeKEerAEbAUpW4aWQCmrGFWykRzGBCnYy2ha3oAIq2MloW9yCCqhgJ6NtcQsqoIKdjLbFLaiACnYyf2fODbrjZcXfr2F4AAAAAElFTkSuQmCC";
// Queue a command to insert a base64 encoded image at the beginning of the first paragraph.
paragraph.insertInlinePictureFromBase64(b64encodedImg, Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Added an image to the first paragraph.');
});
insertInlinePictureFromBase64(base64EncodedImage, insertLocationString)
Inserts a picture into the paragraph at the specified location.
insertInlinePictureFromBase64(base64EncodedImage: string, insertLocationString: "Before" | "After" | "Start" | "End" | "Replace"): Word.InlinePicture;
Parameters
- base64EncodedImage
-
string
Required. The base64 encoded image to be inserted.
- insertLocationString
-
"Before" | "After" | "Start" | "End" | "Replace"
Required. The value must be 'Replace', 'Start', or 'End'.
Returns
Remarks
insertOoxml(ooxml, insertLocation)
Inserts OOXML into the paragraph at the specified location.
insertOoxml(ooxml: string, insertLocation: Word.InsertLocation): Word.Range;
Parameters
- ooxml
-
string
Required. The OOXML to be inserted in the paragraph.
- insertLocation
- Word.InsertLocation
Required. The value must be 'Replace', 'Start', or 'End'.
Returns
Remarks
insertOoxml(ooxml, insertLocationString)
Inserts OOXML into the paragraph at the specified location.
insertOoxml(ooxml: string, insertLocationString: "Before" | "After" | "Start" | "End" | "Replace"): Word.Range;
Parameters
- ooxml
-
string
Required. The OOXML to be inserted in the paragraph.
- insertLocationString
-
"Before" | "After" | "Start" | "End" | "Replace"
Required. The value must be 'Replace', 'Start', or 'End'.
Returns
Remarks
insertParagraph(paragraphText, insertLocation)
Inserts a paragraph at the specified location.
insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation): Word.Paragraph;
Parameters
- paragraphText
-
string
Required. The paragraph text to be inserted.
- insertLocation
- Word.InsertLocation
Required. The value must be 'Before' or 'After'.
Returns
Remarks
insertParagraph(paragraphText, insertLocationString)
Inserts a paragraph at the specified location.
insertParagraph(paragraphText: string, insertLocationString: "Before" | "After" | "Start" | "End" | "Replace"): Word.Paragraph;
Parameters
- paragraphText
-
string
Required. The paragraph text to be inserted.
- insertLocationString
-
"Before" | "After" | "Start" | "End" | "Replace"
Required. The value must be 'Before' or 'After'.
Returns
Remarks
insertTable(rowCount, columnCount, insertLocation, values)
Inserts a table with the specified number of rows and columns.
insertTable(rowCount: number, columnCount: number, insertLocation: Word.InsertLocation, values?: string[][]): Word.Table;
Parameters
- rowCount
-
number
Required. The number of rows in the table.
- columnCount
-
number
Required. The number of columns in the table.
- insertLocation
- Word.InsertLocation
Required. The value must be 'Before' or 'After'.
- values
-
string[][]
Optional 2D array. Cells are filled if the corresponding strings are specified in the array.
Returns
Remarks
insertTable(rowCount, columnCount, insertLocationString, values)
Inserts a table with the specified number of rows and columns.
insertTable(rowCount: number, columnCount: number, insertLocationString: "Before" | "After" | "Start" | "End" | "Replace", values?: string[][]): Word.Table;
Parameters
- rowCount
-
number
Required. The number of rows in the table.
- columnCount
-
number
Required. The number of columns in the table.
- insertLocationString
-
"Before" | "After" | "Start" | "End" | "Replace"
Required. The value must be 'Before' or 'After'.
- values
-
string[][]
Optional 2D array. Cells are filled if the corresponding strings are specified in the array.
Returns
Remarks
insertText(text, insertLocation)
Inserts text into the paragraph at the specified location.
insertText(text: string, insertLocation: Word.InsertLocation): Word.Range;
Parameters
- text
-
string
Required. Text to be inserted.
- insertLocation
- Word.InsertLocation
Required. The value must be 'Replace', 'Start', or 'End'.
Returns
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/insert-in-different-locations.yaml
await Word.run(async (context) => {
// Replace the last paragraph.
let range = context.document.body.paragraphs.getLast().insertText("Just replaced the last paragraph!", "Replace");
range.font.highlightColor = "black";
range.font.color = "white";
await context.sync();
});
insertText(text, insertLocationString)
Inserts text into the paragraph at the specified location.
insertText(text: string, insertLocationString: "Before" | "After" | "Start" | "End" | "Replace"): Word.Range;
Parameters
- text
-
string
Required. Text to be inserted.
- insertLocationString
-
"Before" | "After" | "Start" | "End" | "Replace"
Required. The value must be 'Replace', 'Start', or 'End'.
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.ParagraphLoadOptions): Word.Paragraph;
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.Paragraph;
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.Paragraph;
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
search(searchText, searchOptions)
Performs a search with the specified SearchOptions on the scope of the paragraph object. The search results are a collection of range objects.
search(searchText: string, searchOptions?: Word.SearchOptions | {
ignorePunct?: boolean;
ignoreSpace?: boolean;
matchCase?: boolean;
matchPrefix?: boolean;
matchSuffix?: boolean;
matchWholeWord?: boolean;
matchWildcards?: boolean;
}): Word.RangeCollection;
Parameters
- searchText
-
string
Required. The search text.
- searchOptions
-
Word.SearchOptions | { ignorePunct?: boolean; ignoreSpace?: boolean; matchCase?: boolean; matchPrefix?: boolean; matchSuffix?: boolean; matchWholeWord?: boolean; matchWildcards?: boolean; }
Optional. Options for the search.
Returns
Remarks
select(selectionMode)
Selects and navigates the Word UI to the paragraph.
select(selectionMode?: Word.SelectionMode): void;
Parameters
- selectionMode
- Word.SelectionMode
Optional. The selection mode must be 'Select', 'Start', or 'End'. 'Select' is the default.
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/scroll-to-range.yaml
await Word.run(async (context) => {
// If select is called with no parameters, it selects the object.
context.document.body.paragraphs.getLast().select();
await context.sync();
});
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/scroll-to-range.yaml
await Word.run(async (context) => {
// Select can be at the start or end of a range; this by definition moves the insertion point without selecting the range.
context.document.body.paragraphs.getLast().select("End");
await context.sync();
});
select(selectionModeString)
Selects and navigates the Word UI to the paragraph.
select(selectionModeString?: "Select" | "Start" | "End"): void;
Parameters
- selectionModeString
-
"Select" | "Start" | "End"
Optional. The selection mode must be 'Select', 'Start', or 'End'. 'Select' is the default.
Returns
void
Remarks
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.ParagraphUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- Word.Interfaces.ParagraphUpdateData
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
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/90-scenarios/multiple-property-set.yaml
await Word.run(async (context) => {
const paragraph = context.document.body.paragraphs.getFirst();
paragraph.set({
leftIndent: 30,
font: {
bold: true,
color: "red"
}
});
await context.sync();
});
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/90-scenarios/multiple-property-set.yaml
await Word.run(async (context) => {
const firstParagraph = context.document.body.paragraphs.getFirst();
const secondParagraph = firstParagraph.getNext();
firstParagraph.load("text, font/color, font/bold, leftIndent");
await context.sync();
secondParagraph.set(firstParagraph);
await context.sync();
});
set(properties)
Sets multiple properties on the object at the same time, based on an existing loaded object.
set(properties: Word.Paragraph): void;
Parameters
- properties
- Word.Paragraph
Returns
void
split(delimiters, trimDelimiters, trimSpacing)
Splits the paragraph into child ranges by using delimiters.
split(delimiters: string[], trimDelimiters?: boolean, trimSpacing?: boolean): Word.RangeCollection;
Parameters
- delimiters
-
string[]
Required. The delimiters as an array of strings.
- trimDelimiters
-
boolean
Optional. Indicates whether to trim delimiters from the ranges in the range collection. Default is false which indicates that the delimiters are included in the ranges returned in the range collection.
- trimSpacing
-
boolean
Optional. Indicates whether to trim spacing characters (spaces, tabs, column breaks, and paragraph end marks) from the start and end of the ranges returned in the range collection. Default is false which indicates that spacing characters at the start and end of the ranges are included in the range collection.
Returns
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/split-words-of-first-paragraph.yaml
await Word.run(async (context) => {
let paragraph = context.document.body.paragraphs.getFirst();
let words = paragraph.split([" "], true /* trimDelimiters*/, true /* trimSpaces */);
words.load("text");
await context.sync();
for (let i = 0; i < words.items.length; i++) {
if (i >= 1) {
words.items[i - 1].font.highlightColor = "#FFFFFF";
}
words.items[i].font.highlightColor = "#FFFF00";
await context.sync();
await pause(200);
}
});
startNewList()
Starts a new list with this paragraph. Fails if the paragraph is already a list item.
startNewList(): Word.List;
Returns
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/20-lists/insert-list.yaml
// This example starts a new list stating with the second paragraph.
await Word.run(async (context) => {
let paragraphs = context.document.body.paragraphs;
paragraphs.load("$none"); // No properties needed.
await context.sync();
var list = paragraphs.items[1].startNewList(); // Indicates new list to be started in the second paragraph.
list.load("$none"); // No properties needed.
await context.sync();
// To add new items to the list use start/end on the insert location parameter.
list.insertParagraph("New list item on top of the list", "Start");
let paragraph = list.insertParagraph("New list item at the end of the list (4th level)", "End");
paragraph.listItem.level = 4; // Sets up list level for the lsit item.
// To add paragraphs outside the list use before/after:
list.insertParagraph("New paragraph goes after (not part of the list)", "After");
await context.sync();
});
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 is passed to it.) Whereas the original Word.Paragraph object is an API object, the toJSON
method returns a plain JavaScript object (typed as Word.Interfaces.ParagraphData
) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Word.Interfaces.ParagraphData;
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 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.Paragraph;
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 will need to call context.sync()
before the memory release takes effect.
untrack(): Word.Paragraph;
Returns
Feedback
Submit and view feedback for