为自定义函数 Excel 加载项中的所有行调用一次外部服务
Call external service once for all the rows in Custom Functions Excel Add-in
function stockPrice(ticker) {
var url = "https://api.iextrading.com/1.0/stock/" + ticker + "/price";
return fetch(url)
.then(function(response) {
return response.text();
})
.then(function(text) {
return parseFloat(text);
});
// Note: in case of an error, the returned rejected Promise
// will be bubbled up to Excel to indicate an error.
}
CustomFunctionMappings.STOCKPRICE = stockPrice;
是否有可能通过在一个请求中为它提供每一行的所有参数来批处理 Web 服务请求并仅调用一次,从而立即使用从服务返回的相应响应更新所有行,而不是为每一行调用网络服务?这将有助于处理大量行。
是的,可以通过这种方式批量处理请求。我们的一位自定义函数工程师 Michael Zlatkovsky 在 GitHub gist 中准备了一个示例,展示了如何执行此操作。此外,在下个月,自定义函数文档团队正在编写一份专门用于解决批处理问题的文档,因为我们知道这个主题很受关注。
如果您需要其他帮助,请告诉我 - 谢谢!
function stockPrice(ticker) {
var url = "https://api.iextrading.com/1.0/stock/" + ticker + "/price";
return fetch(url)
.then(function(response) {
return response.text();
})
.then(function(text) {
return parseFloat(text);
});
// Note: in case of an error, the returned rejected Promise
// will be bubbled up to Excel to indicate an error.
}
CustomFunctionMappings.STOCKPRICE = stockPrice;
是否有可能通过在一个请求中为它提供每一行的所有参数来批处理 Web 服务请求并仅调用一次,从而立即使用从服务返回的相应响应更新所有行,而不是为每一行调用网络服务?这将有助于处理大量行。
是的,可以通过这种方式批量处理请求。我们的一位自定义函数工程师 Michael Zlatkovsky 在 GitHub gist 中准备了一个示例,展示了如何执行此操作。此外,在下个月,自定义函数文档团队正在编写一份专门用于解决批处理问题的文档,因为我们知道这个主题很受关注。 如果您需要其他帮助,请告诉我 - 谢谢!