Word.Document
Word.Document is an object type of the Word module (Office.word(iframe)). 37 methods.
Word · 14 object types · 259 methods · namespace Word. This reference is generated from the API document artifact (sdk-api-doc.html) produced with the SDK build. Descriptions are the editor's API comments as published. Pin the SDK and Office versions together and regenerate when either changes.
Remarks
- Module: Word ·
Office.word(iframe)· namespaceWord - Obtained from:
app.getDocument()(root handle) on the app handle returned byOffice.word(iframe). Document methods live on this handle, not on the app handle. - Every method returns a
Promise; signatures use TypeScript notation.
Methods
| Method | Description |
|---|---|
acceptChangeTrackings() | Accepts all change tracking entries in the whole document at once. |
download() | Downloads the document in its original format. |
getBody() | Returns the content area of the document body. |
getBookmark(name) | Returns the bookmark with the given name. |
getBookmarks(includeHidden) | Returns the list of bookmarks in the document. |
getChangeTracking(id) | Returns the change tracking entry with the given ID. |
getChangeTrackings() | Returns the list of change tracking entries in the whole document, in document order. |
getChart(shapeId) | Returns the chart with the given ID. |
getCharts(options) | Returns the list of charts in the document. |
getComment(commentId) | Returns the comment with the given ID. |
getComments() | Returns the list of comments in the document. |
getEndnotes() | Returns the list of endnotes in the document, in document order. |
getFootnotes() | Returns the list of footnotes in the document, in document order. |
getHyperlink(hyperlinkId) | Returns the hyperlink with the given ID. |
getHyperlinks(options) | Returns the list of hyperlinks in the document (or in a specific area). |
getNote(noteId) | Returns the footnote or endnote with the given ID. |
getNotes() | Returns the list of footnotes and endnotes in the document, in document order. |
getParagraph(paragraphId) | Returns the paragraph with the given ID. |
getRange(options) | Returns the range at the given coordinates (RangeData), or the whole body when called with no argument. |
getSection(index) | Returns the section at the given index. |
getSections() | Returns the list of sections in the document, in document order. |
getSelection() | Returns the current selection. |
getShape(shapeId) | Returns the shape with the given ID. |
getShapes(options) | Returns the list of shapes in the document. |
getStyle(style) | Returns the style with the given key. |
getStyles() | Returns the list of styles defined in the document. |
getTable(tableId) | Returns the table with the given ID. |
isChangeTrackingEnabled() | Returns whether change tracking (track changes) is on. |
print() | Prints the current document. |
rejectChangeTrackings() | Rejects all change tracking entries in the whole document at once. |
save() | Saves the document. |
setBackgroundColor(color) | Sets or removes the document (page) background color. |
setChangeTracking(enabled) | Turns change tracking (track changes) on or off. |
setEvenAndOddHeaders(enabled) | Sets the whole document to use different headers and footers on odd and even pages. |
setFormattingMarks(visible) | Shows or hides all formatting marks (paragraph marks, spaces, tabs, etc.). |
setPageNumber(area, options) | Sets or removes the page number in the header or footer. |
setZoom(mode) | Changes the view zoom. |
Method details
acceptChangeTrackings()
Accepts all change tracking entries in the whole document at once.
acceptChangeTrackings(): Promise<{ processedCount: number; remainingCount: number; failedIds: string[] }>;
Returns
Promise<{ processedCount: number; remainingCount: number; failedIds: string[] }> - processing result
download()
Downloads the document in its original format.
download(): Promise<void>;
Returns
Promise<void>
getBody()
Returns the content area of the document body. - Use it to get body text and structure and to insert paragraphs and tables.
getBody(): Promise<Body>;
Returns
Promise<Body> - document body
getBookmark(name)
Returns the bookmark with the given name. - Entry point for per-bookmark operations such as delete, go to, exists, and info.
getBookmark(name: string): Promise<Bookmark>;
Parameters
| Name | Type | Description |
|---|---|---|
name | string | bookmark name |
Returns
Promise<Bookmark> - bookmark object
getBookmarks(includeHidden)
Returns the list of bookmarks in the document.
getBookmarks(includeHidden?: boolean): Promise<Bookmark[]>;
Parameters
| Name | Type | Description |
|---|---|---|
includeHidden (optional) | boolean | if true, also includes hidden bookmarks ("_" prefix) (default: false) |
Returns
Promise<Bookmark[]> - bookmark list (empty array if none)
getChangeTracking(id)
Returns the change tracking entry with the given ID.
getChangeTracking(id: string): Promise<WordChangeTracking>;
Parameters
| Name | Type | Description |
|---|---|---|
id | string | change tracking entry ID |
Returns
Promise<WordChangeTracking> - change tracking object
getChangeTrackings()
Returns the list of change tracking entries in the whole document, in document order.
getChangeTrackings(): Promise<WordChangeTracking[]>;
Returns
Promise<WordChangeTracking[]> - change tracking list
getChart(shapeId)
Returns the chart with the given ID.
getChart(shapeId: string): Promise<WordChart>;
Parameters
| Name | Type | Description |
|---|---|---|
shapeId | string | chart shape ID (obtained from getCharts / getShapes) |
Returns
Promise<WordChart> - chart object
getCharts(options)
Returns the list of charts in the document.
getCharts(options?: { storyId?: string; anchorParagraphId?: string }): Promise<WordChart[]>;
Parameters
| Name | Type | Description |
|---|---|---|
options (optional) | { storyId?: string; anchorParagraphId?: string } | list filter |
options.storyId (optional) | string | target area ID (body if omitted) (default: "0") |
options.anchorParagraphId (optional) | string | anchor paragraph filter (default: all) |
Returns
Promise<WordChart[]> - chart list (empty array if none)
getComment(commentId)
Returns the comment with the given ID.
getComment(commentId: string): Promise<WordComment>;
Parameters
| Name | Type | Description |
|---|---|---|
commentId | string | comment ID |
Returns
Promise<WordComment> - comment object
getComments()
Returns the list of comments in the document.
getComments(): Promise<WordComment[]>;
Returns
Promise<WordComment[]> - comment list
getEndnotes()
Returns the list of endnotes in the document, in document order.
getEndnotes(): Promise<WordNote[]>;
Returns
Promise<WordNote[]> - endnote list
getFootnotes()
Returns the list of footnotes in the document, in document order.
getFootnotes(): Promise<WordNote[]>;
Returns
Promise<WordNote[]> - footnote list
getHyperlink(hyperlinkId)
Returns the hyperlink with the given ID.
getHyperlink(hyperlinkId: string): Promise<Hyperlink>;
Parameters
| Name | Type | Description |
|---|---|---|
hyperlinkId | string | hyperlink ID (obtained from range.insertHyperlink / getHyperlinks) |
Returns
Promise<Hyperlink> - hyperlink object
getHyperlinks(options)
Returns the list of hyperlinks in the document (or in a specific area).
getHyperlinks(options?: { storyId?: string; anchorParagraphId?: string }): Promise<Hyperlink[]>;
Parameters
| Name | Type | Description |
|---|---|---|
options (optional) | { storyId?: string; anchorParagraphId?: string } | list filter |
options.storyId (optional) | string | target area ID (body if omitted) (default: "0") |
options.anchorParagraphId (optional) | string | only links that start in the given paragraph (default: whole area) |
Returns
Promise<Hyperlink[]> - hyperlink list (empty array if none)
getNote(noteId)
Returns the footnote or endnote with the given ID.
getNote(noteId: string): Promise<WordNote>;
Parameters
| Name | Type | Description |
|---|---|---|
noteId | string | footnote/endnote area ID |
Returns
Promise<WordNote> - note object
getNotes()
Returns the list of footnotes and endnotes in the document, in document order.
getNotes(): Promise<WordNote[]>;
Returns
Promise<WordNote[]> - footnote/endnote list
getParagraph(paragraphId)
Returns the paragraph with the given ID. - The area the paragraph belongs to (body/header/footer) is found and bound automatically, so header/footer paragraphs can be formatted and edited the same way as body paragraphs.
getParagraph(paragraphId: string): Promise<Paragraph>;
Parameters
| Name | Type | Description |
|---|---|---|
paragraphId | string | paragraph ID |
Returns
Promise<Paragraph> - paragraph object (area bound automatically)
getRange(options)
Returns the range at the given coordinates (RangeData), or the whole body when called with no argument.
The area the paragraph belongs to (body/header/footer) is found and bound automatically, so passing the paragraphId of a header/footer paragraph works the same as for the body.
Calling it with no argument is a shortcut for getBody().getRange(RangePosition.WHOLE). A range lives in one area, so this covers the body only, not headers, footers, or notes.
Passing coordinates requires startParaId. An options object without it is rejected right away, so a mistyped key cannot turn into the whole body by accident.
Use getBody().getRange(RangePosition.START/END) for the start/end of an area and getSelection() for the selection.
getRange(options?: RangeData): Promise<Range>;
Parameters
| Name | Type | Description |
|---|---|---|
options (optional) | RangeData | coordinate range information. Omit it for the whole body (default: whole body) |
Returns
Promise<Range> - range object
getSection(index)
Returns the section at the given index. - Use it to get the section's body, header, and footer and for page setup.
getSection(index?: number): Promise<Section>;
Parameters
| Name | Type | Description |
|---|---|---|
index (optional) | number | section index (0-based, in document order; 0 = first section) (default: 0) |
Returns
Promise<Section> - section object (the index is validated when header/footer/page setup is called)
getSections()
Returns the list of sections in the document, in document order.
getSections(): Promise<Section[]>;
Returns
Promise<Section[]> - section list (empty array if none)
getSelection()
Returns the current selection. - If nothing is selected, returns an empty (collapsed) range at the cursor position.
getSelection(): Promise<Range>;
Returns
Promise<Range> - selection range
getShape(shapeId)
Returns the shape with the given ID.
Returns an object matching the kind of shape: image, chart, or general shape.
getShape(shapeId: string): Promise<Shape>;
Parameters
| Name | Type | Description |
|---|---|---|
shapeId | string | shape ID (obtained from getShapes / insertShape) |
Returns
Promise<Shape> - shape object (picture → WordImage, chart → WordChart)
getShapes(options)
Returns the list of shapes in the document. - Includes both inline shapes (placed like text) and floating shapes (placed in front of or behind text).
getShapes(options?: { storyId?: string; type?: ShapeType; anchorParagraphId?: string }): Promise<Shape[]>;
Parameters
| Name | Type | Description |
|---|---|---|
options (optional) | { storyId?: string; type?: ShapeType; anchorParagraphId?: string } | list filter |
options.storyId (optional) | string | target area ID (body if omitted) (default: "0") |
options.type (optional) | ShapeType | shape type filter (default: all types) |
options.anchorParagraphId (optional) | string | anchor paragraph filter (default: all) |
Returns
Promise<Shape[]> - shape list (pictures as WordImage, charts as WordChart; empty array if none)
getStyle(style)
Returns the style with the given key. - Use it to get or modify style information and the defined formatting.
getStyle(style: Style | string): Promise<WordStyle>;
Parameters
| Name | Type | Description |
|---|---|---|
style | Style | string | Style enum for built-in styles (value = key); for custom document styles, the style value from getStyles() (e.g. "heading_1"/"strong") |
Returns
Promise<WordStyle> - style object
getStyles()
Returns the list of styles defined in the document.
getStyles(): Promise<WordStyle[]>;
Returns
Promise<WordStyle[]> - style list (empty array if none)
getTable(tableId)
Returns the table with the given ID. - The area the table belongs to (body/header/footer/text box) is found and bound automatically, so tables in those areas can be handled the same way.
getTable(tableId: string): Promise<Table>;
Parameters
| Name | Type | Description |
|---|---|---|
tableId | string | table ID |
Returns
Promise<Table> - table object (area bound automatically)
isChangeTrackingEnabled()
Returns whether change tracking (track changes) is on.
isChangeTrackingEnabled(): Promise<boolean>;
Returns
Promise<boolean> - true if on, false if off
print()
Prints the current document.
Uses browser printing on desktop Chrome and Edge; in other environments, converts to PDF and downloads it.
Does nothing if printing is disabled for the document.
print(): Promise<void>;
Returns
Promise<void>
rejectChangeTrackings()
Rejects all change tracking entries in the whole document at once.
rejectChangeTrackings(): Promise<{ processedCount: number; remainingCount: number; failedIds: string[] }>;
Returns
Promise<{ processedCount: number; remainingCount: number; failedIds: string[] }> - processing result
save()
Saves the document. - Does nothing if there are no edits or a save is already in progress.
save(): Promise<void>;
Returns
Promise<void>
setBackgroundColor(color)
Sets or removes the document (page) background color.
setBackgroundColor(color: string | null): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
color | string | null | background color ("#RRGGBB"). null or an empty string removes the background color. |
Returns
Promise<void>
setChangeTracking(enabled)
Turns change tracking (track changes) on or off. - When on, subsequent edits are tracked as insertions/deletions/format changes; when off, editing returns to normal (already recorded changes are kept).
setChangeTracking(enabled: boolean): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
enabled | boolean | true to turn on, false to turn off |
Returns
Promise<void>
setEvenAndOddHeaders(enabled)
Sets the whole document to use different headers and footers on odd and even pages.
setEvenAndOddHeaders(enabled: boolean): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
enabled | boolean | true to turn on, false to turn off |
Returns
Promise<void>
setFormattingMarks(visible)
Shows or hides all formatting marks (paragraph marks, spaces, tabs, etc.).
setFormattingMarks(visible: boolean): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
visible | boolean | true to show, false to hide |
Returns
Promise<void>
setPageNumber(area, options)
Sets or removes the page number in the header or footer.
Creates the area automatically if it does not exist, and replaces any existing page number.
If remove is true, only the page number paragraph is removed. Nothing changes if the area or the number does not exist.
setPageNumber(
area: PageNumberArea,
options?: { align?: PageNumberAlign; variant?: HeaderFooterVariant; sectionIndex?: number; remove?: boolean }
): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
area | PageNumberArea | target area (header/footer) |
options (optional) | { align?: PageNumberAlign; variant?: HeaderFooterVariant; sectionIndex?: number; remove?: boolean } | page number settings |
options.align (optional) | PageNumberAlign | alignment (left/center/right). Ignored when remove:true (default: PageNumberAlign.LEFT) |
options.variant (optional) | HeaderFooterVariant | header/footer variant (default/first/even) (default: HeaderFooterVariant.DEFAULT) |
options.sectionIndex (optional) | number | 0-based section index (0 = first section) (default: 0) |
options.remove (optional) | boolean | if true, removes the page number (align ignored) (default: false) |
Returns
Promise<void>
setZoom(mode)
Changes the view zoom.
setZoom(mode: ZoomMode): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
mode | ZoomMode | zoom preset (50~200%), fit (fitWidth/fitInWindow), or step (zoomIn/zoomOut) |
Returns
Promise<void>