# Excel and CSV

> Get the result as a file in the same response, for no extra credits.

Page: https://doxtract.manoonlabs.com/docs/api/export

Add `export=xlsx` or `export=csv` to a parse, as a form field or a JSON key. The response is the same JSON plus an `export` object with the file as base64.

**Excel**

```bash
curl -s -X POST https://doxtract.manoonlabs.com/api/v1/parse \
  -H "Authorization: Bearer mldxt_..." \
  -F file=@invoice.pdf \
  -F schema=invoice \
  -F export=xlsx \
| jq -r '.export.content' | base64 -d > invoice.xlsx
```

**CSV**

```bash
curl -s -X POST https://doxtract.manoonlabs.com/api/v1/parse \
  -H "Authorization: Bearer mldxt_..." \
  -F file=@invoice.pdf \
  -F schema=invoice \
  -F export=csv \
| jq -r '.export.content' | base64 -d > invoice.csv
```

**TypeScript**

```ts
import { readFile, writeFile } from "node:fs/promises";

const form = new FormData();
form.append("file", new Blob([await readFile("invoice.pdf")]), "invoice.pdf");
form.append("schema", "invoice");
form.append("export", "xlsx");

const res = await fetch("https://doxtract.manoonlabs.com/api/v1/parse", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.DOXTRACT_KEY}` },
  body: form,
});
const body = await res.json();
if (body.status !== "ok") throw new Error(body.message);

console.log(body.values.total); // the JSON is still here
await writeFile(body.export.filename, Buffer.from(body.export.content, "base64"));
```

**Python**

```python
import base64, os, requests

with open("invoice.pdf", "rb") as f:
    res = requests.post(
        "https://doxtract.manoonlabs.com/api/v1/parse",
        headers={"Authorization": f"Bearer {os.environ['DOXTRACT_KEY']}"},
        files={"file": f},
        data={"schema": "invoice", "export": "xlsx"},
    )
body = res.json()
if body["status"] != "ok":
    raise RuntimeError(body["message"])

print(body["values"]["total"])  # the JSON is still here
with open(body["export"]["filename"], "wb") as out:
    out.write(base64.b64decode(body["export"]["content"]))
```

**Response**

```json
{
  "status": "ok",
  "credits_used": 1,
  "credits_remaining": 59,
  "values": {
    "vendor": "Northwind Supply",
    "invoiceNumber": "INV-1042",
    "issued": "2026-10-25",
    "total": 1280.5,
    "currency": "USD",
    "lineItems": [
      {
        "description": "Cable",
        "amount": 1280.5
      }
    ]
  },
  "export": {
    "format": "xlsx",
    "filename": "invoice-2026-10-26.xlsx",
    "contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    "content": "UEsDBBQABgAIAAAAIQ..."
  }
}
```

**export object**

| Key | Type | Required | Description |
| --- | --- | --- | --- |
| `export.format` | "xlsx" \| "csv" | Always | The export value you sent. |
| `export.filename` | string | Always | A suggested name, <name>-<yyyy-mm-dd>.<ext> in UTC. The name is the document name (filename, else the uploaded file name), else the saved schema name, else "doxtract". |
| `export.contentType` | string | Always | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet for xlsx, text/csv; charset=utf-8 for csv. |
| `export.content` | string | Always | The file bytes as standard base64. Decode and write them to disk. |

## Excel (.xlsx)

- The Document sheet has one row: a document column, then every top-level key.
- Nested objects become dotted columns, for example vendor.address.city.
- Each list of objects gets its own sheet, named after its path (lineItems, or lineItems.taxes for a list inside a list). Its first columns tie each row back: document, then a row number per level ("lineItems #").
- document is the document name: filename, else the uploaded file name, else 1.
- Numbers and dates (yyyy-mm-dd) are real number and date cells. true and false stay booleans. Lists of plain values are joined with "; ". Headers are bold and frozen.

## CSV (.csv)

- One row per item of the largest list in the result, usually the line items. Its columns are prefixed with its path, for example lineItems.amount.
- Every other key is repeated on each row, so the file stands on its own in a spreadsheet or a database import.
- A result with no lists is a single row. Other lists of objects, including lists inside a line item, are written into one cell as JSON. Excel has every list as its own sheet.
- UTF-8 with a byte order mark, so Excel shows accents and currency symbols correctly. Lines end with CRLF. Text that starts with =, +, -, or @ gets a leading apostrophe, so it is not run as a formula.

## Sample output

**Excel**

```text
Document sheet
document    | vendor           | invoiceNumber | issued     | total  | currency
------------|------------------|---------------|------------|--------|---------
invoice.pdf | Northwind Supply | INV-1042      | 2026-10-25 | 1280.5 | USD

lineItems sheet
document    | lineItems # | description | amount
------------|-------------|-------------|-------
invoice.pdf | 1           | Cable       | 1280.5
```

**CSV**

```text
vendor,invoiceNumber,issued,total,currency,lineItems.description,lineItems.amount
Northwind Supply,INV-1042,2026-10-25,1280.5,USD,Cable,1280.5
```

## Notes

- The JSON is always in the response. export only adds the file next to it, from the same parse, for the same credits.
- A failed parse never has export. Check status first.
- If the file cannot be built, the response is the plain JSON without export. The parse itself still counts.
- MCP's parse_document returns JSON only. The Playground has a Download menu for Excel and CSV.
