first commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
// require '../../../vendor/autoload.php';
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$sheet->setTitle('Danh sách');
|
||||
$sheet->setCellValue('A1', 'STT');
|
||||
$sheet->setCellValue('B1', 'HỌ TÊN');
|
||||
$sheet->setCellValue('C1', 'SỐ ĐIỆN THOẠI');
|
||||
$sheet->setCellValue('D1', 'NGHỀ NGHIỆP');
|
||||
$sheet->setCellValue('E1', 'TÊN GIẢI THƯỞNG');
|
||||
$sheet->setCellValue('F1', 'NGÀY QUAY SỐ');
|
||||
$row = 1;// Initialize row counter
|
||||
$stt = 1;
|
||||
// $newsheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, str_replace("/", "-", $date));
|
||||
// $spreadsheet->addSheet($newsheet, 0);
|
||||
// $sheet->mergeCells('A' . $row . ':X' . $row);
|
||||
$sheet->getStyle('A' . $row)->applyFromArray(array(
|
||||
'font' => array(
|
||||
'name' => 'Calibri',
|
||||
'size' => 14,
|
||||
'bold' => true
|
||||
),
|
||||
'alignment' => [
|
||||
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT,
|
||||
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
|
||||
'wrapText' => true,
|
||||
],
|
||||
));
|
||||
$row++;
|
||||
foreach ($data as $item) {
|
||||
$sheet->setTitle('DS Nhận Giải');
|
||||
$sheet->setCellValue('A' . $row, $stt);
|
||||
$sheet->setCellValue('B' . $row, $item->name ?? '');
|
||||
$sheet->setCellValue('C' . $row, $item->phone ?? '');
|
||||
$sheet->setCellValue('D' . $row, $item->job ?? '');
|
||||
$sheet->setCellValue('E' . $row, $item->prize_name ?? '');
|
||||
$sheet->setCellValue('F' . $row, $item->created_at != '' ? date_format(date_create($item->created_at), "d/m/Y H:i") : '');
|
||||
$row++;
|
||||
$stt++;
|
||||
}
|
||||
$sheet->getStyle('A1:F1')->applyFromArray(array(
|
||||
'font' => array(
|
||||
'name' => 'Calibri',
|
||||
'size' => 14,
|
||||
'bold' => true
|
||||
)
|
||||
));
|
||||
$sheet->getStyle('A1:F' . $row - 1)->applyFromArray(array(
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
));
|
||||
foreach (range('A', 'F') as $column) {
|
||||
$sheet->getColumnDimension($column)->setAutoSize(true);
|
||||
}
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$fileName = "Danh sách nhận giải.xlsx";
|
||||
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
header("Content-Disposition: attachment;filename=\"$fileName\"");
|
||||
$writer->save("php://output");
|
||||
exit();
|
||||
?>
|
||||
Reference in New Issue
Block a user