3
votes

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

3

3 Answers

7
votes

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

1
votes

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"

1
votes

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"