application/controllers/Biodata.php
// export to excel with library phpspreadsheet
export to excel with library phpspreadsheet
export to excel with library phpspreadsheet
public function ex_excel() {
		$rslt_bio = $this->M_Biodata->get_all_data(); 
		$spreadsheet = new Spreadsheet(); 
		$spreadsheet->getDefaultStyle()->getFont()->setName('Calibri'); 
		$spreadsheet->getDefaultStyle()->getFont()->setSize(12); 
		$spreadsheet->setActiveSheetIndex(0)
			->setCellValue('A1', 'No')
			->setCellValue('B1', 'UniqueId')
			->setCellValue('C1', 'Nama')
			->setCellValue('D1', 'Tempat_Tanggal_Lahir')
			->setCellValue('E1', 'Email')
			->setCellValue('F1', 'No_Telp')
			->setCellValue('G1', 'Agama')
			->setCellValue('H1', 'Kebangsaan')
			->setCellValue('I1', 'Pendidikan')
			->setCellValue('J1', 'Jenis_Kelamin')
			->setCellValue('K1', 'Status');
		$spreadsheet->getActiveSheet()->setAutoFilter('A1:K1'); 
		$spreadsheet->getActiveSheet()->getStyle('A1:K1')->getAlignment()->setHorizontal('center'); 
		$spreadsheet->getActiveSheet()->getStyle('A1:K1')->getFont()->setBold(true); 
		$spreadsheet->getActiveSheet()->getStyle('A1:K1')->getBorders()->getBottom()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK); 
		$spreadsheet->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
		$spreadsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
		$spreadsheet->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
		$spreadsheet->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
		$spreadsheet->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
		$spreadsheet->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
		$spreadsheet->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
		$spreadsheet->getActiveSheet()->getColumnDimension('H')->setAutoSize(true);
		$spreadsheet->getActiveSheet()->getColumnDimension('I')->setAutoSize(true);
		$spreadsheet->getActiveSheet()->getColumnDimension('J')->setAutoSize(true);
		$spreadsheet->getActiveSheet()->getColumnDimension('K')->setAutoSize(true);
		$rowIndex = 2;
		$number = 1;
		foreach($rslt_bio as $rslt_data):
			$spreadsheet->setActiveSheetIndex(0)
				->setCellValue('A'. $rowIndex, $number)
				->setCellValue('B'. $rowIndex, $rslt_data->BioUniqueId)
				->setCellValue('C'. $rowIndex, $rslt_data->BioName)
				->setCellValue('D'. $rowIndex, $rslt_data->BioBirthPlace .', '. $rslt_data->BioBirthDate)
				->setCellValue('E'. $rowIndex, $rslt_data->BioEmail)
				->setCellValue('F'. $rowIndex, $rslt_data->BioPhoneNum)
				->setCellValue('G'. $rowIndex, $rslt_data->BioReligion)
				->setCellValue('H'. $rowIndex, $rslt_data->BioNationaly)
				->setCellValue('I'. $rowIndex, $rslt_data->BioEducation)
				->setCellValue('J'. $rowIndex, $rslt_data->BioGender)
				->setCellValue('K'. $rowIndex, $rslt_data->BioStatusMarital);
			$spreadsheet->getActiveSheet()->getCell('A' . $rowIndex)->getStyle()->setQuotePrefix(true);
			$spreadsheet->getActiveSheet()->getCell('B' . $rowIndex)->getStyle()->setQuotePrefix(true);
			$spreadsheet->getActiveSheet()->getCell('C' . $rowIndex)->getStyle()->setQuotePrefix(true);
			$spreadsheet->getActiveSheet()->getCell('D' . $rowIndex)->getStyle()->setQuotePrefix(true);
			$spreadsheet->getActiveSheet()->getCell('E' . $rowIndex)->getStyle()->setQuotePrefix(true);
			$spreadsheet->getActiveSheet()->getCell('F' . $rowIndex)->getStyle()->setQuotePrefix(true);
			$spreadsheet->getActiveSheet()->getCell('G' . $rowIndex)->getStyle()->setQuotePrefix(true);
			$spreadsheet->getActiveSheet()->getCell('H' . $rowIndex)->getStyle()->setQuotePrefix(true);
			$spreadsheet->getActiveSheet()->getCell('I' . $rowIndex)->getStyle()->setQuotePrefix(true);
			$spreadsheet->getActiveSheet()->getCell('J' . $rowIndex)->getStyle()->setQuotePrefix(true);
			$spreadsheet->getActiveSheet()->getDefaultRowDimension()->setRowHeight(15.75);
			$rowIndex++;
			$number++;
		endforeach;
		$writer = new Xlsx($spreadsheet);
		header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
		header('Content-Disposition: attachment;filename="Biodata-' . date('dmY') . '.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 ex_excel ( ) { $ rslt_bio = $ this -> M_Biodata -> get_all_data ( ) ; $ spreadsheet = new Spreadsheet ( ) ; $ spreadsheet -> getDefaultStyle ( ) -> getFont ( ) -> setName ( 'Calibri' ) ; $ spreadsheet -> getDefaultStyle ( ) -> getFont ( ) -> setSize ( 12 ) ; $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( 'A1' , 'No' ) -> setCellValue ( 'B1' , 'UniqueId' ) -> setCellValue ( 'C1' , 'Nama' ) -> setCellValue ( 'D1' , 'Tempat_Tanggal_Lahir' ) -> setCellValue ( 'E1' , 'Email' ) -> setCellValue ( 'F1' , 'No_Telp' ) -> setCellValue ( 'G1' , 'Agama' ) -> setCellValue ( 'H1' , 'Kebangsaan' ) -> setCellValue ( 'I1' , 'Pendidikan' ) -> setCellValue ( 'J1' , 'Jenis_Kelamin' ) -> setCellValue ( 'K1' , 'Status' ) ; $ spreadsheet -> getActiveSheet ( ) -> setAutoFilter ( 'A1:K1' ) ; $ spreadsheet -> getActiveSheet ( ) -> getStyle ( 'A1:K1' ) -> getAlignment ( ) -> setHorizontal ( 'center' ) ; $ spreadsheet -> getActiveSheet ( ) -> getStyle ( 'A1:K1' ) -> getFont ( ) -> setBold ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getStyle ( 'A1:K1' ) -> getBorders ( ) -> getBottom ( ) -> setBorderStyle ( \ PhpOffice \ PhpSpreadsheet \ Style \ Border :: BORDER_THICK ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'A' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'B' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'C' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'D' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'E' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'F' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'G' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'H' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'I' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'J' ) -> setAutoSize ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getColumnDimension ( 'K' ) -> setAutoSize ( true ) ; $ rowIndex = 2 ; $ number = 1 ; foreach ( $ rslt_bio as $ rslt_data ) : $ spreadsheet -> setActiveSheetIndex ( 0 ) -> setCellValue ( 'A' . $ rowIndex , $ number ) -> setCellValue ( 'B' . $ rowIndex , $ rslt_data -> BioUniqueId ) -> setCellValue ( 'C' . $ rowIndex , $ rslt_data -> BioName ) -> setCellValue ( 'D' . $ rowIndex , $ rslt_data -> BioBirthPlace . ', ' . $ rslt_data -> BioBirthDate ) -> setCellValue ( 'E' . $ rowIndex , $ rslt_data -> BioEmail ) -> setCellValue ( 'F' . $ rowIndex , $ rslt_data -> BioPhoneNum ) -> setCellValue ( 'G' . $ rowIndex , $ rslt_data -> BioReligion ) -> setCellValue ( 'H' . $ rowIndex , $ rslt_data -> BioNationaly ) -> setCellValue ( 'I' . $ rowIndex , $ rslt_data -> BioEducation ) -> setCellValue ( 'J' . $ rowIndex , $ rslt_data -> BioGender ) -> setCellValue ( 'K' . $ rowIndex , $ rslt_data -> BioStatusMarital ) ; $ spreadsheet -> getActiveSheet ( ) -> getCell ( 'A' . $ rowIndex ) -> getStyle ( ) -> setQuotePrefix ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getCell ( 'B' . $ rowIndex ) -> getStyle ( ) -> setQuotePrefix ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getCell ( 'C' . $ rowIndex ) -> getStyle ( ) -> setQuotePrefix ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getCell ( 'D' . $ rowIndex ) -> getStyle ( ) -> setQuotePrefix ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getCell ( 'E' . $ rowIndex ) -> getStyle ( ) -> setQuotePrefix ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getCell ( 'F' . $ rowIndex ) -> getStyle ( ) -> setQuotePrefix ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getCell ( 'G' . $ rowIndex ) -> getStyle ( ) -> setQuotePrefix ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getCell ( 'H' . $ rowIndex ) -> getStyle ( ) -> setQuotePrefix ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getCell ( 'I' . $ rowIndex ) -> getStyle ( ) -> setQuotePrefix ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getCell ( 'J' . $ rowIndex ) -> getStyle ( ) -> setQuotePrefix ( true ) ; $ spreadsheet -> getActiveSheet ( ) -> getDefaultRowDimension ( ) -> setRowHeight ( 15.75 ) ; $ rowIndex ++ ; $ number ++ ; endforeach ; $ writer = new Xlsx ( $ spreadsheet ) ; header ( 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) ; header ( 'Content-Disposition: attachment;filename="Biodata-' . date ( 'dmY' ) . '.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 ; }
export to excel with library phpspreadsheet
export to excel with library phpspreadsheet
// geta all of data biodata // dec var of spreadsheet // set font // set size of font // -- config of columns // make filter in excel data // set align in column // set strong of text // make style border in column // -- config auto size // header('Content-Disposition: attachment;filename="EmployeeList-'.Accesscontrol_Helper::UniqIdReal().'.xlsx"'); // 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 // echo '<pre>'; // foreach ($rslt_bio as $rslt_data) { // 	print_r($rslt_data); // } // echo '</pre>';