tencent cloud

All product documents
APIs
Advanced Features
Last updated: 2024-06-12 15:27:03
Advanced Features
Last updated: 2024-06-12 15:27:03
The JS-SDK provides advanced features to directly manipulate files. Below is the call process of advanced features:

1. Wait for a file to be loaded

await demo.ready() // You can call an advanced API only after the demo is ready. The demo object is the object after the JS-SDK is instantiated.

2. Get the file object

// Text
const wordApp = demo.WordApplication()
// Spreadsheet
const excelApp = demo.ExcelApplication()
// Presentation
const pptApp = demo.PPTApplication()
// PDF
const pdfApp = demo.PDFApplication()

// Automatic recognition
const app = demo.Application

3. Use advanced features

Below is the sample code of using advanced features on text, spreadsheet, presentation, and PDF files. For the specific formats supported for each file type, see Specifications and Limits.

Text file

Get the total number of pages
/*
* @param: WdInformation: {
* wdNumberOfPagesInDocument: 4
* }
* @return: {PagesCount: number, End: boolean}
*/
const app = demo.WordApplication()
const {Enum} = app
let totalPages = await app.ActiveDocument.Range.Information(Enum.WdInformation.wdNumberOfPagesInDocument)
if (totalPages.End) {
// Getting the total number of pages is an async operation. The obtained number of pages is accurate only after `totalPages.End` becomes `true`.
console.log("All pages are loaded. There are ", totalPages.PagesCount, " pages in total.")
}

Spreadsheet file

Get the names of all sheets
const app = demo.ExcelApplication()
const Names = []
// For(start, end, step, handle)
await app.For(1, app.Sheets.Count, 1, async (Index) => {
Names.push(await app.Sheets.Item(Index).Name)
})
console.log(Names)

Presentation file

Get the total number of pages
/*
* @return: number
*/
let totalPages = await demo.PPTApplication().ActivePresentation.Slides.Count

PDF file

Get the total number of pages
/*
* @return: number
*/
let totalPages = await demo.PDFApplication().ActivePDF.PagesCount
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon