将函数从 Script lab 复制到 excel js udf 项目给出错误 'CustomFunctions' is not defined

问题描述 投票:0回答:0

我是office js的新手。我创建了一个具有共享运行时的 udf 项目,其中包含时钟、当前时间示例函数。

我在下面添加了脚本实验室的功能

/**
 * Returns the #NUM! error as part of a 2-dimensional array.
 * @customfunction
 * @param {number} first First parameter.
 * @param {number} second Second parameter.
 * @param {number} third Third parameter.
 * @returns {number[][]} Three results, as a 2-dimensional array.
 */
function returnInvalidNumberError(first, second, third) {
  // Use the `CustomFunctions.Error` object to retrieve an invalid number error.
  const error = new CustomFunctions.Error(
    CustomFunctions.ErrorCode.invalidNumber // Corresponds to the #NUM! error in the Excel UI.
  );

  // Enter logic that processes the first, second, and third input parameters.
  // Imagine that the second calculation results in an invalid number error.
  const firstResult = first;
  const secondResult = error;
  const thirdResult = third;

  // Return the results of the first and third parameter calculations
  // and a #NUM! error in place of the second result.
  return [[firstResult], [secondResult], [thirdResult]];
}

它给出“CustomFunctions”未定义。还声明了“returnInvalidNumberError”,但它的值永远不会被读取。

现在这个函数在脚本实验室中工作,所以它也应该在 js 项目中工作,但它没有。我做错了什么。

我尝试为自定义功能添加包但没有用

office-js office-addins custom-functions-excel
© www.soinside.com 2019 - 2024. All rights reserved.