> ## Documentation Index
> Fetch the complete documentation index at: https://docs.doconda.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate an Excel file with formulas from an LLM

> How to generate an Excel (.xlsx) file with real formulas from an LLM, without pasted values or errors like #REF! or #DIV/0!.

To generate an Excel file with formulas from an LLM, describe the sheet in a sentence and ask Doconda for
`format="xlsx"`. You get an `.xlsx` with real formulas (not pasted numbers), the assumptions in their own cells and
every formula recalculated and checked before it is delivered, plus its PDF.

## The problem in practice

* The model tends to write the already computed result: the sheet looks right but doesn't update when a value changes.
* The formulas it writes can point at the wrong cells and end up as `#REF!` or `#DIV/0!`.
* When the file is built with code, formulas aren't calculated until someone opens it, so errors go unnoticed.
* Newer functions like `XLOOKUP` or `FILTER` don't work in every version of Excel.

## The solution with Doconda

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  from pathlib import Path
  from doconda import Doconda

  doconda = Doconda()  # reads the key from DOCONDA_API_KEY
  doc = doconda.documents.create(
      format="xlsx",
      prompt="12-month revenue forecast: 1,000 customers at the start, 5% monthly growth and €20 per customer",
  )
  Path("forecast.xlsx").write_bytes(doconda.documents.download(doc["id"], "xlsx"))
  ```

  ```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  import { writeFile } from "node:fs/promises"
  import { Doconda } from "@doconda/sdk"

  const doconda = new Doconda()
  const doc = await doconda.documents.create({
    format: "xlsx",
    prompt: "12-month revenue forecast: 1,000 customers at the start, 5% monthly growth and €20 per customer",
  })
  await writeFile("forecast.xlsx", await doconda.documents.download(doc.id, "xlsx"))
  ```
</CodeGroup>

If your data is in a file, upload it with `doconda.files.upload("sales.xlsx")` and pass it in `sources`.

## What you get back

* An `.xlsx` with formulas: change an assumption and the sheet recalculates. Its PDF too.
* `status`: `ready`, `ready_with_warnings`, `needs_review` or `failed` (not charged).
* A report (`documents.report(id)`). Figures that don't come from your request or your sources are removed or flagged
  for you to check.

## FAQ

<AccordionGroup>
  <Accordion title="How do I make ChatGPT create an Excel file with formulas instead of values?">
    On its own the model returns text or computed values. With `documents.create(format="xlsx", prompt=...)` Doconda
    builds the file with formulas and checks that none of them errors before delivering it.
  </Accordion>

  <Accordion title="How do I avoid #REF! and #DIV/0! errors in an AI-generated Excel file?">
    Doconda recalculates every formula until no error is left. For an Excel file you already have, review it with
    `operation="review"`: formulas with errors and broken references show up in the report.
  </Accordion>

  <Accordion title="Can I review an Excel file I already have?">
    Yes. Upload it with `files.upload` and call `documents.create(operation="review", file=...)`. Among other things it
    detects numbers stored as text and sheets too wide to print. See [Review](/en/guides/review).
  </Accordion>
</AccordionGroup>

## Keep reading

* [Create](/en/guides/create): formats, sources and quality levels.
* [Review](/en/guides/review): the list of issues detected in Excel.
* [Python SDK](/en/sdk/python) and [TypeScript SDK](/en/sdk/introduction).
* [Doconda in your agent](/en/agents/introduction).
* [Examples on GitHub](https://github.com/B-C-Software/doconda-examples).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.