安装库
composer require phpoffice/phpspreadsheet
经测试php7.4.3要安装1.28版本
composer require phpoffice/phpspreadsheet:1.28
引入对应的类
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Shared\Date;
下面是借用layui的upload来对接
1.添加按钮
<button type="button" class="layui-btn demo-class-accept" lay-options="{accept: 'file',acceptMime:'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',exts: 'xlsx|xls'}">
<i class="layui-icon layui-icon-upload"></i>
上传文件
</button>
js方法:
var upload = layui.upload;
upload.render({
elem: '.demo-class-accept', // 绑定多个元素
url: '/api_admin/uploadExcel', // 此处配置你自己的上传接口即可
accept: 'file', // 普通文件
done: function(res){
layer.msg('上传成功');
console.log(res);
}
});
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
请登录后查看评论内容