[英]How to run a Google Sheets App Script, and if there is an error, then call Spreadsheet function IMPORTXML() instead to populate the cell?
To get the price of bitcoin and other cryptocurrencies into my Google Sheets spreadsheet, I use this function:为了将比特币和其他加密货币的价格输入我的 Google 表格电子表格,我使用了这个 function:
=importJSON("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin","0.current_price")
where importJSON is a Google App Script provided by coingecko (see https://blog.coingecko.com/import-coingecko-cryptocurrency-data-into-google-sheets/ )其中 importJSON 是 coingecko 提供的 Google App Script(参见https://blog.coingecko.com/import-coingecko-cryptocurrency-data-into-google-sheets/ )
This works fine for a few lookups, but if the spreadsheet has many cryptocurrencies, a whole bunch of them will say "Error: Exceed maximum execution time (line 0)."这适用于一些查找,但如果电子表格有很多加密货币,一大堆会说“错误:超过最大执行时间(第 0 行)”。
Is it possible to detect this error, and if there is an error, call this function instead:是否可以检测到这个错误,如果有错误,调用这个 function 代替:
=IMPORTXML("https://coinmarketcap.com/currencies/bitcoin","//div[@class='priceValue___11gHJ']")
The problem is that this is a Google Sheets function and I don't know how to call it from inside the Google Apps script inside the catch(err) code block.问题是这是一个 Google 表格 function,我不知道如何从 catch(err) 代码块内的 Google Apps 脚本中调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.