iyogesharma / csv
dev-main
2024-07-02 07:06 UTC
Requires
- php: >=7.0.0
- laravel/framework: >=5.0
This package is auto-updated.
Last update: 2024-09-12 04:40:20 UTC
README
此包作为CSV读取逻辑的包装器,自动处理所有文件读取。您只需提供CSV文件,它将返回文件数据作为数组。
此外,此包包括Ys\Csv\Writer以方便下载CSV文件。
读取CSV文件
$file = $request->file('csv'); $reader = new YS\Csv\Reader(); $reader->importFromPath($file); //to read chunck of data $reader->chunk(2500)->fetch(true); //the fetch function accept a boolean param bool $assoc with default value false, //$assoc = true will fetch data as associated array with column name as key. //$assoc = false will return normal array // get number of rows in file $reader->getSize() $rows = $reader->getRecords() // return generator you can interate over rows to access data
下载CSV文件
Writer::download($headers,$data,'filename');