3

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...

user739711
  • 1,802
  • 1
  • 24
  • 30

4 Answers4

7

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

Johann8
  • 556
  • 6
  • 16
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"

Clotho
  • 56
  • 2
1

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"

Jack Simth
  • 93
  • 1
  • 7
0

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

Slawomir
  • 2,848
  • 1
  • 26
  • 34