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
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));
}