您现在的位置是:首页 > PHP框架交流PHP框架交流

Maatwebsite\Excel 读取导入excel转为数组数据显示不全

上善若水2020-06-30 14:16:57【PHP框架交流】 3497人已围观

简介在laravel中读取excel转换为数组进行数据处理,发现转换为的数组内只有一条记录,其他记录丢失,Maatwebsite\Excel 读取导入excel转为数组数据显示不全,发现网上给出的代码掉了

在laravel中读取excel转换为数组进行数据处理,发现转换为的数组内只有一条记录,其他记录丢失,Maatwebsite\Excel 读取导入excel转为数组数据显示不全,发现网上给出的代码掉了一句话.
错误代码

Excel::load($file,function ($reader)use(&$list){
    $list = $reader->all()->toArray();
 });

修改后代码

Excel::load($tmp, function ($reader) use (&$listing) {
            $reader = $reader->getSheet(0);
            $listing = $reader->toArray();
 });
public function v3(){
        $tmp="D:/phpstudy_pro/WWW/24.com/public/upload/excel/exports/fen.xls";
        // 加载Excel临时文件
        $listing=array();
        Excel::load($tmp, function ($reader) use (&$listing) {
            $reader = $reader->getSheet(0);
            $listing = $reader->toArray();
        });
        $myfile = fopen("D:/phpstudy_pro/WWW/24.com/public/upload/excel/exports/fen.txt", "w") or die("Unable to open file!");
        $txt = json_encode($listing);
        fwrite($myfile, var_export($listing,true));
        fclose($myfile);
    }

Tags: laravel

很赞哦! (8)

相关文章

文章评论

站点信息

  • 建站时间:2019-10-24
  • 网站程序:Thinkphp6 Layui
  • 文章统计247篇文章
  • 标签管理标签云
  • 统计数据cnzz统计
  • 微信公众号:扫描二维码,关注我们