Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download unpublished Google spreadsheet as CSV

Tags:

I have a Google spreadsheet that has not been made public, but just available to anyone that has the access link. Though I can access the data in CSV format from my browser even when I am not logged into my Google account (that is, anonymous access is allowed), there is no way I can download the data from the command line using wget, for instante. I have found several web pages with some instructions to create the download URL, but so far I've had no success. Is there an easy, straightforward way of doing this or will I have to use some Google Data library to access that data?

like image 372
José María Mateos Avatar asked May 24 '12 03:05

José María Mateos


People also ask

Can you download a Google Sheet as a CSV?

Open your Sheets file. Click the File tab. Choose Download. Select the Comma-separated values (CSV) option.

How do I download multiple Google Sheets as CSV?

I. There is a Google Drive option that enables you to select and download all desired files at once. Just log into your Google Drive account and select all the sheet files that you want to export to PC. Then click on more options in the top menu and select export.


1 Answers

Maybe I'm not correctly understanding what you're trying to do, but I found a solution in this article that works just fine for me.

In the article, the author creates a download link for the spreadsheet as an XLS file (using "&output=xls”), but I tried "&output=csv" and successfully downloaded a correct CSV file.

Here's the download link to my "Download Test Spreadsheet", constructed just the way the author of the article suggested, but with "csv" substituted for "xls":

https://docs.google.com/spreadsheet/ccc?key=0At2sqNEgxTf3dEt5SXBTemZZM1gzQy1vLVFNRnludHc&output=csv

The link is anonymous (i.e., "Anyone who has the link can view"), and I downloaded it without logging into my Google account. I'll admit that I didn't use wget to do it (I just used a browser -- I didn't have wget installed), but I can't think of a reason that wget wouldn't work just as well.

Actually, I just grabbed a copy of wget and tried it, and it downloads the file correctly too:

% wget --no-check-certificate --output-document=test.csv 'https://docs.google.com/spreadsheet/ccc?key=0At2sqNEgxTf3dEt5SXBTemZZM1gzQy1vLVFNRnludHc&output=csv'  < bla bla bla, reams of output from wget >  % cat test.csv Foo,Bar,Baz 1,2,3 4,5,6 

So there ya go...


UPDATING FOR 2018

As commented by @AndyMortimer, the new download URL is
  https://docs.google.com/spreadsheets/d/<KEY>/export?gid=<GID>&format=csv
where <KEY> and <GID> can be obtained from your navigation's URL,
  https://docs.google.com/spreadsheets/d/<KEY>/edit#gid=<GID>

PS: spreadsheets may have multiple workbooks, GID is the desired workbook ID. One-workbook-spreadsheet usually has gid=0, but if you add more they'll have random numbers (the GID is preseved even changing tab-order).

So, using wget and the same spreadsheet,

   wget --no-check-certificate -O test.csv \     'https://docs.google.com/spreadsheets/d/0At2sqNEgxTf3dEt5SXBTemZZM1gzQy1vLVFNRnludHc/export?gid=0&format=csv' 
like image 72
Hephaestus Avatar answered Sep 20 '22 22:09

Hephaestus