Blogger Information
Blog 7
fans 0
comment 0
visits 15453
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Laravel-Excel 2.0 (Excel 表格操作)
冷雨画桥
Original
1951 people have browsed it

使用composer安装Excel2.0扩展

  1. //注:一定要加版本号 laravel-Excel 现在最新版是3.0 使用方面会有很大不同 不加版本号的话Composer会默认安装3.0版本
  2. composer require maatwebsite/excel ~2.1.0

配置修改

  1. /config/app.php
  2. providers =>[
  3. Maatwebsite\Excel\ExcelServiceProvider::class
  4. ];
  5. aliases => [
  6. 'Excel' => Maatwebsite\Excel\Facades\Excel::class
  7. ];
  8. //命令行 执行 会在config下生成一个excel.php的配置文件
  9. php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider"

导出

  1. use Excel;
  2. public function export()
  3. {
  4. $cellData = [
  5. ['id','姓名''年龄'],
  6. ['1','zhangsan','10',],
  7. ['2','lisi','12']
  8. ];
  9. Excel::create('user',function($excel) use ($cellData){
  10. $excel->sheet('sheet1',function($sheet) use ($cellData){
  11. $sheet->rows($cellData);
  12. });
  13. })->store('xls')->export('xls');
  14. }

导入

  1. use Excel;
  2. public function import()
  3. {
  4. $path = 'storage/export/'.iconv('UTF','GBK','用户').'xls';
  5. Excel::load($path,function($reader){
  6. $data = $reader->all()->toArray();
  7. dd($data);
  8. });
  9. }

中问乱码的话

  1. to_ascii = "false"; //修改 config[ 'to_ascii' => true ]; 为false

如有帮助,不胜荣幸!

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post