setActiveSheetIndex(0) ->setCellValue('A1','Employee Absence Reporting') ->setCellValue('A2','Human Capital '.$_SESSION['employeename']) ->setCellValue('A3','Date Reporting : '.date("d/m/Y H:i:s")) ->setCellValue('A4','Periode : '.$cl->FN_GETMONTHNAME($month)." $period"); if($idsubunit) { $subunitname=$cl->fn_get_fieldvalue("subunitname","select subunitname from ".DB_APORTIL.".tbl_employee_subunit where id='$idsubunit'"); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A5','Sub Unit : '.$subunitname); } // set format cell $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); // Print Header $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A7','No') ->setCellValue('B7','Employee Name') ->setCellValue('C7','Nik') ->setCellValue('D7','Position') ->setCellValue('E7','Dates') ->setCellValue('F7','Clock In') ->setCellValue('G7','Clock Out') ->setCellValue('H7','Reason') ; // === Merge Cells $objPHPExcel->getActiveSheet()->getStyle('A7:H7')->getFont()->getColor()->setRGB('ffffff'); // Worksheet Name $objPHPExcel->getActiveSheet()->setTitle('Absence_'.date("Ym")); // === Set Background Cell $objPHPExcel->cellColor("A7:H7","938e8e"); // === set Column Width A $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6); // === Set auto COlumn width foreach(range('B','H') as $columnID) { $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true); } $swhere="";// if($idemployee) { $swhere="a.idemployee='$idemployee' and "; } if($month) { $swhere.="a.months='$month' and "; } if($period) { $swhere.="a.years='$period' and "; } $qry="select a.idemployee,e.fullname,e.positionname,a.nik,a.date,a.clockin,a.clockout,a.reason from ".DB_APORTIL.".tbl_employee e inner join ".DB_APORTIL.".tbl_hcm_absence a on e.id=a.idemployee where $swhere a.isdeleted=0 and a.idstatus in (0,3,4) order by a.date asc"; $rsrpt=$cl->selectquery($qry); if($rsrpt) { $i=8;$j=1; while($rw=$cl->data_row_array($rsrpt)) { $colors="000000"; if((int)date("Hi",strtotime($rw['clockin']))>900) { $colors="FF0000"; } $phpColor = new PHPExcel_Style_Color(); $phpColor->setRGB($colors); $clockout=date("H:i",strtotime($rw['clockout'])); if(!$rw['clockout']){$clockout="";} $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$i,$j) ->setCellValue('B'.$i,$rw["fullname"]) ->setCellValue('C'.$i,$rw["nik"]) ->setCellValue('D'.$i,$rw["positionname"]) ->setCellValue('E'.$i,date("d/m/Y",strtotime($rw['date']))) ->setCellValue('F'.$i,date("H:i",strtotime($rw['clockin']))) ->setCellValue('G'.$i,$clockout) ->setCellValue('H'.$i,$rw['reason']) ; $objPHPExcel->getActiveSheet()->getStyle('F'.$i)->getFont()->setColor($phpColor); $objPHPExcel->getActiveSheet()->getStyle('G'.$i)->getFont()->setColor($phpColor); $i+=1;$j+=1; } } $cl->clearrecordset($rsrpt); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a web browser (Excel2007) //header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="HCM_ABSENCE.xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; ?>