Home > Net >  Download Google Sheet to .xlsx Format using Link - multiple tabs
Download Google Sheet to .xlsx Format using Link - multiple tabs

Time:02-22

I need using the link to download the Google Sheet to .xlxs format. This is works for me. but it is for single tab only, the thing is I have to download three or more tabs. I believe the format of "gid" would be different.

https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=1eVcHMWyH1YIDN_i0iMcv468c4_jnPk9Tw5gea-2FCyk&gid=626501804&exportFormat=xlsx

CodePudding user response:

I believe your goal is as follows.

  • You want to export a Google Spreadsheet in XLSX format.
  • You want to include several specific Sheets in the Google Spreadsheet.

In this case, how about the following workaround? In this workaround, a Google Spreadsheet including the several sheets you want to include is created as a temporal Spreadsheet. In this case, as a simple method, Google Apps Script is used for retrieving the URL.

Sample script:

function sample() {
  const exportSheetNames = ["Sheet1", "Sheet2", "Sheet3"]; // Please set the sheet names you want to export.
  const spreadsheetId = "###"; // Please set your Spreadsheet ID.

  const source = SpreadsheetApp.openById(spreadsheetId);
  const temp = source.copy("temp_"   source.getName());
  temp.getSheets().forEach(s => {
    if (!exportSheetNames.includes(s.getSheetName())) temp.deleteSheet(s);
  });
  const url = `https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=${temp.getId()}&exportFormat=xlsx`;
  console.log(url);
}
  • When this script is run, you can see the URL for exporting the Spreadsheet in XLSX format including the specific sheets you want at the log. From your question, I thought that you might want the URL for exporting.

  • This is a simple sample script for achieving your goal. For example, if you want to automatically export the XLSX file using a script, you can see the sample script at this thread.

  • Related