# Google Sheets Analysis

Reads, analyzes, and edits Google Sheets via the Sheets API.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).



<DocsBaseSwitcher base="mastra" agent="google-sheets" />

<AgentPreview
  agent="google-sheets"
  framework="mastra"
  inputFields="[
  {
    name: &#x22;spreadsheetId&#x22;,
    label: &#x22;Spreadsheet ID&#x22;,
    placeholder: &#x22;1A2b3C4d5E6f7G8h9I0j…&#x22;,
    type: &#x22;text&#x22;,
  },
  {
    name: &#x22;request&#x22;,
    label: &#x22;Request&#x22;,
    placeholder: &#x22;Total revenue by region and write it to F1.&#x22;,
    type: &#x22;text&#x22;,
  },
]"
/>

## Summary [#summary]

The **Google Sheets Analysis Agent** reads a spreadsheet, answers questions about
it, and — on request — writes results back. It loads ranges in A1 notation,
computes totals/trends/joins, and updates cells only when you ask. Reach for it to
turn a sheet into a conversational analyst or to automate routine spreadsheet
edits.

## Installation [#installation]

<CodeTabs>
  <TabsList>
    <TabsTrigger value="cli">
      Command
    </TabsTrigger>

    <TabsTrigger value="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="cli">
    ```bash
    npx shadcn@latest add @agentcn/mastra/google-sheets
    ```
  </TabsContent>

  <TabsContent value="manual">
    <Steps>
      <Step>
        Install the following dependencies:
      </Step>

      ```bash
      npm install @mastra/core
      ```

      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource src="registry/mastra/google-sheets/config.ts" title="config.ts" />

      <ComponentSource src="registry/mastra/google-sheets/instructions.md" title="instructions.md" />

      <ComponentSource src="registry/mastra/google-sheets/tools/read_range.ts" title="tools/read_range.ts" />

      <ComponentSource src="registry/mastra/google-sheets/tools/update_range.ts" title="tools/update_range.ts" />

      <Step>
        Update the import paths to match your project setup.
      </Step>
    </Steps>
  </TabsContent>
</CodeTabs>

## Composition [#composition]

```text
├── config.ts             # Agent definition (model + config)
├── instructions.md       # Read-before-write analysis instructions
└── tools/
    ├── read_range.ts     # Reads a range (A1 notation)
    └── update_range.ts   # Writes values to a range
```

## Customization [#customization]

* **Use a service account.** Mint the access token from a service account for
  unattended runs.
* **Add operations.** Add tools for appending rows, formatting, or creating sheets.
* **Guard writes.** Require explicit confirmation before any `update_range` call.
* **Swap the model.** Edit `config.ts`.
