public function export_data($data = array()) { if (!empty($data)) { $phpExcel = new excel(); $prestasi = $phpExcel->setActiveSheetIndex(0); //merger $phpExcel->getActiveSheet()->mergeCells('A1:L1'); //manage row hight $phpExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25); //style alignment $styleArray = array('alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER)); $phpExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); $phpExcel->getActiveSheet()->getStyle('A1:L1')->applyFromArray($styleArray); //border $styleArray1 = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN))); //background $styleArray12 = array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => 'FFEC8B'))); //freeepane $phpExcel->getActiveSheet()->freezePane('A3'); //coloum width $phpExcel->getActiveSheet()->getColumnDimension('A')->setWidth(4.1); $phpExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10); $phpExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15); $phpExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25); $phpExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20); $phpExcel->getActiveSheet()->getColumnDimension('F')->setWidth(10); $phpExcel->getActiveSheet()->getColumnDimension('G')->setWidth(40); $phpExcel->getActiveSheet()->getColumnDimension('H')->setWidth(15); $phpExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15); $phpExcel->getActiveSheet()->getColumnDimension('J')->setWidth(25); $phpExcel->getActiveSheet()->getColumnDimension('K')->setWidth(25); $phpExcel->getActiveSheet()->getColumnDimension('L')->setWidth(25); $prestasi->setCellValue('A1', 'รายงาน รายชื่อนักเรียน'); $phpExcel->getActiveSheet()->getStyle('A2:L2')->applyFromArray($styleArray); $phpExcel->getActiveSheet()->getStyle('A2:L2')->applyFromArray($styleArray1); $phpExcel->getActiveSheet()->getStyle('A2:L2')->applyFromArray($styleArray12); $prestasi->setCellValue('A2', 'No'); $prestasi->setCellValue('B2', 'รหัส'); $prestasi->setCellValue('C2', 'คํานําหน้าชื่อ'); $prestasi->setCellValue('D2', 'ชื่อ-นามสกุล'); $prestasi->setCellValue('E2', 'รหัสบัตรประชาชน'); $prestasi->setCellValue('F2', 'วันเกิด'); $prestasi->setCellValue('G2', 'ปีการศึกษา'); $prestasi->setCellValue('H2', 'ห้องเรียน'); $prestasi->setCellValue('I2', 'ที่อยู่'); $prestasi->setCellValue('J2', 'เบอร์โทรนักเรียน'); $prestasi->setCellValue('K2', 'เบอร์โทรผู้ปกครอง'); $prestasi->setCellValue('L2', 'วันที่เข้าเรียน'); $no = 0; $rowexcel = 2; foreach ($data as $row) { $no++; $rowexcel++; $phpExcel->getActiveSheet()->getStyle('A' . $rowexcel . ':L' . $rowexcel)->applyFromArray($styleArray); $phpExcel->getActiveSheet()->getStyle('A' . $rowexcel . ':L' . $rowexcel)->applyFromArray($styleArray1); $prestasi->setCellValue('A' . $rowexcel, $no); $prestasi->setCellValue('B' . $rowexcel, $row['STU_CODE']); $prestasi->setCellValue('C' . $rowexcel, $row['STU_TITLE']); $prestasi->setCellValue('D' . $rowexcel, $row['STU_FNAME'] . ' ' . $row['STU_LNAME']); $prestasi->setCellValue('E' . $rowexcel, $row['ID_CARD']); $prestasi->setCellValue('F' . $rowexcel, $row['BIRTH_DATE']); $prestasi->setCellValue('G' . $rowexcel, $row['GRADE_NAME']); $prestasi->setCellValue('H' . $rowexcel, $row['CLASS_NUM']); $prestasi->setCellValue('I' . $rowexcel, $row['STU_ADD']); $prestasi->setCellValue('J' . $rowexcel, $row['STU_TEL']); $prestasi->setCellValue('K' . $rowexcel, $row['STU_PTEL']); $prestasi->setCellValue('L' . $rowexcel, $row['STU_INDATE']); } $prestasi->setTitle('รายงาน รายชื่อนักเรียน'); header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=\"Students Report.xls\""); header("Cache-Control: max-age=0"); $objWriter = PHPExcel_IOFactory::createWriter($phpExcel, "Excel5"); $objWriter->save("php://output"); } }