您现在的位置是:首页 > PHP框架交流PHP框架交流
Maatwebsite\Excel 读取导入excel转为数组数据显示不全
上善若水2020-06-30 14:16:57【PHP框架交流】
4614人已围观
简介在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)
相关文章
随机图文
spriingboot之mybatis 一对多关联查询
在接触mybatis时,只会使用mapper提供的单表查询,关联查询需要配置xml完成,整理了使用@Results注解完成表的关联查询.参考博客:https://blog.csdn.net/zhousyii2伪静态 使用apach在phpstudy配置伪静态
yii2 在phpstudy配置伪静态使用阿帕奇作为服务器,yii中文网找了安装了yii2,安装完composer之后发现路径需要重写,就去官网加上伪静态,只找到一下方式. # 开启 mocentos创建软链接 linux如何创建快捷方式
centos创建软链接 linux如何创建快捷方式,一般情况下,我们下载文件会才用软链接的方式去处理,不直接放在网站的public目录下,有时候需要我们创建软链接,每次用每次百度,用一次忘一次。 软链PHP8.0新特性(3) 构造器属性提升 简单写法
PHP8.0新特性(3) 构造器属性提升 简单写法,写法更加简洁,直接定义到构造器传参的参数上了。新版写法 class Point { public function __construct(