| Server IP : 172.67.187.206 / Your IP : 172.71.28.155 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Inetpub/www/school_budget/admin/ |
Upload File : |
<?php
require_once('../libs/PHPExcel/Classes/PHPExcel.php');
// สร้างไฟล์ Excel
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$mainSheet = $objPHPExcel->getActiveSheet();
$mainSheet->setTitle('Schools');
// ตั้งค่าหัวคอลัมน์และตัวอย่าง
$mainSheet->getCell('A1')->setValue("School Name\n(เช่น 'โรงเรียนราชบุรี')");
$mainSheet->getCell('B1')->setValue("Username\n(เช่น 'ratchaburi')");
$mainSheet->getCell('C1')->setValue("Password\n(เช่น 'rb1234')");
// จัดรูปแบบหัวคอลัมน์
$headerStyle = [
'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']],
'fill' => ['type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => ['rgb' => '1F497D']],
'alignment' => ['horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, 'wrap' => true]
];
$mainSheet->getStyle('A1:C1')->applyFromArray($headerStyle);
$mainSheet->getRowDimension(1)->setRowHeight(40);
// กำหนดความกว้างคอลัมน์
$mainSheet->getColumnDimension('A')->setWidth(40);
$mainSheet->getColumnDimension('B')->setWidth(25);
$mainSheet->getColumnDimension('C')->setWidth(25);
// ส่งไฟล์ให้ผู้ใช้ดาวน์โหลด
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="template_schools.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
?>