30

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?

Rubén
  • 34,714
  • 9
  • 70
  • 166
rahulserver
  • 10,411
  • 24
  • 90
  • 164
  • It has been a while but how about if you want to use a different filename for the tab it exports instead of using the name of the spreadsheet? – Jay Mar 04 '22 at 23:59

7 Answers7

60

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

Rubén
  • 34,714
  • 9
  • 70
  • 166
Elijah Lynn
  • 12,272
  • 10
  • 61
  • 91
  • 2
    Does EXACTLY what I need. I am sure this will help other users as well. Thanks man! – rahulserver Apr 04 '16 at 17:37
  • 2
    Nice, yeah, I just had the exact same issue earlier today. Google should make this an option by default. We could write a Chrome extension that hijacks their "Download as" menu and adds another option "Download as (sheet)"... – Elijah Lynn Apr 04 '16 at 17:58
  • 1
    don't sue me if I steal your idea and publish this kind of extension on chrome webstore :p – rahulserver Apr 05 '16 at 09:52
  • That is exactly why I posted it, hoping someone would! It would be nice if it was in Github or Bitbucket etc. though ;). – Elijah Lynn Apr 05 '16 at 15:43
  • We should see if a Google Spreadsheet Add-on might be a good fit too. – Elijah Lynn Apr 05 '16 at 15:44
  • The sheet's GID might be missing from the URL, so you can right click on the sheet's tab name and choose Inspect from the context menu. The Developer Tools will open up and you'll be able to see that tab's ID - id="sheet-button-1282911344", this number is the GUID, so your download URL will be something like - `https://docs.google.com/spreadsheets/d/[ID]/export?gid=1282911344&format=csv` - also export it as CSV if you want. – simo Jun 23 '17 at 06:39
  • @ElijahLynn Any idea of how to achieve the same for say 2 sheets, so that as a result we have a file with two sheets. Suppose you have spreadsheet with 5 sheets, you need only two. Surely will need a function is GAS ...Just cannot get this to work ... – AlexShevyakov Mar 11 '19 at 07:40
  • That would be tough with the method mentioned above as it would require tarring/zipping them up into an archive file. Short of creating a web service with a Lambda function I am not sure how to do this with existing Google Apps functionality. This doesn't mean there isn't a way though... – Elijah Lynn Mar 11 '19 at 15:58
10

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.

Dave Feldt
  • 101
  • 1
  • 3
6

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

Javeed Shakeel
  • 2,926
  • 2
  • 31
  • 40
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

John Conde
  • 217,595
  • 99
  • 455
  • 496
Mayur Patil
  • 139
  • 2
  • 5
0

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.

Santosh
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 06 '22 at 15:31
-1

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.

Snippy Valson
  • 231
  • 3
  • 9
-1

You can use my code:

function emailAsExcel() {
     var config =  {
     to: "name@gmail.com",
     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
         }
       );
    }
SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34