Word.Document class
The Document object is the top level object. A Document object contains one or more sections, content controls, and the body that contains the contents of the document.
- Extends
Remarks
Used by
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-change-tracking.yaml
// Gets the current change tracking mode.
await Word.run(async (context) => {
const document: Word.Document = context.document;
document.load("changeTrackingMode");
await context.sync();
if (document.changeTrackingMode === Word.ChangeTrackingMode.trackMineOnly) {
console.log("Only my changes are being tracked.");
} else if (document.changeTrackingMode === Word.ChangeTrackingMode.trackAll) {
console.log("Everyone's changes are being tracked.");
} else {
console.log("No changes are being tracked.");
}
});
Properties
| active |
Gets the name of the active theme and formatting options. |
| active |
Gets the display name of the active theme. |
| active |
Gets the active window for the document. |
| are |
Gets whether Word encrypts file properties for password-protected documents. |
| are |
Specifies whether grammatical errors are marked by a wavy green line in the document. |
| are |
Specifies whether to use the default math settings when creating new equations. |
| are |
Specifies whether to disable features introduced after a specified version. |
| are |
Specifies whether Microsoft Word underlines spelling errors in the document. |
| are |
Specifies whether the styles in this document are updated to match the styles in the attached template each time the document is opened. |
| are |
Specifies whether Microsoft Word embeds TrueType fonts in the document when it's saved. |
| attached |
Specifies a |
| auto |
Specifies if automatic hyphenation is turned on for the document. |
| auto |
Specifies if the edits in the document are automatically saved. |
| background | Gets a |
| bibliography | Returns a |
| body | Gets the |
| bookmarks | Returns a |
| built |
Gets a |
| change |
Specifies the ChangeTracking mode. |
| characters | Gets the |
| coauthoring | Gets a |
| code |
Gets the code name for the document. |
| comments | Gets a |
| compatibility |
Gets the compatibility mode that Word uses when opening the document. |
| consecutive |
Specifies the maximum number of consecutive lines that can end with hyphens. |
| content | Gets a |
| content |
Gets the collection of |
| context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
| current |
Gets a random number that Word assigns to changes in the document. |
| custom |
Gets a |
| custom |
Gets the custom XML parts in the document. |
| default |
Specifies the interval (in points) between the default tab stops in the document. |
| default |
Specifies the browser frame for displaying a webpage via hyperlink. |
| document |
Returns a |
| do |
Specifies whether Word should not embed common system fonts. |
| encryption |
Specifies the name of the algorithm encryption provider that Microsoft Word uses when encrypting documents. |
| far |
Specifies the East Asian language used for line breaking. |
| far |
Specifies the line break control level. |
| fields | Gets a |
| formatting |
Specifies whether Word shows the next heading level when the previous is used. |
| formatting |
Specifies whether to show user-defined styles. |
| frames | Returns a |
| full |
Gets the name of a document, including the path. |
| grammatical |
Gets a |
| grid |
Specifies the horizontal space between invisible gridlines that Microsoft Word uses when you draw, move, and resize AutoShapes or East Asian characters in the document. |
| grid |
Specifies the vertical space between invisible gridlines that Microsoft Word uses when you draw, move, and resize AutoShapes or East Asian characters in the document. |
| grid |
Specifies whether the character grid starts from the upper-left corner of the page. |
| grid |
Specifies the horizontal origin point for the invisible grid. |
| grid |
Specifies the vertical origin point for the invisible grid. |
| grid |
Specifies the interval for horizontal character gridlines in print layout view. |
| grid |
Specifies the interval for vertical character gridlines in print layout view. |
| has |
Gets whether a password is required to open the document. |
| has |
Gets whether the document has an attached Microsoft Visual Basic for Applications project. |
| hyperlinks | Returns a |
| hyphenate |
Specifies whether words in all capital letters can be hyphenated. |
| hyphenation |
Specifies the width of the hyphenation zone, in points. |
| indexes | Returns an |
| is |
Specifies whether automatic formatting options override formatting restrictions. |
| is |
Specifies whether charts in the active document use cell-reference data-point tracking. |
| is |
Specifies whether the compatibility option specified by the |
| is |
Specifies whether the document is final. |
| is |
Specifies whether Microsoft Word saves a subset of the embedded TrueType fonts with the document. |
| is |
Specifies whether Microsoft Word prints onto a preprinted form only the data entered in the corresponding online form. |
| is |
Specifies whether Microsoft Word saves the data entered in a form as a tab-delimited record for use in a database. |
| is |
Specifies whether a grammar check has been run on the document. |
| is |
Gets whether the most recent firing of the |
| is |
Gets whether the document is in form design mode. |
| is |
Specifies whether Word kerns half-width Latin characters and punctuation marks. |
| is |
Specifies whether to embed speech and handwriting data. |
| is |
Gets whether this document is a master document. |
| is |
Specifies whether Word optimizes the document for Word 97. |
| is |
Specifies whether PRINT field instructions (such as PostScript commands) in the document are to be printed on top of text and graphics when a PostScript printer is used. |
| is |
Specifies whether users can change the Quick Style set. |
| is |
Gets whether changes to the document cannot be saved to the original document. |
| is |
Specifies whether Microsoft Word displays a message box whenever a user opens the document, suggesting that it be opened as read-only. |
| is |
Specifies whether AutoShapes or East Asian characters are automatically aligned with an invisible grid. |
| is |
Specifies whether AutoShapes or East Asian characters align with invisible gridlines through other shapes. |
| is |
Specifies whether spelling has been checked throughout the document. |
| is |
Specifies whether formatting restrictions are enforced in a protected document. |
| is |
Gets whether this document is a subdocument of a master document. |
| is |
Specifies whether users can change the document theme. |
| is |
Specifies whether the document was created or opened by the user. |
| is |
Gets whether the VBA project is digitally signed. |
| is |
Gets whether the document is protected with a write password. |
| justification |
Specifies the character spacing adjustment. |
| kind | Specifies the format type that Microsoft Word uses when automatically formatting the document. |
| language |
Specifies whether Microsoft Word has detected the language of the document text. |
| list |
Gets a |
| lists | Gets a |
| list |
Returns a |
| no |
Specifies the kinsoku characters after which Word will not break a line. |
| no |
Specifies the kinsoku characters before which Word will not break a line. |
| open |
Gets the encoding used to open the document. |
| original |
Gets the title of the original document after legal-blackline comparison. |
| page |
Returns a |
| paragraphs | Gets a |
| password | Sets a password that must be supplied to open the document. |
| password |
Gets the algorithm used for password encryption. |
| password |
Gets the key length used for password encryption. |
| password |
Gets the name of the password encryption provider. |
| path | Gets the disk or the web path to the document (excludes the document name). |
| print |
Specifies whether revision marks are printed with the document. |
| properties | Gets the properties of the document. |
| protection |
Gets the protection type for the document. |
| readability |
Gets a |
| reading |
Specifies the width of pages in reading layout view when frozen. |
| reading |
Specifies the height of pages in reading layout view when frozen. |
| reading |
Specifies whether pages in reading layout view are frozen for handwritten markup. |
| remove |
Specifies whether Word removes user information upon saving. |
| revised |
Gets the title of the revised document after legal-blackline comparison. |
| revisions | Gets the collection of revisions that represents the tracked changes in the document. |
| saved | Indicates whether the changes in the document have been saved. A value of |
| save |
Specifies the encoding used when saving the document. |
| save |
Gets the file format of the document. |
| sections | Gets the collection of |
| selection | Returns a |
| sensitivity |
Returns the sensitivity label of the document. |
| sentences | Gets the |
| settings | Gets the add-in's settings in the document. |
| spelling |
Gets a |
| story |
Gets a |
| styles | Gets a |
| table |
Returns a |
| tables | Gets a |
| tables |
Returns a |
| tables |
Returns a |
| tables |
Returns a |
| text |
Specifies the encoding for saving as encoded text. |
| text |
Specifies how Word marks line and paragraph breaks in text files. |
| tracked |
Specifies whether to remove or store date and time metadata for tracked changes. |
| track |
Specifies whether to track formatting changes when change tracking is on. |
| track |
Specifies whether to mark moved text when Track Changes is on. |
| track |
Specifies whether changes are tracked in the document. |
| type | Gets the document type (template or document). |
| web |
Gets the |
| windows | Gets the collection of |
| words | Gets the |
| write |
Sets a password for saving changes to the document. |
| xml |
Specifies whether error messages are generated from built-in Word messages or MSXML (Microsoft XML). |
| xml |
Specifies whether to save a document through an Extensible Stylesheet Language Transformation (XSLT). |
| xml |
Specifies the path and file name for the XSLT to apply when saving a document. |
Methods
| accept |
Accepts all tracked changes in the document. |
| accept |
Accepts all revisions in the document that are displayed on the screen. |
| activate() | Activates the document so that it becomes the active document. |
| add |
Adds a style into the document by name and type. |
| add |
Adds a style into the document by name and type. |
| add |
Creates a shortcut to the document or hyperlink and adds it to the Favorites folder. |
| apply |
Applies the specified Quick Style set to the document. |
| apply |
Applies the specified Quick Style set to the document. |
| apply |
Applies the specified theme to this document. |
| auto |
Automatically formats the document. |
| can |
Returns |
| check |
Searches all text in a Japanese language document and displays instances where character usage is inconsistent for the same words. |
| check |
Begins a spelling and grammar check for the document. |
| check |
Checks in the document from the local computer to a server and sets the local document to read-only so that it cannot be edited locally. |
| check |
Saves the document to a server from a local computer, and sets the local document to read-only so that it cannot be edited locally. |
| check |
Begins a spelling check for the document. |
| close(close |
Closes the current document. Note: This API isn't supported in Word on the web. |
| close(close |
Closes the current document. Note: This API isn't supported in Word on the web. |
| close |
Switches the document from print preview to the previous view. |
| compare(file |
Displays revision marks that indicate where the specified document differs from another document. |
| compare |
Displays revision marks that indicate where the specified document differs from another document. |
| compute |
Returns a statistic based on the contents of the document. |
| compute |
Returns a statistic based on the contents of the document. |
| convert() | Converts the file to the newest format and enables all features. |
| convert |
Converts automatic hyphens to manual hyphens. |
| convert |
Changes the list numbers and LISTNUM fields in the document to text. |
| convert |
Changes the list numbers and LISTNUM fields in the document to text. |
| convert |
Reconverts a Vietnamese document to Unicode using a code page other than the default. |
| copy |
Copies styles from the specified template to the document. |
| count |
Returns the number of bulleted or numbered items and LISTNUM fields in the document. |
| delete |
Deletes all comments from the document. |
| delete |
Deletes all revisions in the document that are displayed on the screen. |
| delete |
Deletes all handwritten ink annotations in the document. |
| delete |
Deletes a bookmark, if it exists, from the document. |
| detect |
Analyzes the document text to determine the language. |
| end |
Terminates a review of the file that has been sent for review. |
| export |
Saves the document in PDF or XPS format. |
| export |
Saves the document in PDF or XPS format. |
| export |
Saves the document in PDF or XPS format. |
| export |
Saves the document in PDF or XPS format. |
| export |
Saves the document in PDF or XPS format with improved tagging. |
| export |
Saves the document in PDF or XPS format with improved tagging. |
| fit |
Decreases the font size of text just enough so that the document page count drops by one. |
| follow |
Displays a cached document, if it has already been downloaded. Otherwise, this method resolves the hyperlink, downloads the target document, and displays the document in the appropriate application. |
| freeze |
Fixes the layout of the document in Web view. |
| get |
Gets the annotation by ID. Throws an |
| get |
Gets a bookmark's range. Throws an |
| get |
Gets a bookmark's range. If the bookmark doesn't exist, then this method will return an object with its |
| get |
Gets the currently supported content controls in the document. |
| get |
Returns an array of items that can be cross-referenced based on the specified cross-reference type. |
| get |
Returns an array of items that can be cross-referenced based on the specified cross-reference type. |
| get |
Gets the document's endnotes in a single body. |
| get |
Gets the document's footnotes in a single body. |
| get |
Gets the paragraph by its unique local ID. Throws an |
| get |
Returns a |
| get |
Gets the current selection of the document. Multiple selections aren't supported. |
| get |
Gets a |
| go |
Returns a |
| import |
Import styles from a JSON-formatted string. |
| import |
Import styles from a JSON-formatted string. |
| insert |
Inserts a document into the target document at a specific location with additional properties. Headers, footers, watermarks, and other section properties are copied by default. |
| 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 |
| lock |
Locks the file on the server preventing anyone else from editing it. |
| make |
Sets the compatibility options. |
| manual |
Initiates manual hyphenation of a document, one line at a time. |
| merge(file |
Merges the changes marked with revision marks from one document to another. |
| post() | Posts the document to a public folder in Microsoft Exchange. |
| present |
Opens PowerPoint with the Word document loaded. |
| print |
Prints all or part of the document. |
| print |
Switches the view to print preview. |
| protect(type, options) | Protects the document from unauthorized changes. |
| protect(type, options) | Protects the document from unauthorized changes. |
| redo(times) | Redoes the last action that was undone (reverses the |
| reject |
Rejects all tracked changes in the document. |
| reject |
Rejects all revisions in the document that are displayed on the screen. |
| reload() | Reloads a cached document by resolving the hyperlink to the document and downloading it. |
| reload |
Reloads the document based on an HTML document, using the document encoding. |
| reload |
Reloads the document based on an HTML document, using the document encoding. |
| remove |
Removes sensitive information, properties, comments, and other metadata from the document. |
| remove |
Removes sensitive information, properties, comments, and other metadata from the document. |
| remove |
Purges the document of locked styles when formatting restrictions have been applied in the document. |
| remove |
Removes numbers or bullets from the document. |
| remove |
Removes numbers or bullets from the document. |
| remove |
Removes the active theme from the current document. |
| repaginate() | Repaginates the entire document. |
| reply |
Sends an email message to the author of the document that has been sent out for review, notifying them that a reviewer has completed review of the document. |
| reset |
Clears all form fields in the document, preparing the form to be filled in again. |
| return |
Returns the document to the last saved reading position. |
| run |
Runs an auto macro that's stored in the document. If the specified auto macro doesn't exist, nothing happens. |
| run |
Runs an auto macro that's stored in the document. If the specified auto macro doesn't exist, nothing happens. |
| save(save |
Saves the document. |
| save(save |
Saves the document. |
| save |
Saves the group of quick styles currently in use. |
| search(search |
Performs a search with the specified search options on the scope of the whole document. The search results are a collection of |
| select() | Selects the contents of the document. |
| select |
Returns all content controls with the specified tag. |
| select |
Returns a |
| select |
Returns a |
| select |
Returns an |
| select |
Returns an |
| select |
Returns a |
| send |
Sends the document as a fax, without any user interaction. |
| send |
Sends the document to a fax service provider, who faxes the document to one or more specified recipients. |
| send |
Sends the document in an email message for review by the specified recipients. |
| send |
Opens a message window for sending the document through Microsoft Exchange. |
| 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. |
| set |
Specifies the table style to use for newly created tables in the document. |
| set |
Sets the options Microsoft Word uses for encrypting documents with passwords. |
| toggle |
Switches form design mode on or off. |
| 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 |
| transform |
Applies the specified Extensible Stylesheet Language Transformation (XSLT) file to this document and replaces the document with the results. |
| undo(times) | Undoes the last action or a sequence of actions, which are displayed in the Undo list. |
| undo |
Clears the list of actions that can be undone in the document. |
| unprotect(password) | Removes protection from the document. |
| 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 |
| update |
Copies all styles from the attached template into the document, overwriting any existing styles in the document that have the same name. |
| view |
Displays the code window for the selected Microsoft ActiveX control in the document. |
| view |
Displays the property window for the selected Microsoft ActiveX control in the document. |
| web |
Displays a preview of the current document as it would look if saved as a webpage. |
Events
| on |
Occurs when the user clicks an annotation (or selects it using Alt+Down). |
| on |
Occurs when the user hovers the cursor over an annotation. |
| on |
Occurs when the user adds one or more annotations. |
| on |
Occurs when the user performs an action in an annotation pop-up menu. |
| on |
Occurs when the user deletes one or more annotations. |
| on |
Occurs when a content control is added. Run context.sync() in the handler to get the new content control's properties. |
| on |
Occurs when the user adds new paragraphs. |