Skip to main content

Word

Application

Properties

supportedEvents

Supported events

Syntax

Application.supportedEvents

Return Value

string[]

Example

function example() {
const supportedEvents = Application.supportedEvents;
}

events

Listened events

Syntax

Application.events

Return Value

string[]

Example

function example() {
const events = Application.events;
}

docType

Document type

Syntax

Application.docType

Return Value

string

Example

function example() {
const evedocTypents = Application.docType;
}

Methods

addListener

Listen to events

setUIState

JSSDK: 1.9.3、zOffice V8.0 FP3 Supported

Set the default document state when calling APIs, effective for all APIs

Syntax

Application.setUIState(cursorContext)

Parameters

PropertyData TypeRequiredDescription
cursorContextobjectYesDocument cursor state

cursorContext Structure | Property | Data Type | Required | Description | | focus | boolean | No | Whether to focus on document, default true | | scroll | boolean | No | Whether to scroll to target position, default true |

Return Value

Promise<boolean>

Example

async function example1() {
const success = await Application.setUIState({ cursorContext: { focus: false, scroll: true }});

const bookmark = await Application.Bookmarks.item('bm1');
await bookmark.focus(); // Do not focus on document, only scroll view to bookmark position and select bookmark area
}

async function example2() {
const success = await Application.setUIState({ cursorContext: { focus: false, scroll: false }});

const bookmark = await Application.Bookmarks.item('bm1');
await bookmark.setText('zOffice'); // Do not focus on document, do not scroll to bookmark position, only set bookmark area content
}

Syntax

removeListener

Remove event listener

ready

JSSDK: 1.2.3、zOffice2022.2 FP3 Supported

Wait for document to load before calling advanced APIs, only need to call once

Syntax

Application.ready()

Return Value

Promise<boolean>

Example

async function example() {
await Application.ready();
}

updateParams4thirdparty

Update some related values on the server in third-party integration scenarios

Syntax

Application.updateParams4thirdparty(params)

Parameters

PropertyData TypeRequiredDescription
paramsstringYesMultiple values separated by semicolons

Return Value

Promise<boolean>

Example

async function example() {
const params = "3rd-party-token=xxx;id=demo-docx-123;x-webhook-header=xxx;";
const success = await Application.updateParams4thirdparty(params);
if(success){
console.log('Setup successful')
}
}

Bookmark

Bookmark object

Properties

name

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Name of the bookmark object

Syntax

bookmark.name

bookmark: Bookmark object

Return Value

name: Promise<string>

Example

async function example() {
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const name = await bookmark.name;
}

range

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Get the range where the bookmark is located

Syntax

bookmark.range

bookmark: Bookmark object

Return Value

Promise<Word.Range>

Example

async function example() {
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
}

Methods

delete

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Delete bookmark

Syntax

bookmark.delete()

bookmark: Bookmark object

Return Value

Promise<boolean> Whether deletion was successful

Example

async function example(app, name) {
let success = false;
const bookmark = await Application.ActiveDocument.Bookmarks.item(name);
if (bookMark) success = await bookmark.delete();
}

focus

JSSDK: 1.0.3、zOffice2022.1 FP3 Supported

Locate bookmark

Syntax

bookmark.focus()

bookmark: Bookmark object

Return Value

Promise<boolean> Whether location was successful

Example

async function example(app, name) {
let success = false;
const bookmark = await Application.ActiveDocument.Bookmarks.item(name);
if (bookMark) success = await bookmark.focus();
}

getHtml

JSSDK: 1.2.0、zOffice2022.3 Supported

Get HTML structure at bookmark location

Syntax

bookmark.getHtml()

bookmark: Bookmark object

Return Value

Promise<string> HTML string at bookmark location

Example

async function example() {
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const htmlString = await bookmark.getHtml();
}

getText

JSSDK: 1.2.0、zOffice2022.3 Supported

Get text structure at bookmark location

Syntax

bookmark.getText()

bookmark: Bookmark object

Return Value

Promise<string>

Example

async function example() {
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const res = await bookmark.getText();
}

getContent

JSSDK: 1.7.22、zOffice V7.2 FP3 Supported

Get JSON data of bookmark area

Syntax

bookmark.getContent()

bookmark: Bookmark object

Return Value

Promise<any>JSON object of bookmark and JSON version

PropertyData TypeDescription
versionstringJSON data version
dataany[]JSON data of bookmark area content

Example

async function example() {
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const res = await bookmark.getContent();
}

setHtml

JSSDK: 1.2.0、zOffice2022.3 Supported

Set HTML structure at bookmark location

Syntax

bookmark.setHtml()

bookmark: Bookmark object

Parameters

PropertyData TypeRequiredDescription
htmlStringstringYesHTML structure

Return Value

Promise<boolean> Whether setup was successful

Example

async function example() {
const htmlString = JSON.parse('"<span >new Html</span>"');
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const success = await bookmark.setHtml(htmlString);
}

setText

Set text at bookmark location

Syntax

bookmark.setText()

bookmark: Bookmark object

Return Value

Promise<boolean> Whether text was set successfully

Parameters

PropertyData TypeRequiredDescription
contentstringYesText at bookmark location

Example

async function example(content) {
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const success = await bookmark.setText(content);
}

setContent

JSSDK: 1.7.22、zOffice V7.2 FP3 Supported

Set bookmark area content based on incoming JSON data (JSON data only supports being obtained from bookmark.getContent())

Syntax

bookmark.setContent(content)

bookmark: Bookmark object

Return Value

Promise<boolean> Whether data was set successfully (true: setup successful, false: setup failed)

Parameters

PropertyData TypeRequiredDescription
contentany[]JSON data of bookmark area content

Example

async function example() {
// Get JSON data of the first bookmark
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const content = await bookmark.getContent();
// Set bookmark 1's JSON data for the second bookmark
const bookmark = await Application.ActiveDocument.Bookmarks.item(2);
const success = await bookmark.setContent(content.data);
}

setTextCandidates

Add preset values for specified bookmark (after adding preset values to bookmark, when cursor enters the bookmark area, a small button will be displayed at the end of the bookmark, click the small button, preset values will be displayed in the dropdown list, click a preset value, this preset will replace the bookmark content)

Syntax

Bookmark.setTextCandidates(candidates)

Bookmark: Bookmark object

Parameters

PropertyData TypeRequiredDescription
candidatesstring[]YesPreset value array corresponding to this bookmark

Return Value

Promise<boolean>

Example

async function example() {
const bookmark = await Application.ActiveDocument.Bookmarks.item('test');
const success = await bookmark.setTextCandidates([
'CompanyA',
'CompanyB'
]);
}

Bookmarks

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Collection of Bookmark objects that represent bookmarks in the specified selection, range, or document.

Properties

count

Number of bookmarks

Syntax

Application.ActiveDocument.Bookmarks.count

Application: Document type application object

Return Value

count: Promise<number>

Example

async function example() {
const count = await Application.ActiveDocument.Bookmarks.count;
}

Methods

add

Add bookmark in current selected area

Syntax

document.Bookmarks.add(name, range)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
namestringYesBookmark name [If the bookmark name length exceeds 40, truncate to 40 characters as the bookmark name]
rangeWord.RangeNoArea to insert bookmark (default: insert at current selection position)

Return Value

Promise<Word.Bookmark>

Example

// Insert bookmark named 'bm' at current selection position
async function example1() {
const res = await Application.ActiveDocument.Bookmarks.add('bm');
}

// Insert bookmark named 'bm' in first paragraph area
async function example1() {
const para = await Application.ActiveDocument.Paragraphs.item(1);
const range = await para.range;
const res = await Application.ActiveDocument.Bookmarks.add('bm', range);
}

item

Get a single bookmark based on parameters

Syntax

Application.ActiveDocument.Bookmarks.item(key)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
keystring | numberYesBookmark name/bookmark index (index starts from 1)

Return Value

Promise<Word.Bookmark>

Example

async function example(key) {
const bookmark = await Application.ActiveDocument.Bookmarks.item(key);
}

setTextCandidates

Batch add preset values for bookmarks (after adding preset values to bookmark, when cursor enters the bookmark area, a small button will be displayed at the end of the bookmark, click the small button, preset values will be displayed in the dropdown list, click a preset value, this preset will replace the bookmark content)

Syntax

Application.ActiveDocument.Bookmarks.setTextCandidates(candidates)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
candidatesWord.CandidatesYesWord.Candidates is defined as { [key: string]: string[]; }, where key is bookmark name, string[] is Preset value array corresponding to this bookmark

Return Value

Promise<boolean>

Example

async function example() {
const success = await Application.ActiveDocument.Bookmarks.setTextCandidates({
'PartyA': [
'CompanyA',
'CompanyB'
],
'PartyB': [
'CompanyC',
'CompanyD'
]
});
}

identify

JSSDK: 1.7.01、zOffice V7.2 hotfix1 Supported

Identify areas in document that can be set as bookmarks, intelligently generate bookmarks

Syntax

Application.ActiveDocument.Bookmarks.identify(identifyRules, nameRule, includeHeaderFooter)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
identifyRulesWord.MarksIdentifyRuleYesIntelligent bookmark identification rules
nameRuleWord.MarksGenerateNameRuleYesIntelligent bookmark naming rules
includeHeaderFooterbooleanNoWhether to include header and footer areas

Return Value

Promise<boolean>

Example

// Identify underlined areas with text content as bookmarks, name bookmarks using content above underline
async function example1() {
const success = await Application.ActiveDocument.Bookmarks.identify(Word.MarksIdentifyRule.TEXT, Word.MarksGenerateNameRule.ABOVE, true);
}

// Identify underlined areas with text content as bookmarks, name bookmarks using text content before underline
async function example2() {
const success = await Application.ActiveDocument.Bookmarks.identify(Word.MarksIdentifyRule.TEXT, Word.MarksGenerateNameRule.BEFORE, true);
}
// Identify underlined areas with empty content as bookmarks, name bookmarks using text content before underline
async function example3() {
const success = await Application.ActiveDocument.Bookmarks.identify(Word.MarksIdentifyRule.EMPTY, Word.MarksGenerateNameRule.BEFORE, true);
}

toJson

Get all bookmarks contained in the document

Syntax

Application.ActiveDocument.Bookmarks.toJson()

Application: Document type application object

Return Value

Promise<string[]>,Array of bookmark names

Example

async function example() {
const bookmarks = await Application.ActiveDocument.Bookmarks.toJson();
}

Cell

JSSDK: 1.2.0、zOffice2022.3 Supported

Table cell

Properties

range

JSSDK: 1.7.1、zOffice V7.2 FP1 Supported

Get cell range

Syntax

Cell.range

Cell: Cell object

Return Value

Promise<Word.Range>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const range = await cell.range;
}

Methods

getRowSpan

Get row span of cell.

Syntax

cell.getRowSpan()

cell: Cell object

Return Value

Promise<number>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const cellRowSpan = await cell.getRowSpan();
}

getColSpan

Get column span of cell.

Syntax

cell.getColSpan()

cell: Cell object

Return Value

Promise<number>

Return Value

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const cellColSpan = await cell.getColSpan();
}

getIndex

Get row and column position of cell.

Syntax

cell.getIndex()

cell: Cell object

Return Value

Promise<[rowIndex, columnIndex]>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const cellIndex = await cell.getIndex();
}

getHtml

Get HTML structure of cell.

Syntax

cell.getHtml()

cell: Cell object

Return Value

Promise<string>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const getHtml = await cell.getHtml();
}

setHtml

Set HTML structure of cell.

Syntax

cell.setHtml(htmlString)

cell: Cell object

Parameters

PropertyData TypeRequiredDescription
htmlStringstringYesCell HTML structure

Return Value

Promise<boolean>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const success = await cell.setHtml("<table><tbody><colgroup><col style='width:137.25pt'/></colgroup><tr><td><p>New content</p></td></tr></tbody></table>");
}

getText

Get text content of cell.

Syntax

cell.getText()

cell: Cell object

Return Value

Promise<string>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const getText = await cell.getText();
}

setText

Set text content of cell.

Syntax

cell.setText(content)

cell: Cell object

Parameters

PropertyData TypeRequiredDescription
contentstringYesText content

Return Value

Promise<boolean>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const success = await cell.setText('New content');
}

Cells

JSSDK: 1.3.0、zOffice V6 Supported

Collection of cells.

Properties

count

Number of cells.

Syntax

Cells.count

Return Value

Promise<number>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const count = await row.Cells.count;
}

Methods

item

Get cell by parameter.

Syntax

Cells.item(index)

Parameters

PropertyData TypeRequiredDescription
indexnumberYesCell number (starting from 1)

Return Value

Promise<Word.Cell>

Example

async function example(index, cnt, isBefore) {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
}

Column

JSSDK: 1.2.0、zOffice2022.3 Supported

Table column.

Properties

index

JSSDK: 1.3.0、zOffice V6 Supported

Column number.

Syntax

column.index

column: Table column object

Return Value

Promise< number>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const column = await table.Columns.item(1);
const index = await column.index;
}

Methods

delete

JSSDK: 1.3.0、zOffice V6 Supported

Delete column.

Syntax

column.delete()

column: Column object

Return Value

Promise<boolean> Whether deletion was successful

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const column = await table.Columns.item(1);
const result = await column.delete();
}

Columns

JSSDK: 1.3.0、zOffice V6 Supported

Collection of specified table columns.

Properties

count

Number of specified table columns.

Syntax

Columns.count

Return Value

Promise<number>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const count = await table.Columns.count;
}

Methods

add

Insert column.

Syntax

Columns.add(index, cnt, isBefore)

Parameters

PropertyData TypeRequiredDescription
indexnumberYesColumn number (starting from 1)
cntnumberYesNumber to insert (starting from 1, maximum 50)
isBeforebooleanYesBoolean value (true: insert column on left; false: insert column on right)

Return Value

Promise<boolean> Whether insertion was successful

Example

async function example(index, cnt, isBefore) {
const table = await Application.ActiveDocument.Tables.item(1);
const columns = await table.Columns;
const success = await columns.add(index, cnt, isBefore);
}

deleteColumns

Delete specified column.

Syntax

Columns.deleteColumns(index, cnt, isBefore)

Parameters

PropertyData TypeRequiredDescription
indexnumberYesColumn number (starting from 1)
cntnumberNoNumber to delete (default 1)
isBeforebooleanNoBoolean value (true: delete columns to left; false: delete columns to right, default false)

Return Value

Promise<boolean>

Example

async function example(index, cnt, isBefore) {
const table = await Application.ActiveDocument.Tables.item(1);
const success = await table.Columns.deleteColumns(index, cnt, isBefore);
}

item

Get table column by parameter.

Syntax

Columns.item(index)

Parameters

PropertyData TypeRequiredDescription
indexnumberYesColumn number (starting from 1)

Return Value

Promise<Word.Column>

Example

async function example(index, cnt, isBefore) {
const table = await Application.ActiveDocument.Tables.item(1);
const column = await table.Columns.item(1);
}

Comment

JSSDK: 1.7.1、zOffice v7.2 FP1 Supported

Comment

Properties

range

Range where comment is located in document body

Syntax

Comment.range

Return Value

Promise< Word.Range>

Example

// Get range of first comment in document body
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const range = await comment.range;
}

creator

Comment creator

Syntax

Comment.creator

Return Value

Promise\< {name:string, uid:string}>

Example

// Get creator of first comment in document body
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const creator = await comment.creator;
}

content

Comment content

Syntax

Comment.content

Return Value

Promise< string>

Example

// Get content of first comment in document body
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const content = await comment.content;
}

time

Comment create/modify time

Syntax

Comment.time

Return Value

Promise< number>

Example

// Get create/modify time of first comment in document body
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const time = await comment.time;
}

done

Comment resolution status, read/write

Syntax

Comment.done

Return Value

Promise< boolean>

Example

// Resolve first comment in document body
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
comment.done = true;
}

// Reopen first comment in document body
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
comment.done = false;
}

// Get status of first comment in document body
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const isDone = await comment.done;
}

parent

Return parent comment of reply

Syntax

Comment.parent

Return Value

Promise< Word.Comment>

Example

// Get parent comment of reply
async function example() {
const comment = await Application.ActiveDocument.Comments.item(3);
const parent = await comment.parent;
if (parent) {
const content = await parent.content;
}
}

Replies

Return a Comment collection, these comment objects are children of the specified Comment. This is a read-only Property.

Syntax

Comment.Replies

Return Value

Promise<Word.Comments>

Example

// Get reply count of first comment in document body
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const replies = await comment.Replies;
const count = await replies.count;
}

Methods

delete

Delete comment.

Syntax

comment.delete()

Return Value

Promise<boolean> Whether deletion was successful

Example

async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const success = await comment.delete();
}

toJson

Return comment structured data

Syntax

comment.toJson()

Return Value

Promise<any>

{
content: string, // Comment content
creator: {
uid: string, // Comment creator ID
name: string // Comment creator name
},
id: string, // Comment ID
pid: string, // Parent comment ID (returned if this is a reply)
time: number, // Comment creation timestamp
done: boolean // Whether comment is resolved
}

Example

async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const data = await comment.toJson();
}

focus

Locate comment

Syntax

comment.focus()

Return Value

None

Example

// Locate first comment in document
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
await comment.focus();
}

setHidden

Set comment box hidden

Syntax

comment.setHidden(hide)

Parameters

PropertyData TypeRequiredDescription
hidebooleanYesWhether to hide

Return Value

None

Example

// Hide first comment in document
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
await comment.setHidden(true);
}

// Unhide first comment in document
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
await comment.setHidden(false);
}

// Hide first reply of first comment in document
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const replies = await comment.Replies;
const reply = await replies.item(1);
await reply.setHidden(true);
}

setHighlightColor

Set comment marker color

Syntax

comment.setHighlightColor(color)

Parameters

PropertyData TypeRequiredDescription
colorstringYesHexadecimal color code

Return Value

None

Example

// Set comment marker color of first comment in document to red
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
await comment.setHighlightColor('#ff0000');
}

Comments

JSSDK: 1.7.1、zOffice v7.2 FP1 Supported

A Comment object collection that represents comments in the specified selection, range, or document.

Properties

count

Number of comments

Syntax

Comments.count

Return Value

Promise<number>

Example

// Get total comment count in document
async function example() {
const count = await Application.ActiveDocument.Comments.count;
}

Methods

add

Add comment

Syntax

Comments.add(text, range)

Parameters

PropertyData TypeRequiredDescription
textstringYesComment content
rangeWord.RangeNoRange to add comment (default: add at current selection)

Return Value

Promise<Word.Comment>

Example

// Add comment to current selection
async function example() {
const comments = Application.ActiveDocument.Comments;
const comment = await comments.add('My comment');
}

// Add comment to bookmark area
async function example() {
const comments = Application.ActiveDocument.Comments;
const bm = await Application.ActiveDocument.Bookmarks.item('bm');
const range = await bm.range;
const comment = await comments.add('My comment', range);
}

// Add reply to specified comment
async function example() {
const comments = Application.ActiveDocument.Comments;
const comment = await comments.item(1);
const replies = await comment.Replies;
const comment = await replies.add('Add comment');
}

item

Return a single Comment object from collection.

Syntax

Comments.item(index)

Parameters

PropertyData TypeRequiredDescription
indexnumberYesSerial number of Comment in collection

Return Value

Promise<Word.Comment>

Example

// Get first comment in document
async function example() {
const comments = Application.ActiveDocument.Comments;
const comment = await comments.item(1);
}

toJson

Return structured data of a single Comment object from the collection.

Syntax

Columns.toJson()

Return Value

Promise<any[]>

{
content: string, // Comment content
creator: {
uid: string, // Comment creator ID
name: string // Comment creator name
},
id: string, // Comment ID
pid: string, // Parent comment ID (returned if this is a reply)
time: number, // Comment creation timestamp
done: boolean // Whether comment is resolved
}

Example

// Get structured data of all comments in document
async function example() {
const comments = Application.ActiveDocument.Comments;
const data = await comments.toJson();
}

Document

Current word document

Properties

ActiveWindow

Return a Window object, that represents the current active window

Syntax

Application.ActiveDocument.ActiveWindow

Return Value

ActiveWindow

Example

function example() {
const ActiveWindow = Application.ActiveDocument.ActiveWindow;
}

Bookmarks

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Return a Bookmarks collection, that represents all bookmarks in the document.

Syntax

Application.ActiveDocument.Bookmarks

Return Value

Word.Bookmarks

Example

// Get count of all bookmarks in document
function example() {
const bookmarks = Application.ActiveDocument.Bookmarks;
const count = await bookmarks.count;
}

PermMarks

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Return a PermMarks collection, that represents all editable regions in the document.

Syntax

Application.ActiveDocument.PermMarks

Return Value

Word.PermMarks

Example

// Get count of all editable regions in document
function example() {
const permMarks = Application.ActiveDocument.PermMarks;
const count = await permMarks.count;
}

Comments

Return a Comments collection, that represents all comments in the document.

Syntax

Application.ActiveDocument.Comments

Return Value

Word.Comments

Example

// Get count of all comments in document
function example() {
const comments = Application.ActiveDocument.Comments;
const count = await comments.count;
}

Paragraphs

Return a Paragraphs collection, that represents all paragraphs in the document.

Syntax

Application.ActiveDocument.Paragraphs

Return Value

Word.Paragraphs

Example

// Get count of all paragraphs in document
function example() {
const paragraphs = Application.ActiveDocument.Paragraphs;
const count = await paragraphs.count;
}

Tables

Return a Tables collection, that represents all tables in the document.

Syntax

Application.ActiveDocument.Tables

Return Value

Word.Tables

Example

// Get count of all tables in document
function example() {
const tables = Application.ActiveDocument.Tables;
const count = await tables.count;
}

Revisions

Return a Revisions collection, that represents all revisions in the document.

Syntax

Application.ActiveDocument.Revisions

Return Value

Word.Revisions

Example

// Get count of all revisions in document
function example() {
const revisions = Application.ActiveDocument.Revisions;
const count = await revisions.count;
}

Shapes

Return a Shapes collection, that represents all shapes in the document.

Syntax

Application.ActiveDocument.Shapes

Return Value

Word.Shapes

Example

// Get count of all shapes in document
function example() {
const shapes = Application.ActiveDocument.Shapes;
const count = await shapes.count;
}

InlineShapes

Return a InlineShapes collection, that represents all inline shapes in the document.

Syntax

Application.ActiveDocument.InlineShapes

Return Value

Word.InlineShapes

Example

// Get count of all inline shapes in document
function example() {
const inlineShapes = Application.ActiveDocument.InlineShapes;
const count = await inlineShapes.count;
}

Sections

Return a Sections collection, that represents all sections in the document.

Syntax

Application.ActiveDocument.Sections

Return Value

Word.Sections

Example

// Get count of all inline shapes in document
function example() {
const sections = Application.ActiveDocument.Sections;
const count = await sections.count;
}

OutlineEntries

JSSDK: 1.9.1、zOffice V8.0 FP1 Supported

Return a OutlineEntries collection, that represents all outline paragraphs in the document.

Syntax

Application.ActiveDocument.OutlineEntries

Return Value

Word.OutlineEntries

Example

// Get count of all outline paragraphs in document
function example() {
const OutlineEntries = Application.ActiveDocument.OutlineEntries;
const count = await OutlineEntries.count;
}

Content

JSSDK: 1.3.3、zOffice V6.0 FP3 Supported

Return a read-only Range object that represents the main document body.

Syntax

Application.ActiveDocument.Content

Return Value

Range

Example

function example() {
const range = Application.ActiveDocument.Content;
}

ProtectionType

JSSDK: 1.7.2、zOffice V7.2 FP1 Supported

Return document protection type, can be one of Word.ProtectionType constants

Syntax

Application.ActiveDocument.ProtectionType

Return Value

Promise<number>

Example

async function example() {
const protectType = await Application.ActiveDocument.ProtectionType;
}

PermissionType

JSSDK: 1.9.1、zOffice V8.0 FP1 Supported

When document is in region edit protection state, default edit permission of document, can be one of Word.DocPermission constants, read-only

Syntax

Application.ActiveDocument.PermissionType

Return Value

Promise<Word.DocPermission>

Example

async function example() {
const docPermission = await Application.ActiveDocument.PermissionType;
}

Methods

protect

JSSDK: 1.7.2、zOffice V7.2 FP1 Supported

Enable document protection

Syntax

Application.ActiveDocument.protect(type, docPermission)

Multiple modes connected with " | "

Parameters

PropertyData TypeRequiredDescription
typenumberYesPass protection type, specific values refer to Word.ProtectionType enum values (only revision protection type can be set together with other protection types, other protection types can only be set alone)
docPermissionWord.DocPermissionNoWhen enabling region edit protection, default permission for full text, default full text is read-only

Return Value

Promise<boolean>

Example

async function example1() {
const type = Word.ProtectionType
const result = await app.ActiveDocument.protect(type.EditArea | type.Revision); // Enable region edit and revision protection simultaneously
console.log(result)
}
async function example2() {
const type = Word.ProtectionType
const result = await app.ActiveDocument.protect(type.EditArea, Word.DocPermission.Editable); // Enable region edit protection, full text editable by default
console.log(result)
}

unprotect

JSSDK: 1.7.2、zOffice V7.2 FP1 Supported

Disable document protection

Syntax

Application.ActiveDocument.unprotect()

Return Value

Promise<boolean>

Example

async function example() {
const result = await app.ActiveDocument.unprotect();
console.log(result);
}

isDataProtectionOn

JSSDK: 1.0.3、zOffice2022.1 FP3 Supported

Whether content protection is enabled

Syntax

Application.ActiveDocument.isDataProtectionOn()

Return Value

Promise<boolean>

Example

async function example() {
const isOpen = await Application.ActiveDocument.isDataProtectionOn();
console.log(isOpen);
}

save

Save document

Syntax

Application.ActiveDocument.save()

Return Value

Promise<boolean>

Example

async function example() {
await Application.ActiveDocument.save();
}

saveAs

JSSDK: 1.2.1、zOffice2022.3 FP1 Supported

Save as file

Syntax

Application.ActiveDocument.saveAs(format, name, path)

Parameters

PropertyData TypeRequiredDescription
formatstringYesFile type to save as. Currently only pdf is Supported
namestringNoFile name without extension. When name is empty, file name is current file name concatenated with time (format yyyyMMddhhmmss), will be returned when zOffice server sends preflight check request

Return Value

None

Example

// Only specify save as format
async function example() {
await Application.ActiveDocument.saveAs('pdf');
}

// Specify save as format and file name
async function example2() {
await Application.ActiveDocument.saveAs('pdf', 'newFileName');
}

print

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Print document

Syntax

Application.ActiveDocument.print()

Return Value

Promise<boolean> Whether print page was opened successfully

Example

async function example() {
await Application.ActiveDocument.print();
}

getWordCount

JSSDK: 1.9.0、zOffice V7.4 Supported

Get current document word count

Syntax

Application.ActiveDocument.getWordCount()

Return Value

Promise<WordsCountJSON>

WordsCountJSON

{
total: number; // Total document word count
}

Example

async function example() {
const words = await Application.ActiveDocument.getWordCount();
const wordsCount = words.total; // Document word count
console.log(wordsCount)
}

getSelection

Get current cursor selection range

Syntax

Application.ActiveDocument.getSelection()

Application: Document type application object

Return Value

Promise<Word.Range>

Example

async function example() {
const range = await Application.ActiveDocument.getSelection();
}

setSelection

Select specified range content

Syntax

Application.ActiveDocument.setSelection(range)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
rangeWord.RangeYesrange

Return Value

Promise<boolean>

Example

async function example() {
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
const res = await Application.ActiveDocument.setSelection(range);
}

getPageCount

Get total page count

Syntax

Application.ActiveDocument.getPageCount()

Application: Document type application object

Return Value

Promise<number>

Example

async function example() {
const pageCount = await Application.ActiveDocument.getPageCount();
}

getComments

JSSDK: 1.0.4、zOffice2022.1 FP4 Supported

Get all comment data

Syntax

Application.ActiveDocument.getComments()

Application: Document type application object

Return Value

Promise<Comment[]>

Comment data structure

{
content: string,
id: string,
replies: CommentReply[], // Comment replies, if no replies, then empty array
resolved: boolean,
time: number
users: {
name: string,
uid: string
}
}

CommentReply data structure

{
content: string,
id: string,
pid: string, // ID of replied comment
time: number,
users: {
name: string,
uid: string
}
}

Example

async function example() {
const comments = await Application.ActiveDocument.getComments();
}

getName

Get document title name

Syntax

Application.ActiveDocument.getName()

Application: Document type application object

Return Value

Promise<string>

Example

async function example() {
const documentTitle = await Application.ActiveDocument.getName();
}

getParagraphs

Get all first-level paragraphs of current document

Syntax

Application.ActiveDocument.getParagraphs(option)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
optionanyNooption.afterToc is true means only get paragraphs after table of contents

Return Value

Promise<Word.Paragraph[]>

Example

async function example() {
const paras = await Application.ActiveDocument.getParagraphs();
}

enableTrackChange

Enable track changes, subsequent modifications will generate revision records

Syntax

Application.ActiveDocument.enableTrackChange()

Application: Document type application object

Return Value

None

Example

async function example() {
await Application.ActiveDocument.enableTrackChange();
}

disableTrackChange

Disable track changes, after disabling subsequent modifications will no longer generate revision records

Syntax

Application.ActiveDocument.disableTrackChange()

Application: Document type application object

Return Value

None

Example

async function example() {
await Application.ActiveDocument.disableTrackChange();
}

acceptAllRevisions

Accept all changes

Syntax

Application.ActiveDocument.acceptAllRevisions()

Application: Document type application object

Return Value

None

Example

async function example() {
await Application.ActiveDocument.acceptAllRevisions();
}

rejectAllRevisions

Reject all changes

Syntax

Application.ActiveDocument.rejectAllRevisions()

Application: Document type application object

Return Value

None

Example

async function example() {
await Application.ActiveDocument.rejectAllRevisions();
}

CleanDocument

Clean document: Clear all comments in document and accept all revision records

Syntax

Application.ActiveDocument.CleanDocument()

Application: Document type application object

Return Value

None

Example

async function example() {
await Application.ActiveDocument.CleanDocument();
}

CleanComments

Delete all comments

Syntax

Application.ActiveDocument.CleanComments()

Application: Document type application object

Return Value

None

Example

async function example() {
await Application.ActiveDocument.CleanComments();
}

Find

JSSDK: 1.3.3、zOffice V6.0 FP3 Supported

Represent execution conditions for find operation.

Methods

findData

Find all matches and return number of matches.

Syntax

Find.findData(findText, matchCase, matchWholeWord)

Find: Execution condition object for find operation.

Parameters

PropertyData TypeRequiredDescription
findTextstringYesText to find
matchCasebooleanNoWhether to match case
matchWholeWordbooleanNoWhether to match whole word

Return Value

Promise<number>

Example

// Find content "text" in full document, whole word match
async function example1() {
const count = await Application.ActiveDocument.Content.Find.findData("text", false, true);
}

// Find content "text" in current selection, whole word match
async function example2() {
const range = await Application.ActiveDocument.getSelection();
const count = await range.Find.findData("text", false, true);
}

clearHitHighlight

Clear highlight and return a boolean value indicating whether the operation was successful.

Syntax

Find.clearHitHighlight()

Find: Execution condition object for find operation.

Return Value

Promise<boolean>

Example

async function example1() {
const success = await app.ActiveDocument.Content.Find.clearHighlight();
}

execute

JSSDK: 1.5.2、zOffice V7.0 FP2Supported

  • Search and highlight text

Syntax

Find.execute(findText, showHighlight)

Find: Execution condition object for find operation.

Parameters

PropertyData TypeRequiredDescription
findTextstringNoText to search
showHighlightbooleanNoWhether to highlight search results, default true

Return Value

Promise<boolean>

Example

// Search and highlight text
async function example1() {
const success = await app.ActiveDocument.Content.Find.execute('zOffice', true);
console.log('success:', success);
}

Font

JSSDK: 1.7.3、zOffice V7.2 FP3Supported

Return or set font properties in range, such as font size, font color, whether bold, whether underline, whether italic.

Properties

Italic

Return or set italic format in range. Read/write boolean value.

Syntax

Font.Italic

Font: Font object

Example

async function example() {
// Get/set italic style of bookmark range
const bookmark = await app.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
const isItalic = await range.Font.Italic;
console.log(isItalic);
range.Font.Italic = true;
}

Bold

Return or set bold format in range. Read/write boolean value.

Syntax

Font.Bold

Font: Font object

Example

async function example() {
// Get/set bold style of bookmark range font
const bookmark = await app.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
const isBold = await range.Font.Bold;
console.log(isBold);
range.Font.Bold = true;
}

Underline

Return or set type of underline applied to range. Read/write WdUnderline.

Syntax

Font.Underline

Font: Font object

Example

async function example() {
// Get/set underline style of bookmark range font
const bookmark = await app.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
const underline = await range.Font.Underline;
console.log(underline);
range.Font.Underline = Word.WdUnderline.wdUnderlineSingle;
}

Color

Return or set color applied to range. Read/write. 6-digit hexadecimal color value, e.g.: #000000

Syntax

Font.Color

Font: Font object

Example

async function example() {
// Get/return font color of bookmark range based on 6-digit hexadecimal color value
const bookmark = await app.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
const Color = await range.Font.Color;
console.log(Color);
range.Font.Color = "#ffffff";
}

ColorIndex

Return or set a WdColorIndex constant that represents color of specified font. Read/write.

Syntax

Font.ColorIndex

Font: Font object

Example

async function example() {
// Get/return font color of bookmark range based on color enum value
const bookmark = await app.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
const ColorIndex = await range.Font.ColorIndex;
console.log(ColorIndex);
range.Font.ColorIndex = Word.wdColorIndex.wdOrigin;
}

Size

Set or return font size of text, read/write number.

Syntax

Font.Size

Font: Font object

Parameters

PropertyData TypeRequiredDescription
SizenumberYesSize >= 1 && Size <= 1638 && Size supports up to one decimal place (unit: point, pt)

Example

async function example() {
// Get/set font size of bookmark range
const bookmark = await app.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
const Size = await range.Font.Size;
console.log(Size);
range.Font.Size = 20;
}

Footers

JSSDK: 1.4.1、zOffice V7.0 FP1Supported

Represent all footers in document.

Properties

item

Return a single Footer object from collection.

Syntax

Footers.item(key)

Parameters

PropertyData TypeRequiredDescription
keyWord.WdHeaderFooterIndexYesConstant for header in specified range or section

Return Value

Promise<Word.Footer>

Example

async function example() {
const section = await Application.ActiveDocument.Sections.item(1);
const footers = section.Footers;
const footer = await headers.item(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage);
}

JSSDK: 1.4.1、zOffice V7.0 FP1Supported

Represent a single footer, Footer object is a member of Footers collection, Footers collection contains all footers in specified document.

Properties

range

Return a Range object that represents the document part contained in the specified footer.

Syntax

Footer.range

Return Value

Promise<Word.Range>

Example

async function example() {
const section = await app.ActiveDocument.Sections.item(1);
const footers = section.Footers;
const footer = await footers.item(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage);
const range = await footer.range;
}

Headers

JSSDK: 1.4.1、zOffice V7.0 FP1Supported

Represent all headers in document.

Properties

item

Return a single Header object from collection.

Syntax

Headers.item(key)

Parameters

PropertyData TypeRequiredDescription
keyWord.WdHeaderFooterIndexYesConstant for header in specified range or section

Return Value

Promise<Word.Header>

Example

async function example() {
const section = await Application.ActiveDocument.Sections.item(1);
const headers = section.Headers;
const header = await headers.item(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage);
}

JSSDK: 1.4.1、zOffice V7.0 FP1Supported

Represent a single header, Header object is a member of Headers collection, Headers collection contains all headers in specified document.

Properties

range

Return a Range object that represents the document part contained in the specified header.

Syntax

Header.range

Return Value

Promise<Word.Range>

Example

async function example() {
const section = await app.ActiveDocument.Sections.item(1);
const headers = section.Headers;
const header = await headers.item(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage);
const range = await header.range;
}

InlineShape

JSSDK: 1.3.1、zOffice V6.0 FP1 Supported

Represent objects in text layer of document. Inline shapes can only be pictures, OLE objects or ActiveX controls. InlineShape object is a member of InlineShapes collection. InlineShapes collection contains all inline shapes in document, range or selection. (Currently only embedded pictures are supported)

Methods

delete

Delete specified embedded graphic.

Syntax

inlineShape.delete()

inlineShape: Embedded picture object

Return Value

Promise<boolean>

Example

async function example() {
const inlineShape = await Application.ActiveDocument.InlineShapes.item(1);
const success = await inlineShape.delete();
}

focus

JSSDK: 1.4.0、zOffice V6.1 Supported

Locate embedded picture

Syntax

InlineShape.focus()

InlineShape: Embedded picture object

Return Value

Promise<boolean> Whether location was successful

Example

async function example() {
const inlineShape = await Application.ActiveDocument.InlineShapes.item(1);
const success = await inlineShape.focus();
}

InlineShapes

JSSDK: 1.3.1、zOffice V6.0 FP1 Supported

Collection of InlineShape objects that represent objects in the text layer of the document. Inline shapes can only be pictures, OLE objects or ActiveX controls. (Currently only embedded pictures are Supported)

Properties

count

Return a Long that represents the number of inline graphics in the collection. This is a read-only Property.

Syntax

Application.ActiveDocument.InlineShapes.count

Application: Document type application object

Return Value

Promise<number>

Example

async function example() {
const count = await Application.ActiveDocument.InlineShapes.count;
}

Methods

addPicture

Add a picture to the document. Return an InlineShape object that represents the picture. (Default: add at current cursor position)

Syntax

Application.ActiveDocument.InlineShapes.addPicture(file, range, bReplace)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
fileFileYesFile object of picture (limit 10MB)
rangeWord.RangeNoRange position (default: insert at current selection)
bReplacebooleanNoWhether to replace range content (default false, insert picture at start position of range without deleting range content, true means delete range content then insert picture)

Return Value

Promise<Word.InlineShape>

Example

<input type="file" name="Insert embedded image" id="imageInput"/>

const inputElement = document.getElementById('imageInput');


// sample1, insert picture at current selection, do not replace range content
inputElement.onchange = async function() {
const InlineShapes = await Application.ActiveDocument.InlineShapes;
const inlineShape = await InlineShapes.addPicture(inputElement.files[0]);
}

// sample2, insert picture at current selection, replace range content
inputElement.onchange = async function() {
const InlineShapes = await Application.ActiveDocument.InlineShapes;
const pm = await Application.ActiveDocument.PermMarks.item(1);
const pmRange = await pm.range;
const inlineShape = await InlineShapes.addPicture(inputElement.files[0], undefined, true);
}

// sample3, insert picture at specified selection, do not replace range content
inputElement.onchange = async function() {
const InlineShapes = await Application.ActiveDocument.InlineShapes;
const pm = await Application.ActiveDocument.PermMarks.item(1);
const pmRange = await pm.range;
const inlineShape = await InlineShapes.addPicture(inputElement.files[0], range);
}

// sample4, insert picture at specified range, replace range content
inputElement.onchange = async function() {
const InlineShapes = await Application.ActiveDocument.InlineShapes;
const pm = await Application.ActiveDocument.PermMarks.item(1);
const pmRange = await pm.range;
const inlineShape = await InlineShapes.addPicture(inputElement.files[0], range, true);
}

item

Return a single object from collection, InlineShape.

Syntax

Application.ActiveDocument.InlineShapes.item(key)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
keynumberYesSerial position of InlineShape in document (starting from 1)

Return Value

Promise<Word.InlineShape>

Example

async function example() {
const InlineShapes = await Application.ActiveDocument.InlineShapes;
const inlineShape = await InlineShapes.item(1);
}

OutlineEntry

JSSDK: 1.9.1、zOffice V8.0 FP1 Supported

Represent outline entry object in document navigation bar.

Properties

contentRange

Outline paragraph range. Return a Range object that represents the content range in document corresponding to the specified outline entry.

Syntax

OutlineEntry.contentRange

Return Value

Promise<Word.Range>

Example

async function example() {
const outlineEntry = await app.ActiveDocument.OutlineEntries.item(1);
const paraRange = await outlineEntry.contentRange;
}

outlineRange

Outline range. Return a Range object that represents the range in document from paragraph corresponding to specified outline entry to next same-level or higher-level outline paragraph.

Syntax

OutlineEntry.outlineRange

Return Value

Promise<Word.Range>

Example

async function example() {
const outlineEntry = await app.ActiveDocument.OutlineEntries.item(1);
const range = await outlineEntry.outlineRange;
}

level

Return outline level, read-only Word.WdOutlineLevel

Syntax

OutlineEntry.level

Return Value

Promise<Word.WdOutlineLevel>

Example

async function example() {
const outlineEntry = await app.ActiveDocument.OutlineEntries.item(1);
const level = await outlineEntry.level;
}

Methods

focus

Locate document paragraph range corresponding to outline entry

Syntax

OutlineEntry.focus()

OutlineEntry: Outline entry object

Return Value

Promise<boolean>

Example

async function example() {
const outlineEntry = await app.ActiveDocument.OutlineEntries.item(1);
const success = await outlineEntry.focus();
}

outlineFocus

Locate outline range. That is, range in document from paragraph corresponding to outline entry to next same-level or higher-level outline paragraph.

Syntax

OutlineEntry.outlineFocus()

OutlineEntry: Outline entry object

Return Value

Promise<boolean>

Example

async function example() {
const outlineEntry = await app.ActiveDocument.OutlineEntries.item(1);
const success = await outlineEntry.outlineFocus();
}

getText

Return content displayed by outline entry

Syntax

OutlineEntry.getText()

OutlineEntry: Outline entry object

Return Value

Promise<string>

Example

async function example() {
const outlineEntry = await app.ActiveDocument.OutlineEntries.item(1);
const text = await outlineEntry.getText();
}

OutlineEntries

JSSDK: 1.9.1、zOffice V8.0 FP1 Supported

Collection of OutlineEntry objects

Properties

count

Return outline entries in document

Syntax

Application.ActiveDocument.OutlineEntries.count

Application: Document type application object

Return Value

Promise<number>

Example

async function example() {
const count = await Application.ActiveDocument.OutlineEntries.count;
}

Methods

item

Return a single object from collection, OutlineEntry.

Syntax

Application.ActiveDocument.OutlineEntries.item(key)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
keynumber|stringYesnumber: serial position of outlineEntry object among all outline entries (starting from 1)
string: id of outlineEntry object

Return Value

Promise<Word.OutlineEntry>

Example

async function example() {
const OutlineEntries = Application.ActiveDocument.OutlineEntry;
const outlineEntry1 = await OutlineEntries.item(1);
const id = outlineEntry1.id;
const outlineEntry2 = await OutlineEntries.item(id);
}

Paragraph

Paragraph object

Properties

index

JSSDK: 1.9.1、zOffice V8.0 FP1 Supported

Get serial number of paragraph in document

Syntax

paragraph.index

paragraph: Paragraph object

Return Value

Promise<number>

Example

async function example1() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(5);
const index = await paragraph.index;
}

// Get serial number of document paragraph corresponding to first outline entry
async function example2() {
const outlineEntry = await Application.ActiveDocument.OutlineEnties.item(1);
const index = await outlineEntry.paragraph.index;
}

range

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Get Range of paragraph

Syntax

paragraph.range

paragraph: Paragraph object

Return Value

Promise<Range>

Example

async function example() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const range = await paragraph.range;
}

outlineLevel

JSSDK: 1.4.0、zOffice V6.1 Supported

Return outline level of specified paragraph.

Syntax

Paragraph.outlineLevel

Paragraph: Paragraph object

Return Value

Promise<Word.WdOutlineLevel>

Example

async function example() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const outlineLevel = await paragraph.outlineLevel;
}

style

JSSDK: 1.4.0、zOffice V6.1 Supported

Return style of specified object.

Syntax

Paragraph.style

Paragraph: Paragraph object

Return Value

Word.Style

Example

async function example() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const style = paragraph.style;
}

Methods

appendText

Append text to current paragraph

Syntax

paragraph.appendText(content)

paragraph: Paragraph object

Parameters

PropertyData TypeRequiredDescription
contentstringYesPure text content to append

Return Value

Promise<boolean>

Example

async function example(content) {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const res = await paragraph.appendText(content);
}

clear

Clear paragraph content

Syntax

paragraph.clear()

paragraph: Paragraph object

Return Value

Promise<boolean>

Example

async function example() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const res = await paragraph.clear();
}

getRange

Get Range of paragraph with specified offset and length

Syntax

paragraph.getRange(startOffset, length)

paragraph: Paragraph object

Parameters

PropertyData TypeRequiredDescription
startOffsetnumberNoOffset (default 0, when both parameters are not passed, return range of entire paragraph)
lengthnumberNoLength of Range to get (when not passed or length exceeds paragraph length after startOffset, return range from startOffset to end of paragraph)

Return Value

Promise<Range>

Example

async function example() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const res = await paragraph.getRange(1, 10);
}

getTextContent

Get content of paragraph with specified offset and length, when parameters are not passed, default to get entire paragraph content

Syntax

paragraph.getTextContent(startOffset, length, options)

paragraph: Paragraph object

Parameters

PropertyData TypeRequiredDescription
startOffsetnumberNoOffset (starting from 0, default 0)
lengthnumberNoLength of content to get (when not passed or passed as 0, get all content after startOffset)
optionsobjectNoAdditional parameters

options structure

PropertyData TypeRequiredDescription
listSymbolbooleanNoWhether to return numbering, default false

Return Value

Promise<string>

Example

// Complete content of paragraph obtained, without numbering
async function example1() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const text = await paragraph.getTextContent();
}

// Complete content of paragraph obtained, with numbering
async function example2() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const text = await paragraph.getTextContent(undefined, undefined, { listSymbol: true });
}

setText

Set paragraph content to specified text

Syntax

paragraph.setText(content)

paragraph: Paragraph object

Return Value

Promise<boolean>

Parameters

PropertyData TypeRequiredDescription
contentstringYesPure text string to add

Example

async function example(content) {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const success = await paragraph.setText(content);
}

Paragraphs

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Collection of all paragraph objects in the document.

Properties

count

Number of paragraphs

Syntax

Application.ActiveDocument.Paragraphs.count

Application: Document type application object

Return Value

count: Promise<number>

Example

async function example() {
const count = await Application.ActiveDocument.Paragraphs.count;
}

Methods

item

Get single paragraph by paragraph number or paragraph id

Syntax

Application.ActiveDocument.Paragraphs.item(key)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
keynumber | stringYesParagraph number (number starting from 1) | Paragraph Id

Return Value

Promise<Word.Paragraph>

Example

async function example() {
// Get paragraph by index
const paragraphByIndex = await Application.ActiveDocument.Paragraphs.item(1);
// Get paragraph by id
const paragraph = await Application.ActiveDocument.Paragraphs.item(paragraphByIndex.id);
}

add

Insert a new paragraph containing specified text at specified sequential position in current document

Syntax

Application.ActiveDocument.Paragraphs.add(text, index)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
textstringYesPure text content of paragraph to insert
indexnumberNoParagraph number (starting from 1, default insert at end of document)

Return Value

Promise<Word.Paragraph>

Example

async function example(text, index) {
let paragraph = await Application.ActiveDocument.Paragraphs.add(text, index);
}

PermMark

JSSDK: 1.2.0、zOffice2022.3 Supported

Editable region object of content-protected document

Properties

name

Name of editable region object

Syntax

permMark.name

permMark: Editable region object of content-protected document

Return Value

name: Promise<string>

Example

async function example() {
const permMark = await Application.ActiveDocument.PermMarks.item(1);
const name = await permMark.name;
}

range

Get range where editable region is located

Syntax

permMark.range

permMark: Editable region object of content-protected document

Return Value

Promise<Word.Range>

Example

async function example() {
const permMark = await Application.ActiveDocument.PermMarks.item(1);
const range = await permMark.range;
}

permissionType

JSSDK: 1.9.1、zOffice V8.0 FP1 Supported

Editable region, permission for current person

Syntax

permMark.permissionType

permMark: Editable region object of content-protected document

Return Value

Promise<Word.PermissionType>

Example

async function example() {
const permMark = await Application.ActiveDocument.PermMarks.item(1);
const permissionType = await permMark.permissionType;
}

Methods

addEditors

Add editable region user information

Syntax

permMark.addEditors(option)

permMark: Editable region object of content-protected document

PropertyData TypeRequiredDescription
optionanyYesoption is {"group":["everyone"]} or {"users": string[] // user ID}

Return Value

Promise<boolean> Whether addition was successful

Example

async function example(app, option) {
let success = false;
const permMark = await Application.ActiveDocument.PermMarks.item(1);
if (permMark) editors = await permMark.addEditors(option);
}

delete

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Delete editable region

Syntax

permMark.delete()

permMark: Editable region object of content-protected document

Return Value

Promise<boolean> Whether deletion was successful

Example

async function example(app) {
let success = false;
const permMark = await Application.ActiveDocument.PermMarks.item(1);
if (permMark) success = await permMark.delete();
}

deleteEditors

JSSDK: 1.2.0、zOffice2022.3 Supported

Delete editable region user information

Syntax

permMark.deleteEditors(option)

permMark: Editable region object of content-protected document

PropertyData TypeRequiredDescription
optionanyYesoption is {"group":["everyone"]} or {"users": string[] // user ID}

Return Value

Promise<boolean> Whether deletion was successful

Example

async function example(app, option) {
let success = false;
const permMark = await Application.ActiveDocument.PermMarks.item(1);
if (permMark) success = await permMark.deleteEditors(option);
}

focus

JSSDK: 1.2.21、zOffice2022.3 FP2 hotfix1 Supported

Locate editable region

Syntax

permMark.focus()

permMark: Editable region object of content-protected document

Return Value

Promise<boolean> Whether location was successful

Example

async function example() {
const permMark = await Application.ActiveDocument.PermMarks.item(1);
const success = await permMark.focus();
}

getEditors

Get editable region user information

Syntax

permMark.getEditors()

permMark: Editable region object of content-protected document

Return Value

Promise<string> JSON string of editable region user information, in two formats:

{"group":["everyone"]} or {"users": string[] // userID}

Example

async function example(app) {
let success = false;
const permMark = await Application.ActiveDocument.PermMarks.item(1);
if (permMark) success = await permMark.getEditors();
}

getText

JSSDK: 1.2.21、zOffice2022.3 FP2 hotfix1 Supported

Get text of editable region

Syntax

permMark.getText()

permMark: Editable region object of content-protected document

Return Value

Promise<string>

Example

async function example() {
const permMark = await Application.ActiveDocument.PermMarks.item(1);
const success = await permMark.getText();
}

setEditors

Set editable member information of editable region

Syntax

permMark.setEditors(option)

permMark: Editable region object of content-protected document

PropertyData TypeRequiredDescription
optionanyYesoption is {"group":["everyone"]} or {"users": string[] // user ID}

Return Value

Promise<boolean> Whether setup was successful

Example

async function example(app, option) {
let success = false;
const permMark = await Application.ActiveDocument.PermMarks.item(1);
if (permMark) success = await permMark.setEditors(option);
}

setText

JSSDK: 1.2.21、zOffice2022.3 FP2 hotfix1 Supported

Set text of editable region

Syntax

permMark.setText()

permMark: Editable region object of content-protected document

Return Value

Promise<boolean> Whether text was set successfully

Parameters

PropertyData TypeRequiredDescription
contentstringYesText of editable region

Example

async function example(content) {
const permMark = await Application.ActiveDocument.PermMarks.item(1);
const success = await permMark.setText(content);
}

PermMarks

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Collection of editable region objects of content-protected document

Properties

count

Number of editable regions

Syntax

Application.ActiveDocument.PermMarks.count

Application: Document type application object

Return Value

count: Promise<number>

Example

async function example() {
const count = await Application.ActiveDocument.PermMarks.count;
}

Methods

item

Get editable region by parameter

Syntax

document.PermMarks.item(key)

document: Document type application object

Parameters

PropertyData TypeRequiredDescription
keystring | numberYesEditable region name/number (number starting from 1)

Return Value

Promise<Word.PermMark>

Example

async function example(key) {
const permMark = await Application.ActiveDocument.PermMarks.item(key);
}

add

JSSDK: 1.7.1、zOffice V7.2 FP1 Supported

Add editable region with Range as scope

Syntax

document.PermMarks.add(name, option, range, bHide)

document: Document type application object

Parameters

PropertyData TypeRequiredDescription
namestringYesEditable region name
optionobjectYesEditable region user information { "group": ["everyone"] } or { "users": string[] // user ID }
rangeWord.RangeNoRange to insert editable region (default: insert at current selection)
bHidebooleanNoWhether invisible to non-editable users, default false, i.e., only visible

Return Value

Promise<Word.PermMark>

Example

async function example1() {
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;

// Insert an editable region editable by everyone at specified bookmark range, name is pm1
const permMark1 = await Application.ActiveDocument.PermMarks.add('pm1', {"group":["everyone"]}, range);
// Insert an editable region editable only by user test01 at specified bookmark range, others only visible, name is pm2
const permMark2 = await Application.ActiveDocument.PermMarks.add('pm2', {"users":["test01"]}, range);
// Insert an editable region editable only by user test01 at specified bookmark range, others not visible, name is pm3
const permMark3 = await Application.ActiveDocument.PermMarks.add('pm3', {"users":["test01"]}, range, true);
}

// Insert an editable region editable only by user test01 at current selection, others only visible, name is pm
async function example1() {
const permMark = await Application.ActiveDocument.PermMarks.add('pm', {"users":["test01"]});
}

toJson

Get all editable regions contained in document

Syntax

document.PermMarks.toJson()

document: Document type application object

Return Value

Promise<string[]>, array of editable region names

Example

async function example() {
const permMarks = await Application.ActiveDocument.PermMarks.toJson();
}

Range

Range object

Properties

isCollapsed

JSSDK: 1.8.4、zOffice V7.3 FP4 Supported

Whether it is a collapsed range, i.e., no content is selected, only cursor

Syntax

range.isCollapsed

range: Range object

Return Value

boolean

Example

async function example() {
const range = await app.ActiveDocument.getSelection();
const isCollapsed = range.isCollapsed;
}

Find

JSSDK: 1.3.3、zOffice V6.0 FP3 Supported

Return a read-only Find object that contains conditions required for find operation.

Syntax

range.Find

range: Range object

Return Value

Find

Example

async function example() {
const selection = await app.ActiveDocument.getSelection();
const Find = selection.Find;
}

Bookmarks

JSSDK: 1.4.1、zOffice V7.0 FP1 Supported

Return a bookmark collection that represents all bookmarks in document, range or selection. This is a read-only Property.

Syntax

Range.Bookmarks

Range: Range object

Return Value

Word.Bookmarks

Example

// Get bookmark collection of first header range
async function example() {
const section = await app.ActiveDocument.Sections.item(1);
const headers = section.Headers;
const header = await headers.item(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage);
const range = await header.range;
const bookmarks = range.Bookmarks;
}

// Get bookmark collection of current selection
async function example() {
const range = await app.ActiveDocument.getSelection();
const bookmarks = range.Bookmarks;
}

// Get bookmark collection in table
async function example() {
const table = await app.ActiveDocument.Tables.item(1);
const range = await table.range;
const bookmarks = range.Bookmarks;
}

PermMarks

JSSDK: 1.7.1、zOffice V7.2 FP1 Supported

Return an editable region collection that represents all editable regions in document, range or selection. This is a read-only Property.

Syntax

Range.PermMarks

Range: Range object

Return Value

PermMarks

Example

// Get editable region collection of current selection
async function example() {
const range = await app.ActiveDocument.getSelection();
const permMarks = range.PermMarks;
}

// Get editable region collection in table
async function example() {
const table = await app.ActiveDocument.Tables.item(1);
const range = await table.range;
const permMarks = range.PermMarks;
}

Comments

JSSDK: 1.7.1、zOffice V7.2 FP1 Supported

Return a Comment collection that represents all comments in document, range or selection. This is a read-only Property.

Syntax

Range.Comments

Range: Range object

Return Value

Comments

Example

// Get first comment of current selection
async function example() {
const range = await app.ActiveDocument.getSelection();
const comments = range.Comments;
const comment = await comments.item(1);
}

Bold

JSSDK: 1.5.2、zOffice V7.0 FP2Supported

Return or set bold format in range. Read/write boolean value.

Syntax

Range.Bold

Range: Range object

Return Value

Bold

Example

async function example() {
const bookmark = await app.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
const isBold = await range.Bold;
console.log(isBold);
range.Bold = true;
}

Underline

JSSDK: 1.5.2、zOffice V7.0 FP2Supported

Return or set type of underline applied to range. Read/write WdUnderline.

Syntax

Range.Underline

Range: Range object

Return Value

Underline

Example

async function example() {
const bookmark = await app.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
const underline = await range.Underline;
console.log(underline);
range.Underline = Word.WdUnderline.wdUnderlineSingle;
}

Italic

JSSDK: 1.5.2、zOffice V7.0 FP2Supported

Return or set italic format in range. Read/write boolean value.

Syntax

Range.Italic

Range: Range object

Return Value

Italic

Example

async function example() {
const bookmark = await app.ActiveDocument.Bookmarks.item(1);
const range = await bookmark.range;
const isItalic = await range.Italic;
console.log(isItalic);
range.Italic = true;
}

Tables

JSSDK: 1.7.1、zOffice V7.2 FP1Supported

Return a table collection that represents all tables in selection. This is a read-only Property.

Range.Tables

Range: Range object

Return Value

Word.Tables

Example

//Get table in bookmark
async function example() {
const bookmark = await app.ActiveDocument.Bookmarks.item(1);
// Range of bookmark
const range = await bookmark.range;
// Table in specified bookmark
const tables = range.Tables;
console.log(await tables.count);
}

Methods

appendText

JSSDK: 1.2.3、zOffice2022.3 FP3 Supported

Append text after specified range (currently only supports Paragraph type range)

Syntax

range.appendText()

range: Range object

Return Value

Promise<boolean>

Parameters

PropertyData TypeRequiredDescription
contentstringYesText string to append

Example

async function example(content) {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const range = await paragraph.getRange(1, 5);
const success = await range.appendText(content);
}

clear

JSSDK: 1.2.3、zOffice2022.3 FP3 Supported

Clear text content of specified range (currently only supports Paragraph type range)

Syntax

range.clear()

range: Range object

Return Value

Promise<boolean>

Example

async function example() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const range = await paragraph.getRange(1, 5);
const success = await range.clear();
}

compare

JSSDK: 1.2.1、zOffice2022.3 FP1 Supported

Return positional relationship between two Ranges

Syntax

range.compare(_range)

range: Range object

Parameters

PropertyData TypeRequiredDescription
_rangeWord.RangeYesRange object

Return Value

Promise<Word.RangeRelation>

Example

async function example() {
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
const bRange = await bookmark.range;
const selection = await Application.ActiveDocument.getSelection();
const relation = await bRange.compare(selection);
}

getText

JSSDK: 1.2.3、zOffice2022.3 FP3 Supported

Get text content of specified range (currently only supports Paragraph type range)

Syntax

text.getText()

range: Range object

Return Value

Promise<string>

Example

// Get partial text content of specified paragraph
async function example1() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const range = await paragraph.getRange(1, 5);
const text = await range.getText();
}

// Get text content of comment range
async function example2() {
const comment = await Application.ActiveDocument.Comments.item(1);
const range = await comment.range;
const text = await range.getText();
}

// Get text content of current selection
async function example3() {
const range = await Application.ActiveDocument.getSelection();
const text = await range.getText();
}

insertText

JSSDK: 1.2.3、zOffice2022.3 FP3 Supported

Insert text at specified offset position in specified range (currently only supports Paragraph type range)

Syntax

range.insertText(offset, content)

range: Range object

Parameters

PropertyData TypeRequiredDescription
offsetnumberYesOffset
contentstringYesText string to insert

Return Value

Promise<boolean>

Example

// Insert content at specified position in paragraph
async function example1() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const range = await paragraph.getRange(1, 5);
const success = await range.insertText(0, "Insert content");
}

// Insert content at the beginning of comment area
async function example2() {
const comment = await Application.ActiveDocument.Comments.item(1);
const range = await comment.range;
const success = await range.insertText(0, "Insert content");
}

// Insert content at the beginning of current selection
async function example3() {
const range = await Application.ActiveDocument.getSelection();
const success = await range.insertText(0, "Insert content");
}

setText

JSSDK: 1.2.3、zOffice2022.3 FP3 Supported

Set specified range to specified text (currently only supports Paragraph type range)

Syntax

range.setText(content)

range: Range object

Return Value

Promise<boolean>

Parameters

PropertyData TypeRequiredDescription
contentstringYesSpecified text

Example

// Set text content for part of paragraph area
async function example1() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const range = await paragraph.getRange(1, 5);
const success = await range.setText("Replace content");
}

// Set text content for comment area
async function example2() {
const comment = await Application.ActiveDocument.Comments.item(1);
const range = await comment.range;
const text = await range.setText("Replace content");
}

// Set text content for current selection
async function example3() {
const range = await Application.ActiveDocument.getSelection();
const text = await range.setText("Replace content");
}

getHtml

JSSDK: 1.7.2、zOffice V7.2 FP2Supported

Get HtmlString of range

Syntax

range.getHtml()

Return Value

htmlDom

Example

async function example() {
const bookmark1 = await app1.ActiveDocument.Bookmarks.item(1);
const range1 = await bookmark1.range;
const html = await range1.getHtml();
}

setHtml

JSSDK: 1.7.2、zOffice V7.2 FP2Supported

Pass htmlString, paste to specified range position

Syntax

range.setHtml(html)

Return Value

Range: Position to paste to

Example

async function example() {
const bookmark1 = await app1.ActiveDocument.Bookmarks.item(1);
const range1 = await bookmark1.range;
const html = await range1.getHtml();

const bookmark2 = await app2.ActiveDocument.Bookmarks.item(1);
const range2 = await bookmark2.range;
await range2.setHtml(html);
}

scrollIntoView

JSSDK: 1.9.3、zOffice V8.0 FP3Supported

View scrolls to this range

Syntax

range.scrollIntoView()

Return Value

Promise<boolean>

Example

// View scrolls to target table position
async function example() {
const table = await app1.ActiveDocument.Tables.item(1);
const range = await table.range;
const success = await range.scrollIntoView();
}

Revision

JSSDK: 1.2.1、zOffice2022.3 FP1 Supported

Represent modifications marked by revision marks

Properties

author

Return name of user who made specified revision.

Syntax

revision.author

revision: Revision object

Return Value

author: string

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const revision = await revisions.item(1);
const author = revision.author;
}

creator

Return ID of user who made specified revision

Syntax

revision.creator

revision: Revision object

Return Value

creator: string

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const revision = await revisions.item(1);
const author = revision.creator;
}

date

Date and time of revision.

Syntax

revision.date

revision: Revision object

Return Value

date: string

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const revision = await revisions.item(1);
const date = revision.date;
}

isStyle

Whether it is a revision that modifies style.

Syntax

revision.isStyle

revision: Revision object

Return Value

isStyle: boolean

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const revision = await revisions.item(1);
const isStyle = revision.isStyle;
}

range

JSSDK: 1.3.0、zOffice V6 Supported

Return a Range object that represents the document part contained within a revision mark.

Syntax

revision.range

revision: Revision object

Return Value

Promise<Range>

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const revision = await revisions.item(1);
const range = await revision.range;
}

type

Return type of revision.

Syntax

revision.type

revision: Revision object

Return Value

type: Word.RevisionType[]

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const revision = await revisions.item(1);
const type = revision.type;
}

Methods

accept

Accept specified revision, delete revision mark and merge changes into document.

Syntax

revision.accept()

revision: Revision object

Return Value

None

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const revision = await revisions.item(1);
await revision.accept();
}

reject

Reject specified revision. Will delete revision mark without changing original text.

Syntax

revision.reject()

revision: Revision object

Return Value

None

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const revision = await revisions.item(1);
await revision.reject();
}

Revisions

JSSDK: 1.3.0、zOffice V6 Supported

Collection of modifications marked by revision marks.

Properties

count

Number of revisions.

Syntax

Revisions.count

Return Value

Promise<number>

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const count = await revisions.count;
}

Methods

acceptAll

Accept all changes。

Syntax

Revisions.acceptAll()

Return Value

None

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
await revisions.acceptAll();
}

item

Return a single Revision object from collection.

Syntax

Revisions.item(index)

Parameters

PropertyData TypeRequiredDescription
indexnumberYesRevision number (number starting from 1)

Return Value

Promise<Word.Revision>

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const revision = await revisions.item(1);
}

rejectAll

Reject all changes。

Syntax

Revisions.rejectAll()

Return Value

None

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
await revisions.rejectAll();
}

toJson

Get all revisions contained in document.

Syntax

Revisions.toJson()

Return Value

Promise<Object[]>,Array of revision information, specific information as follows:

PropertyData TypeDescription
authorstringUser name
datestringDate and time of revision
typeWord.RevisionTypeType of revision
isStylebooleanWhether it is a revision that modifies style

Example

async function example() {
const revisions = await Application.ActiveDocument.Revisions;
const json = await revisions.toJson();
}

Row

JSSDK: 1.2.0、zOffice2022.3 Supported

Table row.

Properties

range

JSSDK: 1.7.1、zOffice V7.2 FP1 Supported

Get table row range

Syntax

Row.range

Row: Row: Table row object

Return Value

Promise<Word.Range>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const range = await row.range;
}

Cells

JSSDK: 1.3.0、zOffice V6 Supported

Return a Cells collection that represents all cells in table row.

Syntax

row.Cells

row:Row: Table row object

Return Value

Promise< Word.Cells>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const Cells = row.Cells;
}

index

JSSDK: 1.3.0、zOffice V6 Supported

Row number.

Syntax

row.index

row:Row: Table row object

Return Value

Promise< number>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const index = await row.index;
}

Methods

delete

JSSDK: 1.3.0、zOffice V6 Supported

Delete row.

Syntax

row.delete()

row: row: Row object

Return Value

Promise<boolean> Whether deletion was successful

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const result = await row.delete();
}

Rows

JSSDK: 1.3.0、zOffice V6 Supported

Collection of specified table rows.

Properties

count

Number of rows.

Syntax

Rows.count

Return Value

Promise<number>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.count;
}

Methods

add

Insert row.

Syntax

Rows.add(index, cnt, isBefore)

Parameters

PropertyData TypeRequiredDescription
indexnumberYesRow number (starting from 1)
cntnumberYesNumber to insert (starting from 1, maximum 200)
isBeforebooleanYesBoolean value (true: insert row above; false: insert row below)

Return Value

Promise<boolean> Whether insertion was successful

Example

async function example(index, cnt, isBefore) {
const table = await Application.ActiveDocument.Tables.item(1);
const rows = await table.Rows;
const success = await rows.add(index, cnt, isBefore);
}

deleteRows

Delete specified row.

Syntax

Rows.deleteRows(index, cnt, isBefore)

Parameters

PropertyData TypeRequiredDescription
indexnumberYesRow number (starting from 1)
cntnumberNoNumber to delete (default 1 row)
isBeforebooleanNoBoolean value (true: delete rows above; false: delete rows below, default false)

Return Value

Promise<boolean>

Example

async function example(index, cnt, isBefore) {
const table = await Application.ActiveDocument.Tables.item(1);
const success = await table.Rows.deleteRows(index, cnt, isBefore);
}

item

Get table row by parameter.

Syntax

Rows.item(index)

Parameters

PropertyData TypeRequiredDescription
indexnumberYesRow number (starting from 1)

Return Value

Promise<Word.Row>

Example

async function example(index, cnt, isBefore) {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
}

Shape

JSSDK: 1.3.1、zOffice V6.0 FP1 Supported

Represent objects in drawing layer, such as autoshapes, freeform polygons, OLE objects, ActiveX controls or pictures. Shape object is a member of Shapes collection, which includes all shapes in main document body. (Currently only floating pictures are Supported)

Properties

name

Return name of specified shape object. Read-only String type.

Syntax

Shape.name

Return Value

Promise<string>

Example

async function example() {
const shape = await Application.ActiveDocument.Shapes.item(1);
const name = await shape.name;
}

Methods

setName

JSSDK: 1.4.0、zOffice V6.1 Supported

Set the name of the specified shape object.

Syntax

Shape.setName(name)

Parameters

PropertyData TypeRequiredDescription
namestringYesName of shape object

Return Value

Promise<boolean>

Example

async function example() {
const shape = await Application.ActiveDocument.Shapes.item(1);
const success = await shape.setName("Floating signature");
}

delete

Delete specified graphic node.

Syntax

Shape.delete()

Return Value

Promise<boolean>

Example

async function example() {
const shape = await Application.ActiveDocument.Shapes.item(1);
const success = await shape.delete();
}

focus

JSSDK: 1.4.0、zOffice V6.1 Supported

Locate floating picture

Syntax

Shape.focus()

Shape: Floating picture object

Return Value

Promise<boolean> Whether location was successful

Example

async function example() {
const shape = await Application.ActiveDocument.Shapes.item(1);
const success = await shape.focus();
}

Shapes

JSSDK: 1.3.1、zOffice V6.0 FP1 Supported

Collection of Shape objects that represent all shapes in document. Each Shape object represents an object in drawing layer, such as autoshapes, freeform polygons, OLE objects or pictures. (Currently only floating pictures are supported)

Properties

count

Return a Long that represents the number of graphics in collection. This is a read-only Property.

Syntax

Application.ActiveDocument.Shapes.count

Application: Document type application object

Return Value

Promise<number>

Example

async function example() {
const count = await Application.ActiveDocument.Shapes.count;
}

Methods

addPicture

Add a picture on drawing canvas, return a Shape object (default: add at current cursor position)

Syntax

Application.ActiveDocument.Shapes.addPicture(file, left, top, width, height, range, wdWrapType)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
fileFileYesFile object of picture (limit 10MB)。
leftnumberNoPosition of left edge of new picture relative to drawing canvas, in points. (Not currently supported)
topnumberNoPosition of top edge of new picture relative to drawing canvas, in points. (Not currently supported)
widthnumberNoWidth of picture, in points.
heightnumberNoHeight of picture, in points.
rangeWord.RangeNoRange to insert picture. (Default: add at current selection)
wrapTypeWord.WdWrapTypeNoWrap type, default is to place picture in front of text.

Return Value

Promise<Word.Shape>

Example

<input type="file" name="Insert non-embedded image" id="imageInput"/>

const inputElement = document.getElementById('imageInput');


// sample1, add picture at current selection
inputElement.onchange = async function(width, height, wrapType) {
const shapes = await Application.ActiveDocument.Shapes;
const shape = await shapes.addPicture(inputElement.files[0], undefined, undefined, width, height, undefined, wrapType);
}

// sample2, add picture at specified range
inputElement.onchange = async function(width, height, wrapType) {
const shapes = await Application.ActiveDocument.Shapes;
const pm = await Application.ActiveDocument.PermMarks.item(1);
const pmRange = await pm.range;
const shape = await shapes.addPicture(inputElement.files[0], undefined, undefined, width, height, range, wrapType);
}

item

Return a single Shape object from collection.

Syntax

Application.ActiveDocument.Shapes.item(key)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
keynumber | stringYesSerial number of Shape in document (starting from 1) or its name

Return Value

Promise<Word.Shape>

Example

async function example() {
const Shapes = await Application.ActiveDocument.Shapes;
const shape = await Shapes.item(1);
}

async function example() {
const Shapes = await Application.ActiveDocument.Shapes;
const shape = await Shapes.item('signature-image.png');
}

Style

JSSDK: 1.4.0、zOffice V6.1 Supported

Style object

Properties

headingLevel

Return heading level of paragraph.

Syntax

Style.headingLevel

Style: Style object

Return Value

Promise<Word.WdBuiltinStyle>

Example

async function example() {
const paragraph = await Application.ActiveDocument.Paragraphs.item(1);
const headingLevel = await paragraph.style.headingLevel;
}

Methods

setHeadingLevel

Set heading style

Syntax

Style.setHeadingLevel(level)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
levelWord.WdBuiltinStyleYesSpecified heading level

Return Value

Promise<boolean>

Example

// Set style heading 1 for paragraph
async function example() {
const para = await Application.ActiveDocument.Paragraphs.item(1);
await para.style.setHeadingLevel(Word.WdBuiltinStyle.wdStyleHeading1);
}

Sections

JSSDK: 1.4.1、zOffice V7.0 FP1Supported

Collection of all section objects in document.

Properties

count

Get total number of all sections in document.

Syntax

Sections.count

Return Value

Promise<number>

Example

async function example() {
const sections = await Application.ActiveDocument.Sections;
const count = await sections.count;
}

first

Get first section in document.

Syntax

Sections.first

Return Value

Promise<Word.Section>

Example

async function example() {
const sections = await Application.ActiveDocument.Sections;
const first = await sections.first;
}

last

Get last section in document.

Syntax

Sections.last

Return Value

Promise<Word.Section>

Example

async function example() {
const sections = await Application.ActiveDocument.Sections;
const last = await sections.last;
}

Methods

item

Represent a single section in document, return Section object

Syntax

Application.ActiveDocument.Sections.item(index)

Application: Document type application object

Parameters

PropertyData TypeRequiredDescription
indexnumberYesSection number (number starting from 1)

Return Value

Promise<Word.Section>

Example

async function example() {
const section = await Application.ActiveDocument.Sections.item(1);
}

Section

JSSDK: 1.4.1、zOffice V7.0 FP1Supported

Represent a section in document. Section object is a member of Sections collection. Section collection contains all sections in document.

Properties

Headers

Get all headers of current section in document, return Headers object.

Syntax

Sections.Headers

Return Value

Promise<Word.Headers>

Example

async function example() {
const section = await Application.ActiveDocument.Sections.item(1);
const headers = section.Headers;
}

Footers

Get all footers of current section in document, return Footers object.

Syntax

Sections.Footers

Return Value

Promise<Word.Footers>

Example

async function example() {
const section = await Application.ActiveDocument.Sections.item(1);
const footers = section.Footers;
}

Table

JSSDK: 1.2.0、zOffice2022.3 Supported

Table object.

Properties

range

JSSDK: 1.7.1、zOffice V7.2 FP1 Supported

Get table range

Syntax

Table.range

Table: Table object

Return Value

Promise<Word.Range>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const range = await table.range;
}

Columns

JSSDK: 1.3.0、zOffice V6 Supported

Return a Columns collection that represents all columns in table.

Syntax

table.Columns

table: Table object

Return Value

Promise< Word.Columns>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const Colunms = table.Columns;
}

Rows

JSSDK: 1.3.0、zOffice V6 Supported

Return a Rows collection that represents all rows in table.

Syntax

table.Rows

table: Table object

Return Value

Promise< Word.Rows>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const Rows = table.Rows;
}

title

JSSDK: 1.3.0、zOffice V6 Supported

Get table title.

Syntax

table.title

table: Table object

Return Value

Promise< string>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const title = await table.title;
}

Methods

delete

JSSDK: 1.3.0、zOffice V6 Supported

Delete table.

Syntax

table.delete()

table: Table object

Return Value

Promise<boolean> Whether deletion was successful

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const success = await table.delete();
}

setTitle

JSSDK: 1.4.0、zOffice V6.1 Supported

Set table title.

Syntax

Table.setTitle(title)

Parameters

PropertyData TypeRequiredDescription
titlestringYesTable title

Return Value

Promise<boolean>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const success = await table.setTitle('Table name');
}

Tables

JSSDK: 1.3.0、zOffice V6 Supported

Collection of all table objects in document

Properties

count

Number of tables.

Syntax

Tables.count

Return Value

Promise<number>

Example

async function example() {
const count = await Application.ActiveDocument.Tables.count;
}

Methods

add

Insert a blank table at current selection or specified range, table will replace the range.

Syntax

Tables.add(rowNum, columnNum, option)

Parameters

PropertyData TypeRequiredDescription
rowNumnumberYesNumber of table rows (maximum 20)
columnNumnumberYesNumber of table columns (maximum 20)
optionJSONNooption.title is the table title

Return Value

Promise<Word.Table>

Example

// Insert table at current selection position
async function example1() {
const table = await Application.ActiveDocument.Tables.add(2, 2, { title: 'Price table' });
}

// Insert table in specified area
async function example2() {
const bm = await Application.ActiveDocument.Bookmarks.item('bm1');
const range = await bm.range;
const table = await range.Tables.add(2, 2, { title: 'Price table' });
}

item

Get table object by parameter.

Syntax

Tables.item(key)

Parameters

PropertyData TypeRequiredDescription
keystring|numberYesTable title/number (number starting from 1)

Return Value

Promise<Word.Table>

Example

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
}

Window

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Return a Window object, that represents the current active window

Properties

Zoom

Document zoom options (e.g., zoom percentage)

Syntax

Application.ActiveDocument.ActiveWindow.Zoom

Application: Spreadsheet application object

Return Value

zoom: Zoom

Example

async function example() {
// Get window zoom percentage
const Zoom = Application.ActiveDocument.ActiveWindow.Zoom;
const percentage = await Zoom.percentage;
console.log(percentage);
}

revisionsView

JSSDK: 1.3.23、zOffice V6.0 FP2 hotfix 3 Supported

Return a WdRevisionsView constant, this option specifies whether Word displays original or final version of document, these versions may have revisions and format changes applied. Read-only. (Currently only final version is Supported)

Syntax

Application.ActiveDocument.ActiveWindow.revisionsView

Application: Spreadsheet application object

Example

async function example() {
const revisionsView = await Application.ActiveDocument.ActiveWindow.revisionsView;
}

showComments

JSSDK: 1.3.23、zOffice V6.0 FP2 hotfix 3 Supported

Get marker state of comments. Read-only Boolean.

Syntax

Application.ActiveDocument.ActiveWindow.showComments

Application: Spreadsheet application object

Example

async function example() {
// Whether comments in current document are displayed
const isShow = await Application.ActiveDocument.ActiveWindow.showComments;
console.log(isShow);
}

showRevisionsAndComments

JSSDK: 1.3.23、zOffice V6.0 FP2 hotfix 3 Supported

Get marker state of revisions, read-only Boolean

Syntax

Application.ActiveDocument.ActiveWindow.showRevisionsAndComments

Application:Word document application object

false: Final mode, true: Display revisions in comment box

Example

// Set to final mode
async function example1() {
app.ActiveDocument.ActiveWindow.showRevisionsAndComments = false;
const state = await app.ActiveDocument.ActiveWindow.showRevisionsAndComments;
console.log(state);
}

// Set to display revisions in comment box
async function example2() {
app.ActiveDocument.ActiveWindow.showRevisionsAndComments = true;
const state = await app.ActiveDocument.ActiveWindow.showRevisionsAndComments;
console.log(state);
}

Methods

setShowComments

JSSDK: 1.4.0、zOffice V6.1 Supported

Set whether to display comments in Word document

Syntax

ActiveWindow.setShowComments(value)

Parameters

PropertyData TypeRequiredDescription
valuebooleanYesWhether to display comments in Word document

Return Value

Promise<boolean>

Example

async function example(sheetName) {
const success = await Application.ActiveDocument.ActiveWindow.setShowComments(true);
}

setShowRevisionsAndComments

JSSDK: 1.4.0、zOffice V6.1 Supported

Set marker state of revisions and comments Syntax

ActiveWindow.setShowRevisionsAndComments(value)

Parameters

PropertyData TypeRequiredDescription
valuebooleanYesWhether to display revision and comment markers

Return Value

Promise<boolean>

Example

async function example(sheetName) {
const success = await Application.ActiveDocument.ActiveWindow.setShowRevisionsAndComments(true);
}

Zoom

JSSDK: 1.2.2、zOffice2022.3 FP2 Supported

Document zoom options (e.g., zoom percentage)

Properties

percentage

Zoom percentage of current word document/worksheet (10% ~ 400%)

Syntax

Application.ActiveDocument.ActiveWindow.Zoom.percentage

Application: Document type application object

Return Value

Promise<number>

Example

async function example() {
const percentage = await Application.ActiveDocument.ActiveWindow.Zoom.percentage;
console.log(percentage);
}

Methods

setPercentage

JSSDK: 1.4.0、zOffice V6.1 Supported

Set zoom percentage of current document (10% ~ 400%)

Syntax

Zoom.setPercentage(value)

Parameters

PropertyData TypeRequiredDescription
valuenumberYesZoom percentage of document

Return Value

Promise<boolean>

Example

async function example(sheetName) {
const success = await Application.ActiveDocument.ActiveWindow.Zoom.setPercentage(200);
}

JSSDK: 1.6.1、zOffice 7.1 FP1 Supported

Hyperlink object collection

Methods

add

Insert hyperlink at selection position

Syntax

document.Hyperlinks.add({ Address, TextToDisplay })

document: Document type application object

Parameters

PropertyData TypeRequiredDescription
AddressstringYesLink address to insert
TextToDisplaystringNoText to display for hyperlink

Return Value

Promise<void>

Example

async function example() {
const params = {
Address: 'https://example.com',
TextToDisplay: 'Example hyperlink',
}

// Get the first bookmark
const bookmark = await Application.ActiveDocument.Bookmarks.item(1);
// Select bookmark in selection
await bookmark.focus();

// Insert hyperlink at current selection position
await Application.ActiveDocument.Hyperlinks.add(params);
}

WebClipboard

Properties

Copy

JSSDK: 1.7.2、zOffice V7.2 FP2Supported

Copy content. Write Range to copy, then paste content through Paste operation.

Syntax

WebClipboard.Copy

WebClipboard: Clipboard

Return Value

Range: Object to copy

Example

async function example() {
const bookmark1 = await app1.ActiveDocument.Bookmarks.item(1);
const range1 = await bookmark1.range;
app.ActiveDocument.WebClipboard.Copy = range1;

const bookmark2 = await app2.ActiveDocument.Bookmarks.item(1);
const range2 = await bookmark2.range;
app.ActiveDocument.WebClipboard.Paste = range2;
}

Paste

JSSDK: 1.7.2、zOffice V7.2 FP2Supported

Paste content. After Copy operation is performed, paste to specified position through Paste operation.

Syntax

WebClipboard.Paste

WebClipboard: Clipboard

Return Value

Range: Position to paste to

Example

async function example() {
const bookmark1 = await app1.ActiveDocument.Bookmarks.item(1);
const range1 = await bookmark1.range;
app.ActiveDocument.WebClipboard.Copy = range1;

const bookmark2 = await app2.ActiveDocument.Bookmarks.item(1);
const range2 = await bookmark2.range;
app.ActiveDocument.WebClipboard.Paste = range2;
}