Converting google spreadsheet to XLSX or ODS using GAS

后端 未结 1 1495
攒了一身酷
攒了一身酷 2020-12-20 05:28

I want to convert a few google spreadsheets to Excel (xlsx preferred).
I\'ve read several threads about how to achieve this, but I can\'t get it running.
Amongst the

相关标签:
1条回答
  • You can use the Advanced Drive Service to get the export URL and use the script's OAuth2 token to download the file.

    function exportAsExcel(spreadsheetId) {
      var file = Drive.Files.get(spreadsheetId);
      var url = file.exportLinks['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
      var token = ScriptApp.getOAuthToken();
      var response = UrlFetchApp.fetch(url, {
        headers: {
          'Authorization': 'Bearer ' +  token
        }
      });
      return response.getBlob();
    }
    
    function test() {
      var spreadsheetId = 'SPREADSHEET ID HERE';
      DriveApp.createFile(exportAsExcel(spreadsheetId));
    }
    
    0 讨论(0)
提交回复
热议问题