This topic describes how to call advanced operations to directly manage documents for online document collaboration.
Overview
The API style of the JavaScript Software Development Kit (JS-SDK) is consistent with Visual Basic for Applications (VBA). The APIs are compatible with VBA operations and parameters. When you call an index, start from 1.
The advanced operations of the JS-SDK are categorized based on document types:
Text (Word): text documents such as DOC, DOCX, and WPS documents.
Table (Excel): table documents such as XLS and XLSX documents.
Presentation (PPT): presentation documents such as PPT and PPTX documents.
PDF: PDF documents.
Common: advanced operations that can be used across all types of documents.
The term instance in this topic refers to the JS-SDK instance. For more information, see Quick Start.
Step 1: Wait for instantiation to complete
Before you call advanced operations, ensure that the instance is ready.
window.onload = async function() {
const instance = aliyun.config({
url: 'online document preview URL',
});
// Wait until the instance is ready, then call advanced operations.
await instance.ready();
};Step 2: Obtain the document type application object
You can use WordApplication, ExcelApplication, PPTApplication, or PDFApplication to determine the document type. To automatically identify the document type, you can use instance.Application.
// Text document.
const wordApp = instance.WordApplication();
// Table document.
const excelApp = instance.ExcelApplication();
// Presentation document.
const pptApp = instance.PPTApplication();
// PDF document.
const pdfApp = instance.PDFApplication();
// Automatic identification.
const app = instance.Application;Step 3: Call advanced operations
The following example shows how to use advanced operations to set the zoom ratio of a text document.
<script src="https://g.alicdn.com/IMM/office-js/1.1.15/aliyun-web-office-sdk.min.js"></script>
<script>
window.onload = async function() {
const instance = aliyun.config({
url: 'Word document path',
});
// Wait until the instance is ready.
await instance.ready();
// Automatically identify the document type.
const app = instance.Application;
// Set the document zoom ratio to 50%.
app.ActiveDocument.ActiveWindow.View.Zoom.Percentage = 50;
};
</script>