[英]Google App - Doesn't Populate Spreadsheet Cell During Script Run using Debug
[英]How to run a Google Sheets App Script, and if there is an error, then call Spreadsheet function IMPORTXML() instead to populate the cell?
为了将比特币和其他加密货币的价格输入我的 Google 表格电子表格,我使用了这个 function:
=importJSON("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin","0.current_price")
其中 importJSON 是 coingecko 提供的 Google App Script(参见https://blog.coingecko.com/import-coingecko-cryptocurrency-data-into-google-sheets/ )
这适用于一些查找,但如果电子表格有很多加密货币,一大堆会说“错误:超过最大执行时间(第 0 行)”。
是否可以检测到这个错误,如果有错误,调用这个 function 代替:
=IMPORTXML("https://coinmarketcap.com/currencies/bitcoin","//div[@class='priceValue___11gHJ']")
问题是这是一个 Google 表格 function,我不知道如何从 catch(err) 代码块内的 Google Apps 脚本中调用它。
示例公式:
=IFERROR(importJSON("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin","0.current_price"),IMPORTXML("https://coinmarketcap.com/currencies/bitcoin","//div[@class='priceValue___11gHJ']"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.