0

這是將JSON數據拖入Google表格的Google Apps腳本。無權調用setValues() - Google Apps腳本,JSON數據

的代碼是:

function pullJSON() { 

    var url="https://api.myjson.com/bins/4610d"; // publicly available json 

    var response = UrlFetchApp.fetch(url); // 
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1"); 

    var dataAll = JSON.parse(response.getContentText()); 
    var dataSet = dataAll; 

    var rows = [], 
     data; 

    for (i = 0; i < Object.keys(dataSet).length; i++) { 
    data = dataSet[Object.keys(dataSet)[i]]; 
    rows.push([data.name]); //JSON entities here 
    } 

    dataRange = sheet.getRange(1, 1, rows.length, 1); 
    dataRange.setValues(rows); 
} 

在谷歌表格,我通過輸入= pullJSON()插入細胞調用的函數。它顯示錯誤:

「您沒有權限調用setValues(第20行)」,它引用行:dataRange.setValues(rows);

並在單元格A1,A2,A3中產生「未定義」結果。

JSON數據源很簡單:

{"id":1,"name":"A green door","price":12.5} 

做這些的目的是爲了能夠將JSON數據轉換成表形式在谷歌片材。

大部分上面的密切關注此主題的內容: "The coordinates or dimensions of the range are invalid" - Google Apps Script and JSON Data

將是任何指導,非常感謝在這個問題上,請。

回答

4

A custom function cannot affect cells other than those it returns a value to. In other words, a custom function cannot edit arbitrary cells, only the cells it is called from and their adjacent cells. To edit arbitrary cells, use a custom menu to run a function instead.

從文檔:https://developers.google.com/apps-script/guides/sheets/functions

我不知道您的具體使用情況,但它看起來將有可能從一個自定義菜單運行功能。