1. Go to this page and download the library: Download mckue/laravel-excel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Exports;
use Mckue\Excel\Concerns\FromArray;
class UserExport implements FromArray
{
/**
* @return array */
public function array() : array
{
return [ ['哈哈', 'aaa'],
['哈哈', 'aaa'],
['哈哈', 'aaa'],
['哈哈', 'aaa']
];
}
/**
* @return array
*/
public function headers() : array {
return [];
}
}
namespace App\Http\Controllers;
use App\Exports\UsersExport;
use Mckue\Excel\Facades\Excel;
class UsersController extends Controller
{
public function export()
{
return Excel::download(new UserExport, 'users.xlsx');
}
}