Sheet相关

获取所有sheet名称

  1. await demo.ready()
  2. const app = demo.ExcelApplication()
  3. const Names = []
  4. // For(start, end, step, handle)
  5. await app.For(1, app.Sheets.Count, 1, async (Index) => {
  6. Names.push(await app.Sheets.Item(Index).Name)
  7. })
  8. console.log(Names)

获取当前sheet名称

  1. await demo.ready()
  2. const app = demo.ExcelApplication()
  3. const name = await app.ActiveSheet.Name
  4. console.log('ActiveSheet:', name)

切换到指定sheet

  1. await demo.ready()
  2. const app = demo.ExcelApplication()
  3. const sheetIndex = 1 // sheets序号, 从1开始
  4. app.Sheets.Item(sheetIndex).Activate() // 切换sheet

切换sheet回调事件

  1. await demo.ready()
  2. const app = demo.Application
  3. app.Sub.Worksheet_Activate = async function() {
  4. console.log("ActiveSheet:", await app.ActiveSheet.Name)
  5. }