google-sheets - 使用自定义脚本作为公式时如何使用单元格的值?
问题描述
功能(https://blog.coingecko.com/import-coingecko-cryptocurrency-data-into-google-sheets/):
/**
* Imports JSON data to your spreadsheet
* @param url URL of your JSON data as string
* @param xpath simplified xpath as string
* @customfunction
*/
function IMPORTJSON(url,xpath){
try{
// /rates/EUR
var res = UrlFetchApp.fetch(url);
var content = res.getContentText();
var json = JSON.parse(content);
var patharray = xpath.split(".");
//Logger.log(patharray);
for(var i=0;i<patharray.length;i++){
json = json[patharray[i]];
}
//Logger.log(typeof(json));
if(typeof(json) === "undefined"){
return "Node Not Available";
} else if(typeof(json) === "object"){
var tempArr = [];
for(var obj in json){
tempArr.push([obj,json[obj]]);
}
return tempArr;
} else if(typeof(json) !== "object") {
return json;
}
}
catch(err){
return "Error getting data";
}
}
谷歌表格公式:
=importJSON("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin","0.current_price")
我想用另一个单元格中的值替换比特币这个词,比如 C3。
这是我的代码不起作用(给出公式解析错误):
=importJSON(=CONCATENATE("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=",$C3),"0.current_price")
解决方案
尝试:
=IMPORTJSON("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids="&$C3),
"0.current_price")
推荐阅读
- google-chrome - 如何在 Chrome DevTools 网络面板中否定 `is:` 过滤器属性
- c - 如何通过指针访问结构的第二个成员?
- django - Nginx 无法代理传递给 Django docker 容器
- tensorflow - 使用 TPU 运行时在 Google Colab 上训练 Keras 模型时出错
- android - 如何保存和显示共享首选项中的项目
- php - 在 Nextcloud 上通过 SAML 登录失败,并显示“未配置帐户”
- python - 将数据从 Python 数据帧快速插入 SQL Server
- c# - 如何使用来自 ac# 控制台应用程序的 RabbitMQ API 创建 RabbitMQ 用户
- linux - shell脚本键值比较2个文件
- javascript - 将用户导入 Google 套件时忽略错误