PHP code example of mckue / laravel-excel

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/ */

    

mckue / laravel-excel example snippets


php artisan vendor:publish --provider="Mckue\Excel\ExcelServiceProvider" --tag=config
 

 php artisan php-ext-xlswriter:status
 



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');
    }
}

Route::get('users/export/', [UsersController::class, 'export']);
 
public function export() 
{
    return Excel::download(new InvoicesExport, 'invoices.xlsx', true, ['X-Vapor-Base64-Encode' => 'True']);
}