'Google spreadsheet direct download link for only ONE sheet as excel

I was wondering if its possible to download say only sheet 1 of a google spreadsheet as excel? I have seen few SO posts that show the method to export the WHOLE sheet as excel, but I need to just export one sheet. Is it at all possible? and if yes, how?



Solution 1:[1]

From what I've found, the other two answers on this post are exactly correct, all you need to do is replace this:

/edit#gid=

with:

/export?format=xlsx&gid=

This works just fine although I did find that I had to keep looking up this string and copying it. Instead, I made a quick Javascript snippet that does all the work for you:

Just run the code snippet below and drag the link it creates into your bookmarks bar. I know this is a little hacky but for some reason, stackoverflow doesn't want me injecting javascript into the links I provide.

<a href="javascript:var%20winURL%20=%20window.location.href;if(winURL.indexOf('/edit#gid=')%20%3E%200)%7Bwindow.location.assign(winURL.replace('/edit#gid=',%20'/export?format=xlsx&gid='));%7Delse%7Balert('Incorrect%20URL%20format');%7D">Export Sheet as Excel</a>

I've tested this on the latest versions of Chrome, Safari, and Firefox. They all work although you might have to get a little creative about how you make your bookmarks.

Solution 2:[2]

when you see every Google spreadsheet url looks like this

https://docs.google.com/spreadsheets/d/1D5vzPaOJOx402RAEF41235qQTOs28_M51ee5glzPzj0/edit#gid=1078561300

In every spreadsheet URL we can see: /edit#gid=

this is generally the default mode.

/edit#gid=

just replace it with:

/export?format=xlsx&gid=

it will download the single spreadsheet from the workbook

Solution 3:[3]

I am able to download all sheets of a spreadsheet.

Just remove anything after

/edit?

and replace with

/export?format=xlsx 

for Excel

or

/export?format=pdf

for PDF

Solution 4:[4]

You can do this by clicking on the down arrow near the sheet name to bring up the options, and then selecting "Copy to -> New spread sheet", then click the "Open spread sheet" in the pop up that comes up after.

Solution 5:[5]

You can use my code:

function emailAsExcel() {
     var config =  {
     to: "[email protected]",
     subject: "your text",
     body: "your text" 
     };
     var ui = SpreadsheetApp.getUi();
     if (!config || !config.to || !config.subject || !config.body) {
         throw new Error('Configure "to", "subject" and "body" in an object as 
         the first parameter');
     };
     var spreadsheet   =  SpreadsheetApp.getActiveSpreadsheet();
     var spreadsheetId = spreadsheet.getId();
     var file = Drive.Files.get(spreadsheetId);
     var url = 'https://docs.google.com/spreadsheets/d/'+spreadsheetId+'/export? 
         format=xlsx&gid=numberSheetID to email';
     var token = ScriptApp.getOAuthToken();
     var response      = UrlFetchApp.fetch(url, {
         headers: {
         'Authorization': 'Bearer ' +  token
         };
     });

     var fileName = (config.fileName || spreadsheet.getName()) + '.xlsx';
     var blobs   = [response.getBlob().setName(fileName)];
     if (config.zip) {
         blobs = [Utilities.zip(blobs).setName(fileName + '.zip')];
     }

     GmailApp.sendEmail(
         config.to,
         config.subject,
         config.body,
         {
          attachments: blobs
         }
       );
    }

Solution 6:[6]

Please use any_value() function before the column because field(column) have more than one value for one id(group by). like- select any_value(phone_no) from user_details group by user_id. here one user_id have more than one phone number so query confused which choose.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dave Feldt
Solution 2 Javeed Shakeel
Solution 3 John Conde
Solution 4 Snippy Valson
Solution 5 SwissCodeMen
Solution 6 Santosh