凌的博客

您现在的位置是: 首页 > 学无止境 > PHP > 

PHP

spreadsheet 读取excel,xls,xlsx表格

2022-07-18 PHP 809
use PhpOffice\PhpSpreadsheet\IOFactory;
......
public static function readExcel($file)
{
    $spreadsheet = IOFactory::load($file);

    $sheet = $spreadsheet->getActiveSheet();
    $res = [];
    foreach ($sheet->getRowIterator() as $row) {
        $tmp = [];
        foreach ($row->getCellIterator() as $cell) {
            $tmp[] = $cell->getFormattedValue();
        }
        $res[$row->getRowIndex()] = $tmp;
    }
    return $res;
}


文章评论

0条评论