简体   繁体   English

Google 表格 - Json 到表格

[英]Google sheets - Json to Sheet

I'm using this Google App script我正在使用这个 Google App 脚本

   // Reference: https://www.labnol.org/code/20068-blogger-api-with-google-apps-script

function bloggerAPI() {

      var api = "https://www.googleapis.com/blogger/v3/users/self/blogs";

      var headers = {
        "Authorization": "Bearer " + getService().getAccessToken()
      };

      var options = {
        "headers": headers,
        "method" : "GET",
        "muteHttpExceptions": true
      };

      var response = UrlFetchApp.fetch(api, options);

      var json = JSON.parse(response.getContentText());

      for (var i in json.items) {
        Logger.log("[%s] %s %s", json.items[i].id, json.items[i].name, json.items[i].url);
      }
    }

How can I import the values that are in the Logger.log into my sheet.如何将 Logger.log 中的值导入到我的工作表中。

You have to change the Logger.log() for appendRow() .您必须更改appendRow()的 Logger.log () In your case you have to set the sheet you want to insert the values:在您的情况下,您必须设置要插入值的工作表:

var ss = SpreadsheetApp.getActiveSpreadsheet();  // Gets the Active Spreadsheet
var ss = SpreadsheetApp.openById("ID OF THE SPREADSHEET"); // Alternative way of getting a Spreadsheet

var sheet = ss.getSheets()[0]; // Gets the first sheet
var sheet = ss.getSheets().getSheetByName("Sheet4"); // Gets the sheet with the name Sheet4

Once you have the Spreadsheet you want, inside the for loop, you insert the values:获得所需的电子表格后,在 for 循环中插入值:

sheet.appendRow([json.items[i].id, json.items[i].name, json.items[i].url]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM