> 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/file-and-folder/write-excel-file.md).

# 写入Excel文件

### 写入数据到 Excel 的操作 (Write excel file)

写入 Excel 文件是将特定值写入或更新 Excel 文件 (`.xlsx` 或 `.xls`) 中指定单元格的操作，基于指定的行和列位置。

#### 配置参数：

* 文件路径：指向需要写入数据的 Excel 文件的绝对路径（例如：`D:\GPM\data.xlsx`）。
* 工作表索引：需要写入数据的工作表（sheet）的位置，从 0 开始计算 *(第一个工作表是 `0`，第二个工作表是 `1`...)*。
* 列名称或索引：需要写入数据的列位置。您可以通过两种方式填写：
  * 按字母字符名称：`A`，`B`，`C`，`D`...
  * 按索引数字，从 1 开始计算 *(列 A 是 `1`，列 B 是 `2`...)*。
* 行索引：需要写入数据的行位置，从 1 开始计算 *(第 1 行是 `1`，第 2 行是 `2`...)*。
* 值：您想要写入该 Excel 单元格的文本内容（或包含数据的变量）。

#### 实际示例：根据正在运行的 Profile 更新账户状态

当您运行多线程脚本（同时运行多个 profile）时，每个 profile 将由 GPM Automate 系统分配系统变量以进行识别：输入 Excel 配置文件路径的变量 (`$inputExcelFileLocation`) 和该 profile 正在处理的数据行序号 (`$inputExcelCurrentRow`)。

假设您希望脚本在成功登录后自动将 `"成功"` 写入对应 profile 在 Excel 文件中正确行的 C 列（状态）：

* 配置方式：
  * 文件路径：传入系统变量 `$inputExcelFileLocation`。
  * 工作表索引：`0` *(写入第一个工作表)*。
  * 列名称或索引：`C` *(状态列)*。
  * 行索引：传入系统变量 `$inputExcelCurrentRow` *(系统自动理解每个 profile 对应的行，例如 profile 1 运行第 2 行将写入第 2 行，profile 2 运行第 3 行将写入第 3 行)*。
  * 值：填写字符串内容 `"成功"`（或包含您日志的变量）。

结果：脚本运行到哪里，将自动同步和准确地更新结果到 Excel 文件中，实时进行，而不必担心被覆盖或数据行在各线程之间错位。


---

# 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/file-and-folder/write-excel-file.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.
