This topic describes how to export tables, obtain worksheet names, switch worksheets, obtain the operator information, and listen to clipboard events.
Export a table document
Export the entire table document
Export the entire table document as a PDF file or an image file, and obtain the URL of the exported file.
Syntax
Expression.ActiveWorkbook.ExportAsFixedFormat({ Type }
Expression: the document type application object.
Parameters
Parameter
Data type
Required
Description
Type
Enum
No
The type of the file to which the table document is exported. Valid values of
Enum.XlFixedFormatType
:0 or xlTypePDF: PDF format.
1 or xlTypeXPS: XML Paper Specification (XPS) format. This format is not supported.
2 or xlTypeIMG: IMG format.
Return value
Parameter
Data type
Description
url
string
The URL of the exported file.
Example
Export the table document as a PDF file
async function example() { await instance.ready(); const app = instance.Application; // Export the entire table document. const workbookPdfUrl = await app.ActiveWorkbook.ExportAsFixedFormat(); console.log(workbookPdfUrl); }
Export the table document as an image file
async function example() { await instance.ready(); const app = instance.Application; // Export the entire table document. const workbookPdfUrl = await app.ActiveWorkbook.ExportAsFixedFormat({ Type: app.Enum.XlFixedFormatType.xlTypeIMG, }); console.log(workbookPdfUrl); }
Export the current worksheet
Export the current worksheet as a PDF file or an image file, and obtain the URL of the exported file.
Syntax
Expression.ActiveWorkbook.ActiveSheet.ExportAsFixedFormat({ Type }
Expression: the document type application object.
Parameters
Parameter
Data type
Required
Description
Type
Enum
No
The type of the file to which the table document is exported. Valid values of
Enum.XlFixedFormatType
:0 or xlTypePDF: PDF format.
1 or xlTypeXPS: XML Paper Specification (XPS) format. This format is not supported.
2 or xlTypeIMG: IMG format.
Return value
Parameter
Data type
Description
url
string
The URL of the exported file.
Example
Export the current worksheet as a PDF file
async function example() { await instance.ready(); const app = instance.Application; // Export the current worksheet. const workbookPdfUrl = await app.ActiveWorkbook.ActiveSheet.ExportAsFixedFormat(); console.log(workbookPdfUrl); }
Export the current worksheet as an image file
async function example() { await instance.ready(); const app = instance.Application; // Export the current worksheet. const workbookPdfUrl = await app.ActiveWorkbook.ActiveSheet.ExportAsFixedFormat({ Type: app.Enum.XlFixedFormatType.xlTypeIMG, }); console.log(workbookPdfUrl); }
Obtain worksheet names
Obtain the name of the current worksheet
Syntax
Expression.ActiveWorkbook.ActiveSheet.Name
Expression: the document type application object.
Return value
Returns a
string
representing the name of the worksheet.Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the name of the current worksheet. const name = await app.ActiveWorkbook.ActiveSheet.Name; console.log(name); }
Switch worksheets
Switch to a specified worksheet
Syntax
Expression.ActiveWorkbook.Sheets.Item(Index).Activate()
Expression.Sheets(Index).Activate()
Expression: the document type application object.
Parameters
Parameter
Data type
Required
Description
Index
Number
Yes
The index number of the worksheet.
Examples
Example 1:
async function example() { await instance.ready(); const app = instance.Application; // Switch to the specified worksheet. const sheetIndex = 2; // The index number of the worksheet. The number starts from 1. app.ActiveWorkbook.Sheets.Item(sheetIndex).Activate(); }
Example 2
async function example() { await instance.ready(); const app = instance.Application; // Switch to the specified worksheet. const sheetIndex = 2; // The index number of the worksheet. The number starts from 1. app.Sheets(sheetIndex).Activate(); }
Listen to the worksheet switch events
Syntax
Expression.Sub.Worksheet_Activate = Function
Expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Listen to the worksheet switch events. app.Sub.Worksheet_Activate = async () => { console.log('ActiveSheet:', await app.ActiveSheet.Name); }; }
Obtain the operator information
Obtain the information about the current operator.
Syntax
Expression.ActiveWorkbook.GetOperatorsInfo()
Expression: the document type application object.
Return value
Object object
Parameter
Data type
Description
type
String
The request type.
response
Object
Details about the users.
Structure of the response parameter
Parameter
Data type
Description
id
String
The user ID.
avatar_url
Object
The profile picture of the user.
logined
Object
The logon status of the user.
name
Object
The name of the user.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the information about the current operator. const operatorsInfo = await app.ActiveWorkbook.GetOperatorsInfo(); console.log(operatorsInfo); }
Listen to the clipboard events
Listen to the copy operations.
Syntax
Expression.Sub.Clipboard_Copy = Function
Expression: the document type application object.
Return value
Parameter
Data type
Description
copyId
String
The ID of the copy operation.
isRestoreFocus
Boolean
Undefined.
text
String
The copied content.
Example
async function example() { await instance.ready(); const app = instance.Application; // Listen to the copy operations. app.Sub.Clipboard_Copy = async (e) => { await console.log(e); } }
Set the zoom ratio
Set the zoom ratio of a window.
Syntax
Expression.ActiveWindow.Zoom
Expression: the document type application object.
Return value
Returns a
number
representing the zoom ratio.Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the zoom ratio. const zoom = await app.ActiveWindow.Zoom; console.log(zoom); // Set the zoom ratio. app.ActiveWindow.Zoom = 10; }
Show or hide gridlines
Show or hide gridlines.
Syntax
Expression.ActiveWindow.DisplayGridlines = Boolean
Expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Hide gridlines. app.ActiveWindow.DisplayGridlines = false; }
Show or hide headings
Show or hide the row and column headings.
Syntax
Expression.ActiveWindow.DisplayHeadings = Boolean
Expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Hide the row and column headings. app.ActiveWindow.DisplayHeadings = false; }
Save a document
Save changes to a document.
JS-SDK V1.1.9 and later support this feature.
Syntax
Expression.ActiveWorkbook.Save()
Expression: the document type application object.
Return value
Parameter
Data type
Description
result
String
The save status.
size
Number
The size of the document. Unit: bytes.
version
Number
The version number.
Description of save status
Save status
Description
ok
The version is saved. You can view the saved version in the historical versions of the document.
nochange
The document is not updated. You do not need to save the version.
SavedEmptyFile
The document is empty and cannot be saved.
This status is returned when the document is empty after the kernel is saved.
SpaceFull
The storage space is used up.
QueneFull
Frequent saving operations are not allowed when the document is being saved.
This status is returned when the saving operation queue is full on the server.
fail
Failed to save the document.
Example
async function example() { await instance.ready(); const app = instance.Application; // Save changes to the document. const saveResult = await app.ActiveWorkbook.Save(); console.log(saveResult); }
Change the status of the card view
JS-SDK V1.1.15 and later support this feature.
Syntax
Expression.ActiveWorkbook.SwitchCardView()
Expression: the document type application object.
Parameter
Specify a value of the boolean type to change the status of the card view.
Parameter
Data type
Required
Description
Status
Boolean
Yes
You can only turn on the card view.
Example
async function example() { await instance.ready(); const app = instance.Application; // Turn on the card view. await app.ActiveWorkbook.SwitchCardView(true); }