getProperties()->setCreator("Syamsudin") ->setLastModifiedBy("Syamsudin") ->setTitle("Office 2007 XLSX Test Document") ->setSubject("Export Data") ->setDescription("Export Data") ->setKeywords("office 2007 openxml php") ->setCategory("Export Data"); // $myJSON = json_encode($list); // echo $myJSON; // // var_dump($list); // die(); $event=$list['event']; $assesor=''; $manufacture_name=''; $products_name=''; if($event){ $assesor=isset($event[0]['fullname'])?$event[0]['fullname']:''; $manufacture_name=$event[0]['ref_manunfactures_name']; $products_name=$event[0]['ref_manunfacture_products_name']; } $cel = 2; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A' . $cel, 'Nama Pabrik') ->setCellValue('B' . ($cel), $manufacture_name) ->setCellValue('A' . ($cel+1), 'Nama Produk') ->setCellValue('B' . ($cel+1), $products_name) ->setCellValue('A' . ($cel+2), 'Assesor') ->setCellValue('B' . ($cel+2), $assesor); $cel = 5; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('E' . $cel, 'SCORE') ->setCellValue('E' . ($cel+1), 'Result (Actual) Grouping :'); $cel = 5; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('E' . $cel, 'SCORE') ->setCellValue('E' . ($cel+1), 'Result (Actual) Grouping :'); $column='J'; $header=$list['header']; for ($i=0; $i < count($header); $i++) { $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($column.'' . ($cel), $header[$i]['name']); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($column.'' . ($cel+1), ($header[$i]['total_score']/$list['total_all_max_score'])*100); $column++; $column++; $column++; $column++; } $cel = 7; $event_section=$list['gmb_event_sections']; for ($i=0; $i < count($event_section); $i++) { $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A' . ($cel+1), $event_section[$i]['first_question']) ->setCellValue('B' . ($cel+1), '-') ->setCellValue('C' . ($cel+1), $event_section[$i]['last_question']) ->setCellValue('D' . ($cel+1), $event_section[$i]['section_name']) ->setCellValue('E' . ($cel+1), $event_section[$i]['ach_result_section']) ->setCellValue('F' . ($cel+1), $event_section[$i]['score']) ->setCellValue('G' . ($cel+1), '/') ->setCellValue('H' . ($cel+1), $event_section[$i]['weight']); $column='J'; $header=$event_section[$i]['category_type']; foreach ($header as $key => $value) { $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($column.'' . ($cel+1), $value['total_score']); $column++; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($column.'' . ($cel+1), '/'); $column++; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($column.'' . ($cel+1), $value['total_max_score']); $column++; $column++; } $cel++; } $column='J'; $header=$list['header']; // var_dump($header);die(); for ($i=0; $i < count($header); $i++) { $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($column.'' . ($cel+1), ($header[$i]['total_score']/$header[$i]['total_max_score'])*100); $column++; $column++; $column++; $column++; } $cel++; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A' . ($cel+1), 'PLANT SECTION ACHIEVEMENT'); $cel++; for ($i=0; $i < count($event_section); $i++) { $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A' . ($cel+1), 'SECTION SCORE') ->setCellValue('A' . ($cel+2), $event_section[$i]['ach_result_section']) ->setCellValue('C' . ($cel+1), 'VALUES') ->setCellValue('D' . ($cel+1), $event_section[$i]['section_name']) ->setCellValue('E' . ($cel+1), 'Grand Total'); $cel++; $header=$event_section[$i]['category_type']; foreach ($header as $key => $value) { // var_dump($value);die(); if($value['type'] == 'types'){ $score=ROUND(($value['total_score']/$value['total_max_score'])*100,2); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('C' . ($cel+1), $value['name']) ->setCellValue('D' . ($cel+1), $score) ->setCellValue('E' . ($cel+1), $score); $cel++; } } $cel++; $cel++; } foreach(range('A',$column) as $columnID) { $objPHPExcel->getActiveSheet() ->getColumnDimension($columnID) ->setAutoSize(true); } // $style = array( // 'alignment' => array( // 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, // ) // ); $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);; // Rename worksheet // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); if($generate){ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="gemba-report-'.strtotime(date('Y-m-d')).'.xls"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Pragma: public'); // HTTP/1.0 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save(str_replace(__FILE__,'/hcportal_docs/gembareport/'.$filename,__FILE__)); $objPHPExcel->disconnectWorksheets(); unset($objPHPExcel); // $obj->sendMailAttAwnReport($filename,$mail); }else{ // Redirect output to a client’s web browser (Excel2007) header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="gemba-report.xls"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Pragma: public'); // HTTP/1.0 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); $objPHPExcel->disconnectWorksheets(); unset($objPHPExcel); } exit; // var_dump($objPHPExcel);