Export a caller-provided Google Sheet as an XLSX artifact or read worksheet tables without modifying the source sheet.
Use Cases
Use when the caller supplies a Google Sheets URL or ID and needs workbook data for downstream processing or model preparation.
Automation Flow
- Read the opaque spreadsheet ID from
/spreadsheets/d/{spreadsheet-id}/in the supplied URL. Never fabricate an ID. - Navigate directly to
https://docs.google.com/spreadsheets/d/{spreadsheet-id}/export?format=xlsx. Capture the resulting download artifact or browser download metadata, including any handle needed by a subsequent step. No DOM extraction or editor interaction is needed. - If another format is requested, use
export?format={format}only when the site supports it. - For worksheet reads instead of a workbook download, use
/spreadsheets/d/{spreadsheet-id}/htmlviewto discover tab labels and#gid={number}links. Use only caller-provided or observed tab names; never guess them. From a loadeddocs.google.compage in the authenticated profile, fetch multiple known tabs in one evaluation. Replace{spreadsheet-id-json}with a JSON string literal and{sheet-names-json}with a JSON array of tab-name strings, including their quotes:
(async () => { const id = {spreadsheet-id-json}, sheets = {sheet-names-json}, results = []; for (const sheet of sheets) { const url = `https://docs.google.com/spreadsheets/d/${encodeURIComponent(id)}/gviz/tq?tqx=out:html&sheet=${encodeURIComponent(sheet)}`; const r = await fetch(url, {credentials: 'include'}); results.push({sheet, ok: r.ok, status: r.status, contentType: r.headers.get('content-type'), text: await r.text()}); } return results; })()- Validate each tab response independently: require a successful status and actual worksheet table content, not a sign-in, access-denied, or error page. Keep failed or empty tabs unresolved rather than treating them as empty worksheets. Use
tqx=out:csvinstead when CSV is requested.
Possible Friction Points
- The export endpoint triggers a browser download rather than an HTML page. Preserve the download handle for downstream use.
- The source sheet remains unchanged. An authenticated browser profile may be needed for access.
- Same-origin gviz fetches use the existing browser session; HTML error or sign-in content can arrive even with HTTP 200, so status alone does not establish a successful worksheet read.
Example Result
[
{
"sheet": "Example Sheet",
"ok": true,
"status": 200,
"contentType": "text/html",
"text": "<html>…</html>"
}
]