How to export Google Spreadsheets as Excel format using Apps Script

I’m trying to figure out how to export Google Sheets files to Excel (.xls) format using Google Apps Script. I’ve been struggling with this for a while and can’t seem to get it working properly.

I tried different approaches including using Blobs but most files end up being converted to PDF format instead of Excel. Does anyone know the correct way to do this conversion?

Here’s my current attempt but it’s not working as expected:

function convertToExcel() {
  var allSheets = DocsList.getFilesByType('spreadsheet');
  for(var j = 0; j < allSheets.length; j++){
    var currentFile = allSheets[j];
    var sourceSpreadsheet = SpreadsheetApp.open(currentFile);
    var activeWorksheet = sourceSpreadsheet.getActiveSheet();
    var excelFile = SpreadsheetApp.create(currentFile.getName() + ".xls");
    excelFile.setActiveSheet(activeWorksheet);
  }
}

Any help would be appreciated!

Apps Script exports suck when you’re doing them regularly. Had the same headache when our finance team wanted weekly Excel files from multiple Google Sheets.

You’re basically trapped in Google’s ecosystem trying to force manual exports. Why not set it up once and forget about it?

I automated our whole Google Sheets to Excel process with Latenode. It monitors sheets for changes, converts to proper Excel format, and sends files wherever - email, cloud storage, you name it.

No more Apps Script quota fights or auth token nightmares. No manual export URLs or blob conversion hell. Build the workflow once and it runs itself.

It pulls data from Google Sheets, makes real Excel files, and delivers on schedule or triggers. Takes 10 minutes to set up instead of hours debugging Apps Script.

Why code when you can automate everything? Check out https://latenode.com

hey isaac, you’re using the old DocsList API - that’s been deprecated for years. switch to DriveApp.getFiles() and export with the right mimetype. try file.getBlob().setContentType('application/vnd.ms-excel') instead of creating new spreadsheets.

Yeah, this is super common with Google Apps Script exports. Don’t create new spreadsheet files - use the Drive API export calls instead. I hit the same wall when I started.

Here’s what actually works: Use Utilities.newBlob() with the right export parameters. Grab the spreadsheet data with a GET request to the export endpoint, but you’ve got to authenticate properly with getOAuthToken().

The trick is getting your format parameter right in the URL - ‘xlsx’ for modern Excel or ‘xls’ for the old format. Your current code is making Google Sheets files, not actual Excel exports.

Skip the DocsList API (it’s dead anyway) and stick with DriveApp. Start with one sheet to test before you process multiple files - trust me, you don’t want to hit those quota limits.

hey isaac, that code’s outdated - docslist got deprecated years ago. use driveapp.getFilesByType() instead, then hit the export url with format=xlsx. way better than creating new sheets.

The problem is you’re using SpreadsheetApp.create() - that just makes another Google Sheets file, not an actual Excel export. I hit this same issue last year building automated reports. You need to hit the Drive API export endpoint directly. Build the export URL yourself and fetch the blob with proper auth. This approach works consistently:

function exportAsExcel() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var exportUrl = 'https://docs.google.com/spreadsheets/d/' + ss.getId() + '/export?format=xlsx&gid=0';
  var token = ScriptApp.getOAuthToken();
  var response = UrlFetchApp.fetch(exportUrl, {
    headers: {'Authorization': 'Bearer ' + token}
  });
  var blob = response.getBlob().setName(ss.getName() + '.xlsx');
  DriveApp.createFile(blob);
}

Don’t forget to enable the Drive API in your script project settings. The trick is using the export endpoint with the format parameter instead of messing with spreadsheet objects directly.

Your code’s creating new Google Sheets instead of actually exporting to Excel. You need the Drive API’s export function with the right MIME type. Here’s how to fix it:

function exportToExcel() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var file = DriveApp.getFileById(spreadsheet.getId());
  var blob = file.getBlob();
  
  // Export as Excel format
  var url = 'https://docs.google.com/spreadsheets/d/' + spreadsheet.getId() + '/export?format=xlsx';
  var response = UrlFetchApp.fetch(url, {
    headers: {
      'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()
    }
  });
  
  DriveApp.createFile(response.getBlob().setName(spreadsheet.getName() + '.xlsx'));
}

This uses the export URL with xlsx format - actually converts your Google Sheet to Excel instead of making another Google Sheet file.