我尝试使用Google Apps脚本将Google电子表格导出为JSON(或XML)。这是我的谷歌表:
https://docs.google.com/spreadsheets/d/15fwOeR6Jo4UadzOTlryTucgI3ZFZ5IVM16GDSwA0XE0/edit?usp=sharing
这是我的谷歌应用脚本代码:
function doGet() {
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/15fwOeR6Jo4UadzOTlryTucgI3ZFZ5IVM16GDSwA0XE0/edit#gid=0');
SpreadsheetApp.setActiveSpreadsheet(ss);
SpreadsheetApp.setActiveSheet(ss.getSheets()[0]);
var title = ss.getSheets()[0].getRange("A1:A3").getValues();
var link = ss.getSheets()[0].getRange("B1:B3").getValues();
return ContentService.createTextOutput(title).setMimeType(ContentService.MimeType.XML);
}
但是,部署它时我没有获得任何JSON。
非常感谢,
答案 0 :(得分:1)
对于JSON,您可以通过将脚本上方的返回部分更改为以下代码来获得它。
return ContentService.createTextOutput(JSON.stringify(title)).setMimeType(ContentService.MimeType.JSON);