await demo.ready() // 务必等待 demo ready 之后再调用高级 api,demo 对象是指 JS-SDK 实例化后的对象,参考使用说明->初始化
// 文字const wordApp = demo.WordApplication()// 表格const excelApp = demo.ExcelApplication()// 演示const pptApp = demo.PPTApplication()const pdfApp = demo.PDFApplication()// 自动识别const app = demo.Application
/** @param: WdInformation: {* wdNumberOfPagesInDocument: 4* }* @return: {PagesCount: number, End: boolean}*/const app = demo.WordApplication()const {Enum} = applet totalPages = await app.ActiveDocument.Range.Information(Enum.WdInformation.wdNumberOfPagesInDocument)if (totalPages.End) {// 获取总页数是异步过程,仅当totalPages.End为true时,获取到的总页数才是准确的console.log("加载完了!一共", totalPages.PagesCount, "页")}
/** @param: WdInformation: {* wdActiveEndPageNumber: 3* }* @return: number*/const app = demo.WordApplication()const {Enum} = applet currentPage = await app.ActiveDocument.Selection.Information(Enum.WdInformation.wdActiveEndPageNumber)
/** @param: { What?: WdGoToItem, Which?: WdGoToDirection.wdGoToAbsolute, Count?: number, Name?: string}* WdGoToItem: {* wdGoToPage: 1,* }* WdGoToDirection: {* wdGoToAbsolute: 1* }* @return: number 返回跳转页*/const app = demo.WordApplication()const {Enum} = appconst page = await app.ActiveDocument.Selection.GoTo(Enum.WdGoToItem.wdGoToPage, Enum.WdGoToDirection.wdGoToAbsolute, 10)// 或者const page = await app.ActiveDocument.Selection.GoTo({What: Enum.WdGoToItem.wdGoToPage,Which: Enum.WdGoToDirection.wdGoToAbsolute,Count: 10})
/** @param: bool* true 为显示, false 为隐藏*/// 隐藏评论demo.WordApplication().ActiveDocument.ActiveWindow.View.ShowComments = false
/** @param: bool* true 为显示, false 为隐藏*/// 隐藏目录demo.WordApplication().ActiveDocument.ActiveWindow.DocumentMap = false
/** @return: number*/await demo.WordApplication().ActiveDocument.ActiveWindow.View.Zoom.Percentage // 读取视图缩放比例/** @param : 50 <= number <= 300 (缩放属性值在50%到 300%之间)*/demo.WordApplication().ActiveDocument.ActiveWindow.View.Zoom.Percentage = 100 // 设置视图缩放比例
const app = demo.ExcelApplication()const Names = []const count = await app.Sheets.Count;for(let index = 1; index <= count; index++) {Names.push(await app.Sheets.Item(index).Name);}console.log(Names)
const app = demo.ExcelApplication()const name = await app.ActiveSheet.Name
const app = demo.ExcelApplication()const sheetIndex = 1 // sheets序号, 从1开始app.Sheets.Item(sheetIndex).Activate() // 切换sheet
/** @return: number*/await demo.ExcelApplication().ActiveWorkbook.ActiveSheetView.Zoom // 读取视图缩放比例/** @param : 10 <= number <= 500 (缩放属性值在10%到500%之间)*/demo.ExcelApplication().ActiveWorkbook.ActiveSheetView.Zoom = 100 // 设置视图缩放比例
/** @return: number*/let totalPages = await demo.PPTApplication().ActivePresentation.Slides.Count
/** @return: number*/let totalPages = await demo.PPTApplication().ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
/** @param: number*/await demo.PPTApplication().ActivePresentation.SlideShowWindow.View.GotoSlide(3) // 跳转到第三页
await demo.PPTApplication().ActivePresentation.SlideShowSettings.Run()
await demo.PPTApplication().ActivePresentation.SlideShowWindow.View.Exit()
await demo.PPTApplication().ActivePresentation.SlideShowWindow.View.GotoNextClick()
await demo.PPTApplication().ActivePresentation.SlideShowWindow.View.GotoPreClick()
/** @return: string ('preview' | 'play')*/let currentState = await demo.PPTApplication().ActivePresentation.SlideShowWindow.View.State
/** @return: number*/await demo.PPTApplication().ActivePresentation.View.Zoom // 读取视图缩放比例/** @param : 1 <= number <= 400 (缩放属性值在1%到400%之间)*/demo.PPTApplication().ActivePresentation.View.Zoom = 100 // 设置视图缩放比例(非播放模式)
/** @return: number*/let totalPages = await demo.PDFApplication().ActivePDF.PagesCount
/** @return: number*/let totalPages = await demo.PDFApplication().ActivePDF.CurrentPage
/** @param : { PageNum: number }*/let PageNum = 10await demo.PDFApplication().ActivePDF.JumpToPage({PageNum})
/** 1:单页模式* 0:多页模式*/demo.PDFApplication().ActivePDF.PageMode = 1 // 设置为单页模式
/** true:显示目录* false:隐藏目录*/demo.PDFApplication().ActivePDF.DocumentMap = true // 显示目录
/** @return: number*/await demo.PDFApplication().ActivePDF.Zoom // 读取视图缩放比例/** @param : 1 <= number <= 400 (缩放属性值在1%到400%之间)*/demo.PDFApplication().ActivePDF.Zoom = 100 // 设置视图缩放比例
demo.on('事件名', function(data) {// do something...})
事件名 | 说明 |
fileOpen | 文件打开成功或者失败时的事件回调 |
error | 错误发生时的事件回调,会返回错误码 |
fileStatus | 文件保存的事件回调,会返回状态 status 值:0表示文档无更新,1表示版本保存成功,2表示暂不支持保存空文件,3表示空间已满,4表示保存中请勿频繁操作,5表示保存失败,6表示文件更新保存中,触发场景:修改文档内容触发的保存,7表示文档内容修改保存成功 |
本页内容是否解决了您的问题?