update code
This commit is contained in:
81
app/Exports/UsersExport.php
Normal file
81
app/Exports/UsersExport.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use Maatwebsite\Excel\Concerns\WithPreCalculateFormulas;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Events\BeforeExport;
|
||||
use Maatwebsite\Excel\Events\BeforeWriting;
|
||||
use Maatwebsite\Excel\Events\BeforeSheet;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
|
||||
class UsersExport
|
||||
implements
|
||||
FromCollection,
|
||||
WithHeadings,
|
||||
WithMapping,
|
||||
ShouldAutoSize,
|
||||
WithTitle,
|
||||
WithCustomStartCell
|
||||
{
|
||||
protected $users;
|
||||
|
||||
public function __construct($users){
|
||||
$this->users = $users;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
return $this->users;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Mã',
|
||||
'Tên',
|
||||
'Email',
|
||||
'Số điện thoại',
|
||||
'Ngày sinh',
|
||||
'Chức danh',
|
||||
'Phòng ban',
|
||||
'Kích hoạt',
|
||||
];
|
||||
}
|
||||
|
||||
public function map($user): array
|
||||
{
|
||||
return [
|
||||
$user->id,
|
||||
$user->name,
|
||||
$user->email,
|
||||
$user->tel,
|
||||
explode(' ', $user->birthday)[0],
|
||||
$user->title_id,
|
||||
$user->department_id,
|
||||
$user->active,
|
||||
];
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Danh sách người dùng';
|
||||
}
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A1';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user