rahulserver
rahulserver

Reputation: 11205

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?

Upvotes: 36

Views: 89903

Answers (7)

Elijah Lynn
Elijah Lynn

Reputation: 13468

You can download a specific sheet using the 'GID'.

Each sheet has a GID, you can find GID of specific sheet in the URL of spreadsheet. Then you can use this link to download specific sheet -

https://docs.google.com/spreadsheets/d/<KEY>/export?format=xlsx&gid=<GID>

ex: https://docs.google.com/spreadsheets/d/1D5vzPaOJOx402RAEF41235qQTOs28_M51ee5glzPzj0/export?format=xlsx&gid=1990092150

KEY is the unique ID of the spreadsheet.

source: https://www.quora.com/How-do-I-download-just-one-sheet-from-google-spreadsheet/answer/Ranjith-Kumar-339?srid=2YCg

Upvotes: 81

Santosh
Santosh

Reputation: 1

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.

Upvotes: 0

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

Upvotes: -1

Snippy Valson
Snippy Valson

Reputation: 361

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.

Upvotes: -1

Mayur Patil
Mayur Patil

Reputation: 159

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

Upvotes: 3

Dave Feldt
Dave Feldt

Reputation: 131

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.

Upvotes: 13

Javeed Shakeel
Javeed Shakeel

Reputation: 3417

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

Upvotes: 6

Related Questions