PHP Excel via CodeIgniter

Permisi agan2 dan mastah2 mau tanya, ada yang tahu soal PHPExcel ga? saya punya ribuan data yang mau di export ke excel tapi saya maunya data itu di bagi per part

ada yang bisa bantu, nih script sementara ane :

public function exportStudents() {
	ini_set("memory_limit", "500M");
	$field = $this->export->selectField("biodata");
	$data = $this->export->selectData("biodata");

	// print_r($field);exit;

	if(count($data) == 0){
		echo "<script>alert('Students Data is Empty!');location.href='".site_url('admin/export_data')."'</script>";
	}

	$phpExcel = new PHPExcel();
	//set properties
	$phpExcel->getProperties()
			 ->setCreator("Directorate of Central ICT")
			 ->setTitle("Personal Data of Students");
	$objSet = $phpExcel->setActiveSheetIndex(0);
	$objGet = $phpExcel->getActiveSheet();

	$objGet->setTitle("Bio Sheets"); //Sheet Title
	$objGet->getStyle("A1:Y1")->applyFromArray(
						array(
							"fill" => array(
								"type" => PHPExcel_Style_Fill::FILL_SOLID,
								"color" => array("rgb" => "2c3e50")
								),
							"font" => array(
								"color" => array("rgb" => "ecf0f1")
								)
							)
						);

	//Set Table Header
	$column = array(
		"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y"
	);//ActiveColumn
	//Field Name
	foreach ($field as $key) {
		$colValue[] = $key->name;
	}

	for ($i=0; $i < sizeof($column); $i++) {
		$objSet->setCellValue($column[$i]."1", $colValue[$i]); //Fill Field Name into Column
	}
	//Fill Column with Data
	$start = 2; //Row Start at
	foreach ($data as $key) {
		$objSet->setCellValue("A".$start, $key['id_sis']);
		$objSet->setCellValue("B".$start, $key['nim']);
		$objSet->setCellValue("C".$start, $key['Nama_Mahasiswa']);
		$objSet->setCellValue("D".$start, $key['tempat_lahir']);
		$objSet->setCellValue("E".$start, $key['tanggal_lahir']);
		$objSet->setCellValue("F".$start, $key['Sex']);
		$objSet->setCellValue("G".$start, $key['Agama']);
		$objSet->setCellValue("H".$start, $key['asal_smu']);
		$objSet->setCellValue("I".$start, $key['thn_angkatan_smu']);
		$objSet->setCellValue("J".$start, $key['jurusan_smu']);
		$objSet->setCellValue("K".$start, $key['Alamat']);
		$objSet->setCellValue("L".$start, $key['kodepos']);
		$objSet->setCellValue("M".$start, $key['telepon']);
		$objSet->setCellValue("N".$start, $key['kode']);
		$objSet->setCellValue("O".$start, $key['tingkat']);
		$objSet->setCellValue("P".$start, $key['kelas']);
		$objSet->setCellValue("Q".$start, $key['kodecabang']);
		$objSet->setCellValue("R".$start, $key['NPM']);
		$objSet->setCellValue("S".$start, $key['TahunAngkatan']);
		$objSet->setCellValue("T".$start, $key['status']);
		$objSet->setCellValue("U".$start, $key['NomorTranskrip']);
		$objSet->setCellValue("V".$start, $key['jeniskelas']);
		$objSet->setCellValue("W".$start, $key['foto']);
		$objSet->setCellValue("X".$start, $key['ID']);
		$objSet->setCellValue("Y".$start, $key['email']);
		$phpExcel->getActiveSheet()->getStyle('Y1:Y'.$start)->getNumberFormat()->setFormatCode('0');
		$start++;
	}

	$phpExcel->getActiveSheet()->setTitle("Data Exported");
	$phpExcel->setActiveSheetIndex(0);
	$filename = urlencode("StudentsData_".date("d-m-Y").".xls");
	header('Content-Type: application/vnd.ms-excel'); //mime type
	header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
	header('Cache-Control: max-age=0'); //no cache
	$objWriter = IOFactory::createWriter($phpExcel, 'Excel5');
	$objWriter->save('php://output');

	ini_set("memory_limit", "16M");
	redirect('admin/export_data','refresh');
	}

avatar ilhamdsofyan
@ilhamdsofyan

25 Kontribusi 3 Poin

Dipost 7 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban