Office365 在Excel Javascript API中循环浏览所有工作表的最佳方法?

Office365 在Excel Javascript API中循环浏览所有工作表的最佳方法?,office365,office-js,excel-addins,Office365,Office Js,Excel Addins,我想循环浏览工作簿中的每个工作表,并对每个工作表执行操作(例如,运行calculate())。出于性能方面的原因,我希望将这一切都集成在一起 问题是,在同步之前,我只能通过一些有限的方式获取工作表,如通过或通过,这使得循环变得困难 我能想到的最佳方法是使用getFirst()和getNext(): Excel.run(函数(ctx){ var sheets=ctx.workbook.worksheets; var sheetCount=sheets.getCount(); var current

我想循环浏览工作簿中的每个工作表,并对每个工作表执行操作(例如,运行
calculate()
)。出于性能方面的原因,我希望将这一切都集成在一起

问题是,在同步之前,我只能通过一些有限的方式获取工作表,如通过或通过,这使得循环变得困难

我能想到的最佳方法是使用
getFirst()
getNext()

Excel.run(函数(ctx){
var sheets=ctx.workbook.worksheets;
var sheetCount=sheets.getCount();
var currentSheet=sheets.getFirst();
currentSheet.calculate()
如果(张数>1){

对于(var i=2;i您的代码工作吗?看起来很可疑--您正在执行一个
sheets.getCount()
,但是在继续之前您没有同步。因此,我不确定
sheetCount>1
我啊,我怀疑您提到的事情(包括代码不太工作).谢谢你的建议…这将有助于降低这些东西的成本。
Excel.run(function(ctx) {
  var sheets = ctx.workbook.worksheets;
  var sheetCount = sheets.getCount();
  var currentSheet = sheets.getFirst();
  currentSheet.calculate()

  if (sheetCount > 1) {
    for (var i = 2; i <= sheetCount; i++) {
      currentSheet = currentSheet.getNext();
      currentSheet.calculate();
    }
  }
  return ctx.sync();
});
Excel.run(function(ctx) {
    var sheets = ctx.workbook.worksheets;
    sheets.load("$none");
    await context.sync();

    sheets.items.forEach(sheet => sheet.calculate());
    await context.sync();
});