首页 文章

使用Google Apps脚本将Google电子表格导出为JSON(或XML)格式

提问于
浏览
0

我正在尝试使用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 .

非常感谢,

1 回答

  • 1

    在JSON的情况下,您可以通过将脚本上方的返回部分更改为以下代码来获得它 .

    return ContentService.createTextOutput(JSON.stringify(title)).setMimeType(ContentService.MimeType.JSON);
    

相关问题