application/modules/ts/controllers/Ts.php
/* report export excel mttr vs mtbf */
report export excel mttr vs mtbf
report export excel mttr vs mtbf
public function rpt_mttr_vs_mtbf()
	{
		$start_date = date_input($this->input->post('f_start_date')); 
		$end_date = date_input($this->input->post('f_end_date'));
		$spreadsheet = new spreadsheet();
		$styeArray = [
			'borders' => [
				'allBorders' => [
					'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
					'color' => ['argb' => '1e232b'],
				],
			],
		]; 
		$spreadsheet->setActiveSheetIndex(0)->getColumnDimension('A')->setAutoSize(true); 
		$spreadsheet->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->setARGB('#1e232b');
		$data = $this->mttr->mttr_vs_mtbf($start_date,$end_date);
		$spreadsheet->getActiveSheet()
    ->fromArray(
        $data,  
        NULL,        
        'A2'         
	);
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("A1","NAP");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("B1","TYPE");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("C1","GROUP");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("D1","NO MACHINE");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("E1","SERIAL NUMBER");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("F1","MODEL");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("G1","MANUFACTURER");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("H1","TOTAL DOWN TIME");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("I1","TOTAL DAYS");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("J1","WORKING HOURS");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("K1","POSSIBLE WORKING HOURS");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("L1","OPERATION WORKING HOURS");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("M1","AVERAGE (%)");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("N1","TOTAL EVENT");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("O1","MTBF (%)");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("P1","MTTR (%)");
		$spreadsheet->setActiveSheetIndex(0)->setCellValue("Q1","STATUS BREAKDOWN");
		for ($i=2; $i <= count($data) ; $i++) { 
			$status = $spreadsheet->getActiveSheet()->getCell("Q".$i)->getValue();
			$code_unit = $spreadsheet->getActiveSheet()->getCell("B".$i)->getValue();
				if ($status == 0 ) {
					$spreadsheet->setActiveSheetIndex(0)->setCellValue("Q".$i,$status)->getStyle('Q'.$i)->getFill()
			->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
			->getStartColor()->setARGB('f44141');
			$spreadsheet->setActiveSheetIndex(0)->setCellValue("B".$i,$code_unit)->getStyle('B'.$i)->getFill()
			->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
			->getStartColor()->setARGB('f44141');
				}
			}
		$nama_file = date("Y-m-d");
		header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheet.sheet');
		header('Content-Disposition: attachment;filename="rpt_mttr_vs_mtbf_'.$start_date.'_'.$end_date.'.xlsx"');
		header('Cache-control: max-age=0');
		header('Cache-Control: max-age=1');
		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 
		header('Cache-Control: cache, must-revalidate'); 
		header('Pragma: public'); 
		$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
		ob_end_clean();
		$writer->save('php://output');
		exit;
	}
public function rpt_mttr_vs_mtbf ( ) { $ start_date = date_input ( $ this -> input -> post ( 'f_start_date' ) ) ; $ end_date = date_input ( $ this -> input -> post ( 'f_end_date' ) ) ; $ spreadsheet = new spreadsheet ( ) ; $ styeArray = [ 'borders' => [ 'allBorders' => [ 'borderStyle' => \ PhpOffice \ PhpSpreadsheet \ Style \ Border :: BORDER_THIN , 'color' => [ 'argb' => '1e232b' ] , ] , ] , ] ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> getColumnDimension ( 'A' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getStyle ( 'A1' ) -> getFill ( ) -> getStartColor ( ) -> setARGB ( '#1e232b' ) ; $ data = $ this -> mttr -> mttr_vs_mtbf ( $ start_date , $ end_date ) ; $ spreadsheet -> getActiveSheet ( ) -> fromArray ( $ data , NULL , 'A2' ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " A1 " , " NAP " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " B1 " , " TYPE " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " C1 " , " GROUP " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " D1 " , " NO MACHINE " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " E1 " , " SERIAL NUMBER " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " F1 " , " MODEL " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " G1 " , " MANUFACTURER " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " H1 " , " TOTAL DOWN TIME " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " I1 " , " TOTAL DAYS " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " J1 " , " WORKING HOURS " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " K1 " , " POSSIBLE WORKING HOURS " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " L1 " , " OPERATION WORKING HOURS " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " M1 " , " AVERAGE (%) " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " N1 " , " TOTAL EVENT " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " O1 " , " MTBF (%) " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " P1 " , " MTTR (%) " ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " Q1 " , " STATUS BREAKDOWN " ) ; for ( $ i = 2 ; $ i <= count ( $ data ) ; $ i ++ ) { $ status = $ spreadsheet -> getActiveSheet ( ) -> getCell ( " Q " . $ i ) -> getValue ( ) ; $ code_unit = $ spreadsheet -> getActiveSheet ( ) -> getCell ( " B " . $ i ) -> getValue ( ) ; if ( $ status == 0 ) { $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " Q " . $ i , $ status ) -> getStyle ( 'Q' . $ i ) -> getFill ( ) -> setFillType ( \ PhpOffice \ PhpSpreadsheet \ Style \ Fill :: FILL_SOLID ) -> getStartColor ( ) -> setARGB ( 'f44141' ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( " B " . $ i , $ code_unit ) -> getStyle ( 'B' . $ i ) -> getFill ( ) -> setFillType ( \ PhpOffice \ PhpSpreadsheet \ Style \ Fill :: FILL_SOLID ) -> getStartColor ( ) -> setARGB ( 'f44141' ) ; } } $ nama_file = date ( " Y-m-d " ) ; header ( 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheet.sheet' ) ; header ( 'Content-Disposition: attachment;filename="rpt_mttr_vs_mtbf_' . $ start_date . '_' . $ end_date . '.xlsx"' ) ; header ( 'Cache-control: max-age=0' ) ; header ( 'Cache-Control: max-age=1' ) ; header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ) ; header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ) ; header ( 'Cache-Control: cache, must-revalidate' ) ; header ( 'Pragma: public' ) ; $ writer = IOFactory :: createWriter ( $ spreadsheet , 'Xlsx' ) ; ob_end_clean ( ) ; $ writer -> save ( 'php://output' ) ; exit ; }
report export excel mttr vs mtbf
report export excel mttr vs mtbf
// array untuk membuat all border //set widht menjadi autosize // The data to set // Array values with this value will not be set // Top left coordinate of the worksheet range where //    we want to set these values (default is A1) //$spreadsheet->getActiveSheet()->getStyle("Q".$i)->getFill()->getStartColor()->setARGB('8094b5');				 // If you're serving to IE 9, then the following may be needed // If you're serving to IE over SSL, then the following may be needed // Date in the past // always modified // HTTP/1.1 // HTTP/1.0