Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

Download link for Google Spreadsheets CSV export - with Multiple Sheets

I'm trying to find a link which allows me to download a CSV formatted version of my Google Spreadsheet. Currently I'm using:

https://docs.google.com/spreadsheets/d/DOCID/export?format=csv

This works great except that it only download the first Sheet. My document has multiple sheets. Does anyone know how to format this link so that it downloads either all the sheets or a specific sheet? Something like:

&sheet=all

or

&sheet=3
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Every document in Google Sheets supports the "Chart Tools datasource protocol", which is explained (in a rather haphazard way) in these articles:

  1. "Creating a Chart from a Separate Spreadsheet"
  2. "Query Language Reference"
  3. "Implementing the Chart Tools Datasource Protocol"

To download a specific sheet as a CSV file, replace {key} with the document's ID and {sheet_name} with the name of the sheet to export:

https://docs.google.com/spreadsheets/d/{key}/gviz/tq?tqx=out:csv&sheet={sheet_name}

The datasource protocol is quite flexible. Various other options include:

Response Format: Options include tqx=out:csv (CSV format), tqx=out:html (HTML table), and tqx=out:json (JSON data).

Export part of a sheet: Supply the range={range} option, where the range can be any valid range specifier, e.g. A1:C99 or B2:F.

Execute a SQL query: Supply the tq={query} option, such as tq=SELECT a, b, (d+e)*2 WHERE c < 100 AND x = 'yes'.

Export textual data: Supply the headers=0 option in case your fields contain textual data, otherwise they might be cut out during export.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...