1

所以我试图使用 Scriptlab 中的 RangeAreas 类一次从多个范围中检索一些信息,但我无法让它工作。这是我的代码:

$("#run").click(() => tryCatch(run));

async function run() {

  await Excel.run(async (context) => {
    var sheet = context.workbook.worksheets.getActiveWorksheet();
    var rangeAreas = sheet.getRanges("F3:F5, H3:H5");

    rangeAreas.load("address");

    await context.sync();

    console.log(rangeAreas.address);
  });
}

/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
  try {
    await callback();
  } catch (error) {
    // Note: In a production add-in, you'd want to notify the user through your add-in's UI.
    console.error(error);
  }
}

这是我在 Scriptlab 控制台中遇到的错误:

c {name: "RichApi.Error", code: "InvalidArgument", traceMessages: Array[0], innerError: null, debugInfo: Object…}
 name: "RichApi.Error"
 code: "InvalidArgument"
 traceMessages: Array[0]
 innerError: null
▶debugInfo: Object
 code: "InvalidArgument"
 message: "L’argument est manquant ou non valide, ou a un format incorrect."
 toString: function ()
 errorLocation: "Worksheet.getRanges"
 statement: "var ranges=activeWorksheet.getRanges(...);"
▶surroundingStatements: Array[8]
 0: "var workbook=context.workbook;"
 1: "var worksheets=workbook.worksheets;"
 2: "var activeWorksheet=worksheets.getActiveWorksheet();"
 3: "// >>>>>"
 4: "var ranges=activeWorksheet.getRanges(...);"
 5: "// <<<<<"
 6: "// Instantiate {ranges}"
 7: "ranges.load(["address"]);"
▶fullStatements: Array[6]
 line: 24
 column: 243520
 sourceURL: "https://appsforoffice.microsoft.com/lib/1/hosted/excel-mac-16.00.js"

我确定我在某个地方犯了一个愚蠢的错误,但我就是找不到哪里,这让我发疯。任何帮助是极大的赞赏。

4

1 回答 1

1

你的代码在我这边运行得很好。您的系统语言环境是法语吗?范围的分隔符存在一个已知问题,分隔符根据系统本地更改。

所以我想在法语中它可能使用“;”,你可以试试下面的代码吗?

var rangeAreas = sheet.getRanges("F3:F5; H3:H5");
于 2020-06-08T12:51:57.913 回答