PHP laravel Framework Import Export Excel, Phpexcel data export divided into multiple workspaces (sheet)

Source: Internet
Author: User

Laravel Import and export there are many but you find that when you install excal according to Conposer, you find that he is always bricks prompt you: Installation failed

This is laravel5.4 's genius, let's take a look at it!

1. In the root directory of the Laravel project we will see a Composer.json file:

Open and find "Maatwebsite/excel": "~2.0.0" modified to "~2.1.0" save

2. Perform composer update Maatwebsite/excel

3. Edit laravel-config-app.php

Find an array of provides to add Maatwebsite\excel\excelserviceprovider::class to the array,

In the array of aliases, add ' Excel ' = Maatwebsite\excel\facades\excel::class,

4. Execute after add: PHP artisan vendor:publish

So you can build routing controllers and so on.

Code:

<?phpnamespace app\http\controllers; Useilluminate\http\request; Useapp\http\requests; UseApp\http\controllers\controller; UseExcel;classExcelcontrollerextendscontroller{//Excel file export feature by Laravel College     Public functionExport () {$cellData= [            [' Learning number ', ' name ', ' score ',            [' 10001 ', ' AAAAA ', ' 99 '],            [' 10002 ', ' bbbbb ', ' 92 '],            [' 10003 ', ' CCCCC ', ' 95 '],            [' 10004 ', ' ddddd ', ' 89 '],            [' 10005 ', ' eeeee ', ' 96 '],        ]; Excel:: Create (' Student score ',function($excel) Use($cellData){            $excel->sheet (' SheetName ',function($sheet) Use($cellData){                $sheet->rows ($cellData);        }); })->export (' xls '); }}
If you need export is divided into multiple workspaces (sheet):
Multiple calls   $excel->sheet (..... )  , note sheetname avoid duplication
  
//Import$filePath= ' storage/exports/'.Iconv(' UTF-8 ', ' GBK ', ' 1234 '). xls; Excel:: Load ($filePath,function($reader) { $data=$reader-All (); DD ($data);}); Supplement:if the project uses time, please revise it.: Root directory->config->app' TimeZone ' = ' PRC ',//' UTC ', for Excel time//PRC for Chinese time does not use UTC because time is inaccurate when using the date functionIf the table header is a Chinese character cause the column data cannot be output please modify: root directory->config->Excel' To_ascii ' =false //ture If the Excel header is a Chinese character, the value will be missing .

PHP laravel Framework Import Export Excel, Phpexcel data export divided into multiple workspaces (sheet)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.