Import and export files with the spreadsheet API
What it does
Section titled “What it does”Import CSV or XLSX into one sheet and export an A1 range as a file. The server saves each job before returning 202. Only succeeded confirms that the import was written or the export is ready.
How to use it
Section titled “How to use it”Use the sheet ID from GET /workbook. Import requires Edit cells, and export requires Read.
| Method | Inputs |
|---|---|
POST /sheets/{sheetId}/imports |
Query format=csv or xlsx, range=A1 or a rectangle, header Idempotency-Key, raw file bytes, optional If-Match: "42" |
POST /sheets/{sheetId}/exports |
JSON format, range, idempotencyKey, optional revision |
GET /jobs/{jobId} |
Job ID from the 202 response |
GET /jobs/{jobId}/file |
ID of a successful export |
Poll the job about every two seconds. queued and running are pending states. A successful result has revision, range, and cells for imports or size in bytes for exports. A failed job has an error code.
Behavior and limits
Section titled “Behavior and limits”- CSV defaults to UTF-8 and comma. Choose
encoding=windows-1251orgb18030anddelimiter=comma,semicolon,tab, orpipe. Spreadsheet number and date parsing applies. Formula-like input text remains text. - XLSX takes one visible sheet.
formulas=preserverequiresrange=A1and a write key for all sheets. It supports references within the incoming rectangle and the basic functionsSUM,AVERAGE,MIN,MAX,COUNT,COUNTA,IF,IFERROR,AND,OR,NOT,ABS, andROUND. External references and unsupported formulas fail the job. Values and supported formulas are imported. Styles, images, names and validation rules are omitted. - Exports contain computed values. CSV is UTF-8 with commas and prefixes formula-like text with an apostrophe. XLSX stores that text unchanged as a string. Formulas, links and images are excluded.
- Up to 1 MiB uploaded, 8 MiB expanded XLSX, 256 ZIP entries, 10,000 written positions, and 50,000 positions or 8 MiB exported. Import commits in one revision and honors protection, validation and workbook limits.
- Jobs expire after 24 hours. The original key must still have access. Pending limits are 2 per key, 8 per organization, and 64 overall. Retained limits are 24, 64, and 256 respectively. Up to two jobs run at once across the server pool.
Errors and recovery
Section titled “Errors and recovery”Replay the same bytes, options, revision condition and idempotency key to find the current state after a lost submission response. Use a new key for a changed request. 409 or 412 revision_conflict means reread the revision. If the revision changed after 202, the job fails and includes the current revision in result. For 409 job_not_ready, check status. Follow Retry-After on 429 or 503.
