Installation of Excel Plug-ins in Laravel
Introduction of Laravel Excel packages in composer
"Maatwebsite/excel": "1.*"
To edit the app.php file under Laravel/app/config, add the following values in the providers array
' Maatwebsite\excel\excelserviceprovider ',
Find the aliasses array in the same file add the following values
' Excel ' => ' maatwebsite\excel\facades\excel ',
Executes the composer install or composer Update command.
Laravel Excel Configuration
Some of the configuration items for Plug-ins are located under Laravel/vendor/maatwebsite/excel/src/config
config.php > Some settings for Excel and table global
csv.php > settings for exporting CSV files to import
Export.pho > Some settings to print out the contents of a file
import.php > settings for importing Excel files
Simple use of Laravel Excel
We'll be able to use the Excel plugin after all the previous preparations have been done.
Export Excel
<?php
$rows = Array (array (' ID ' => 1, ' name ' => ' Marlon '));
Excel::create ($name, function ($excel) use ($rows) {
$excel->sheet (' Registration of the day ', function ($sheet) use ($rows) {
$sheet->fromarray ($rows);
});
})->store (' xls ', Storage_path (' Excel '));
Since it is not possible to get the variables outside the closure in the PHP closure, you need to introduce $rows with use, and the parameters that are passed in the store of the last chained call are the format of Excel and the location to save to the server, which is the absolute path.
In this place store () method for storage, the corresponding can also use the download () method to download directly, as for the export method The author has not understood what is the use of
Import Excel
<?php
Excel::load (Input::file (' Excel '), function ($reader) {
Get the first few tables of Excel
$reader = $reader->getsheet (0);
Get data from a table
$results = $reader->toarray ();
Here, $results is already in Excel data, can be here to operate on him, warehousing or other ....
});