网站搜索

typescript - 我如何为 Excel 加载项自定义函数设置环境变量?


我正在开发一个 Excel 加载项的自定义函数,但我在如何将环境变量添加到项目中遇到了困难。根据我的研究,我们在运行时无法访问清单文件,并且由于代码在 Excel 内部运行,我们也无法访问环境变量(例如 NODE_ENV)。阅读文档时,我似乎找不到任何关于如何在代码中处理环境变量的细节。我如何才能在代码中使用环境变量?

在这个例子中,我的baseUrl应该根据我所处的环境而改变。

/**
* Returns price.
* @customfunction PRICE
* @param {string} symbol
* @returns string
*/
export async function price(symbol: string): Promise<string> {
  try {
    const url = `${baseUrl}/api/${symbol}`;
    const response = await axios.get(url);

    return response.data[0].symbol;
  } catch (err) {
    return err.message;
  }
}

答案#1

感谢你的提问,但恐怕目前不支持这个功能。

也许你可以分享更多关于你的情况的细节,这样可能会考虑其他选项。