YII FRAMEWORK TUTORIAL Andrea Stevens Karnyoto (CV. Anugrah Empat Pilar) andrekarnyoto@yahoo.com/andre@empatpilarweb.co.

id(FB: Karnyoto Andre ) Cara menggunakan PHPExcel di yii framework

Nah berikut ini adalah potongan program yang diletakkan disebuah controller sehingga pada saat action diekekusi maka akan ada perintah untuk mendonload file tersebut : Untuk penginstalan PHPExcel sudah dijelaskan pada bagian sebelumnya : O iya jangan lupa bikin template excelnya dulu lalu di taruh di \template, buat templatenya pake excel 2007 koq.
public function actionKhsperorang($id) { $objReader = Yii::app()->excel; $objReader = PHPExcel_IOFactory::createReader('Excel2007'); $objPHPExcel = $objReader->load("template/khsperorang.xlsx"); $model = $this->loadModelKhs($id); $nama = $model->Mahasiswa->NamaMahasiswa; $nim = $model->Nim; $jurusan = $model->Mahasiswa->Jurusannya->NamaJurusan; $semester = $model->Semester->Semesteran; $objPHPExcel->getActiveSheet()->setCellValue('NAMA', $nama); $objPHPExcel->getActiveSheet()->setCellValue('nim', chr(39) . $nim); $objPHPExcel->getActiveSheet()->setCellValue('JURUSAN', $jurusan); $objPHPExcel->getActiveSheet()->setCellValue('SEMESTER', chr(39) . $semester); $md = new Tablekhsdetail(); $modeldetail = $md->searchdetail($id)->getData(); $baseRow = 14; $r = 0; foreach ($modeldetail as $rowx) { $row = $baseRow + $r; $objPHPExcel->getActiveSheet()->insertNewRowBefore($row, 1); $objPHPExcel->getActiveSheet()->mergeCells('C' . $row . ':' . 'J' . $row); $objPHPExcel->getActiveSheet()->setCellValue('B' . $row, $r + 1); $objPHPExcel->getActiveSheet()->setCellValue('C' . $row, TableMataKuliah::model()->findByPk($rowx['KodeMataKuliah'])->NamaMataKuliah); $objPHPExcel->getActiveSheet()->setCellValue('K' . $row, TableMataKuliah::model()->findByPk($rowx['KodeMataKuliah'])->Sks); $objPHPExcel->getActiveSheet()->setCellValue('L' . $row, $rowx['Hasil']); $objPHPExcel->getActiveSheet()->setCellValue('M' . $row, $this>GetIfM($row)); $objPHPExcel->getActiveSheet()->setCellValue('N' . $row, '=M' . $row . '*K' . $row); $r++; } $objPHPExcel->getActiveSheet()->removeRow($baseRow-1,1); $objPHPExcel->getActiveSheet()->setCellValue('K' .($row + 1), '=SUM(K' . ($baseRow-1) . ':K' . ($row-1) .')'); $objPHPExcel->getActiveSheet()->setCellValue('N' .($row + 1), '=SUM(N' . ($baseRow-1) . ':N' . ($row-1) .')'); $objPHPExcel->getActiveSheet()->setCellValue('K' .($row + 2), '=ROUND(N'

YII FRAMEWORK TUTORIAL Andrea Stevens Karnyoto (CV. Anugrah Empat Pilar) andrekarnyoto@yahoo.com/andre@empatpilarweb.co.id(FB: Karnyoto Andre )
.($row + 1) .'/'. 'K' .($row + 1) .',2)' ); header('Content-Type: application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="'.$nama.'-'.$nim.'.xlsx"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); }

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer: Get 4 months of Scribd and The New York Times for just $1.87 per week!

Master Your Semester with a Special Offer from Scribd & The New York Times