[英]Unable to output or save API response from custom function in Google sheet
我有以下Google App脚本,最终会返回一个矩阵,但是我可以更改行并使用appendRow方法,因为我试图从自定义函数调用它。
有关自定义函数返回的内容,请咨询有关堆栈溢出和GAS文档的其他相关问题,并应在调用它的单元格中显示。
我可以在Google脚本编辑器中使用GAS Logger看到返回的信息,仅此而已。 如何将其输出到工作表,或者保存并导出此响应?
样本响应如下所示:
[[diy_move, forward_mail, update_account, renters_insurance, recommended_provider, utility, home_service, offer, share],
[forward_mail, update_account, utility, home_service, offer, share]]
// Get current row function getActiveRow() { var sheet = SpreadsheetApp.getActiveSpreadsheet(); var activeRow = sheet.getActiveCell().getRow(); return activeRow; } // call updater api function getSteps() { var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues(); var userIds = []; var sheet = SpreadsheetApp.getActiveSheet(); var ss = SpreadsheetApp.getActiveSpreadsheet(); var sss = ss.getSheets()[0]; var range = sheet.getRange(getActiveRow(), 1, 1, 1); var id = range.getValues(); function first(list) { return list[0]; } function getProperty(property) { return function (item) { return item[property]; } } var getCode = getProperty('code'); var userIds = values.map(first); var headers = { // auth "Content-Type": "application/json", "app": "company", "uid": "phong@updater.com", "client": "*****", "access-token": "*****" }; var options = { "method": "GET", "headers": headers //"muteHttpExceptions": true }; function callApi(id) { var url = "http://api.updater.com/v2/item_definitions?user_id=" + id; var response = UrlFetchApp.fetch(url, options) var json = response.getContentText(); var data = JSON.parse(json); return data.map(getCode); } function createSupersteps(ids) { return ids.map(callApi); } Logger.log(createSupersteps(userIds)); sss.appendRow(createSupersteps(userIds)); //createSupersteps(userIds) }
尝试将[]添加到sss.appendRow(createSupersteps(userIds));
使它成为sss.appendRow([createSupersteps(userIds)]);
。
基于文档样本代码appendRow(rowContents)
在电子表格上追加一行。 此操作是原子操作; 它可以防止出现以下问题:用户要求最后一行,然后写入该行,并且在获取最后一行并写入之前发生了中间的突变。
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Appends a new row with 3 columns to the bottom of the
// spreadsheet containing the values in the array
sheet.appendRow(["a man", "a plan", "panama"]);
这是我的示例代码:
function insert(){
var ss = SpreadsheetApp.openById('FILE_ID');
var sheet = ss.getSheets()[0];
var sample = "sample";
// Appends a new row with 3 columns to the bottom of the
// spreadsheet containing the values in the array
sheet.appendRow([sample]);
}
尝试使用sheet.appendRow(sample);添加; 给出一个错误
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.