> For the complete documentation index, see [llms.txt](https://docs.gpmautomate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gpmautomate.com/automate-zh/cao-zuo-zhi-nan/google-service/read-google-sheet.md).

# 读取谷歌表格

读取谷歌表格是指命令脚本自动连接到您的Google Drive帐户，以提取和读取在线Google Sheets文件中单元格或数据区域的内容。

#### 配置参数：

* 凭证文件：选择Google帐户的凭证文件（扩展名为`.json`的文件）。该文件充当安全密钥，用于与Google API系统建立安全连接，验证并授权GPM Automate可以读取/写入您Google Sheet中的内容。
  * *详细指南*：您可以在此处查看有关如何创建此凭证文件的视频指导：
* 文件ID：需要交互的Google Sheets文件的唯一标识符，以便系统准确识别需要读取数据的文件。
  * *如何获取ID*：当您在浏览器中打开Google Sheet文件时，URL路径的格式为`https://docs.google.com/spreadsheets/d/abc123xyz_在这里的_ID/edit`。您只需复制位于`/d/`和`/edit`之间的字符字符串以填入此框。
* 表格ID：需要读取的工作表（Sheet）在文件中的位置序号（从左到右，第一张表的编号为`0`，依次为1、2、3...）。
* 列名称或索引：指定需要读取数据的列位置。您可以通过两种方式输入：
  * *按字母名称*：输入从`A`、`B`、`C`、`D`...开始的列名称。
  * *按序号（Index）*：输入从`1`开始的序号（对应列1为列A）。
* 行索引：需要读取数据的行的序号，从`1`开始计算（对应Google Sheet中的第1行）。
* 输出变量：GPM Automate用于接收和存储从该单元格读取的文本内容的变量名称。

#### 实际示例：自动从Google Sheet获取账户数据以填写表单

当您在共享的Google Sheet文件中存储大量MMO账户（包括用户名、密码）列表，并希望脚本自动读取第一行以提取数据进行处理时：

* 配置以获取单元格A1中的用户名：
  * 凭证文件：选择配置好的`client_secret_....json`文件的路径。
  * 文件ID：输入您的Sheet文件的ID。
  * 表格ID：`0`（在第一张表中读取）。
  * 列名称或索引：填写`A`（或填写`1`）。
  * 行索引：填写`1`。
  * 输出变量：`currentUsername`
* 结果：GPM Automate将自动连接到Google Sheet，提取A1单元格中的数据，并将文本内容直接加载到变量`$currentUsername`中。之后，您可以在输入操作中顺利调用此变量。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gpmautomate.com/automate-zh/cao-zuo-zhi-nan/google-service/read-google-sheet.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
