yii2 phpexecl导入

composer require phpoffice/phpexcel : "*"

$fileType =  \PHPExcel_IOFactory::identify($file);
$excelReader = \PHPExcel_IOFactory::createReader($fileType);

$phpExcel = $excelReader->load($file)->getSheet(0);
$total_line = $phpExcel->getHighestRow();//总行数
$total_column = $phpExcel->getHighestColumn();//总列数

$data = [];
if($total_line > 1) {
    for ($row = 1; $row <= $total_line; $row++) {
        for ($column = 'A'; $column <= $total_column; $column++) {
            $data[$row][] = trim($phpExcel->getCell($column . $row)->getValue());
        }
    }
}

参考:https://blog.csdn.net/renamayu/article/details/53431701

猜你喜欢

转载自blog.csdn.net/weixin_39461487/article/details/81170801