# XLSX 转 CSV - 回调模式

## 应用场景

数据需要经过二次处理写入CSV。

1. 较多的 xlsx 文件碎片，合并为单一CSV文件，统一处理；
2. xlsx文件新增的速度大于任务处理速度，可异步将文件转为CSV后，使用更高效的工具处理（例如：数据库工具直接导入CSV）；

更多的应用场景等待你去发现...........

## **函数原型**

```php
putCSVCallback(callable $callback, resource $handler): bool
```

### **callable $callback**

> 回掉函数

### **resource $handler**

> 文件指针必须是有效的，必须指向由 fopen() 或 fsockopen() 成功打开的文件(并还未由 fclose() 关闭)。

## 示例

```php
$config   = ['path' => './tests'];
$excel    = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('tutorial.xlsx', 'TestSheet1')
    ->header(['String', 'Int', 'Double'])
    ->data([
        ['Item_1', 10, 10.9999995],
    ])
    ->output();

$fp = fopen('./tests/file.csv', 'w');

$csvResult = $excel->openFile('tutorial.xlsx')
    ->openSheet()
    ->putCSVCallback(function(array $row){
        return $row;
    }, $fp);
```


---

# Agent Instructions: 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:

```
GET https://xlswriter-docs.viest.me/zhong-wen-jian-ti/csv/put-csv-callback.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
