【问题标题】:UDF Excel Using Vlookup? JavaScript APIUDF Excel 使用 Vlookup? JavaScript API
【发布时间】:2019-12-10 00:17:10
【问题描述】:

如何在我的 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
  };
}

【问题讨论】:

    标签: excel office-js custom-functions-excel


    【解决方案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);
    

    【讨论】:

    • 嗨瑞克!这次真是万分感谢!我附上了一张图片作为示例数据。我在哪里调用带有 await 关键字的函数?谢谢
    • 嗨 Rick,我仍然对调用 await InspectionMins(5); 感到困惑。如何在 Excel 中调用它?
    • 您在创建自定义函数吗?如果是这样,那么以下文章可能会有所帮助:docs.microsoft.com/en-us/office/dev/add-ins/excel/….
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多