kentreez/easy-file-reader

读取.txt、.msv、.xls、.xlsx文件的简单方法

dev-main 2022-07-31 18:13 UTC

This package is auto-updated.

Last update: 2024-09-29 06:09:11 UTC


README

从文件(.txt、.csv、.xls、.xlsx)中读取每一行数据。该库使用PHP 生成器,然后逐行读取输入文件,以避免将整个文件数据存储在内存中。

*** 警告 ***

由于使用了生成器来遍历输入文件的行,请不要在遍历文件行时中断循环,否则会导致意外的行为。

用法

<?php

    use Kentreez\EasyFileReader\EasyFileReader;
    
    require_once 'vendor/autoload.php';
    
    $easy = EasyFileReader::Read('example.xlsx');
    
    // count all rows
    $easy->count();
    
    // iterate over rows in input file
    foreach ($easy->rows() as $rows) {
        print_r($rows);
    }

    // if we interest only first column of each row then
    foreach ($easy->firstColumns() as $str) {
        echo $str . PHP_EOL;
    }
?>