0

如何在我的 Excel 电子表格中调用它?Rick 在下面用下面的代码帮助了我,但是我怎么称呼它呢?我正在尝试 VLOOKUP numOfParts(在参数中询问)并返回 finalInspectionPerPart。

async function inspectionMins(numOfParts) {

  try {
    let finalInspectionPerPart;
    const procEff = 0.72;

    await Excel.run(async function (context) {
      const range = context.workbook.worksheets.getItem("Sheet1").getRange("A1:B9");
      finalInspectionPerPart = context.workbook.functions.vlookup(numOfParts, range, 2, false);
      finalInspectionPerPart.load('value');
      await context.sync();
      return (finalInspectionPerPart.value / procEff);
    })
  } catch (error) {
    // handle error
  };
}

在此处输入图像描述

4

1 回答 1

1

很难使用您的代码,因为我们没有 A1:B9 的示例数据。作为第一次尝试用 ES6 语法做你想做的事情,试试:

async function inspectionMins(numOfParts) {

  try {
    let finalInspectionPerPart;
    const procEff = 0.72;

    await Excel.run(async function (context) {
      const range = context.workbook.worksheets.getItem("Sheet1").getRange("A1:B9");
      finalInspectionPerPart = context.workbook.functions.vlookup(numOfParts, range, 2, false);
      finalInspectionPerPart.load('value');

      await context.sync();
      return (finalInspectionPerPart.value / procEff);
    })
  } catch (error) {
      // handle error
  };  
}

您需要使用以下await关键字调用此函数:

await inspectionMins(5);
于 2019-12-10T01:03:59.413 回答