4

I want to download one of my google spreadsheet using curl and save it as a .csv file. Following is the command I am using:

(curl --silent --header "Authorization: GoogleLogin auth=AUTH_KEY" https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=SPREADSHEET_KEY&exportFormat=csv) > a.csv

This is downloading a file which is in pdf format. Can anybody help me in resolving this issue I am stuck with for 1 hr...

4 Answers 4

8

This works: curl 'https://docs.google.com/spreadsheets/d/<yourkey>/export?exportFormat=csv', with adequate link-sharing parameters.

3

As of 6/3/2023, the steps are:

In Google Sheet, click the Share button, then Get Link.

Edit the link from:

https://docs.google.com/spreadsheets/d/<LONG-UGLY-CODE>/edit?usp=sharing

To:

https://docs.google.com/spreadsheets/d/<LONG-UGLY-CODE>/export?exportFormat=csv

*) Replace: <LONG-UGLY-CODE> with your code.

Curl the link, -L will follow temporary redirects:

curl -L 'https://docs.google.com/spreadsheets/d/<LONG-UGLY-CODE>/export?exportFormat=csv' -o my_sheet.csv

2
  • 2
    if you need to get only one sheet from multi-sheet file, add &gid=nnnnnnnn to the query so it would be .../export?gid=123456789&exportFormat=csv ... Gid number is displayed in the URL if you browse your sheets. Jul 6, 2022 at 14:57
  • 1
    if you need to get contents of only one cell add &range=A2 to the URL, referring to your required range. Jul 6, 2022 at 15:07
2

You need quotes. Without them, the & breaks the command into a background process and a foreground process - at which point, the exportFormat=csvsets a variable in your bash shell named exportFormat with a value of csv; the exportFormat doesn't go to the google page, so it spits it out in the default format, pdf: Which isn't what you want. Try: curl --silent -o a.csv--header "Authorization: GoogleLogin auth=AUTH_KEY" "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=SPREADSHEET_KEY&exportFormat=csv"

1

Try to add "&hl" and quotes

ie. curl --silent --header "Authorization: GoogleLogin auth=AUTH_KEY" "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=SPREADSHEET_KEY&hl&exportFormat=csv"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.