Google-sheets – Export CSV from a Google Spreadsheet page from command-line

automationgoogle sheetslinux

I'm using a Google Spreadsheet document to configure a data-driven program.

The program consumes a CSV file, which now I have to export manually from the document. It is rather inconvenient, as everything else is automated.

I'd like to export the CSV file using a bash-script.

How do I do that?

Best Answer

Doing it from bash is very straightforward. All you need to do is run:

curl -s -d /dev/null https://docs.google.com/spreadsheets/d/DOCUMENT_ID/export?exportFormat=csv > mydocument.csv
dos2unix mydocument.csv 2> /dev/null

This only works for publicly shared documents though. To have access to private documents you will need to use OAuth2. You can find information about doing that here and then you can Google how to use OAuth2 with curl. (Because for the time being I can only post 1 URL at a time)