Download Google Sheets CSV with cURL


This post goes over how to export and download Google Sheets spreadsheet as a CSV with cURL.

Prerequisites

Create a Google Sheets spreadsheet and change the Share access to Anyone with the link.

Copy the link, which should look something like:

https://docs.google.com/spreadsheets/d/ABCDEF123456/edit?usp=sharing

Export

Following this Stackoverflow answer, the link should be changed from:

https://docs.google.com/spreadsheets/d/<SHEET_ID>/edit?usp=sharing

To:

https://docs.google.com/spreadsheets/d/<SHEET_ID>/export?exportFormat=csv

See diff:

-https://docs.google.com/spreadsheets/d/<SHEET_ID>/edit?usp=sharing
+https://docs.google.com/spreadsheets/d/<SHEET_ID>/export?exportFormat=csv

Make sure to replace the <SHEET_ID> with the Google Sheets spreadsheet ID.

Then download the spreadsheet using cURL:

curl -L "https://docs.google.com/spreadsheets/d/<SHEET_ID>/export?exportFormat=csv" -o my_sheet.csv

Example

Given a public Google Sheets spreadsheet:

https://docs.google.com/spreadsheets/d/1OiuuC_WrDCRfhnYX9i9BJ75-F0frFuSkAIYOgf-Qf6I/edit?usp=sharing

Export and download the CSV with the Bash commands:

SHEET_ID='1OiuuC_WrDCRfhnYX9i9BJ75-F0frFuSkAIYOgf-Qf6I'
URL="https://docs.google.com/spreadsheets/d/$SHEET_ID/export?exportFormat=csv"
curl -L $URL -o my_sheet.csv

Replit:



Please support this site and join our Discord!