Files
Document-Management-System-…/app/Exports/UsersExport.php
2021-04-07 06:32:42 -04:00

82 lines
1.9 KiB
PHP

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