Perhatian, artikel ini telah diupdate di http://www.proweb.co.id/articles/web_application/setup_phpexcel_yii.html .

Setelah kita berhasil membuat dan membaca dokumen Microsoft Excel 2007 dengan PHPExcel dan menggunakan bahasa pemrograman murni, saat ini kita akan mengembangkan supaya kita dapat menggunakan PHPExcel di lingkungan framework Yii.

Langkah-langkah menggunakan PHPExcel dalam framework Yii

  1. Pertama-tama silahkan salin phpExcel ke folder extensions seperti gambar berikut ini
  2. Silahkan edit PHPExcel/Autoloader, dan ganti register menjadi:
    public static function Register() {
    $functions = spl_autoload_functions();
      foreach($functions as $function)
        spl_autoload_unregister($function);
      $functions=array_merge(array(array(‘PHPExcel_Autoloader’, ‘Load’)), $functions);
      foreach($functions as $function)
        $x = spl_autoload_register($function);
      return $x;
    }//     function Register()
  3. Silahkan membuat coding misalnya:
        public function actionBuatExcel()
        {
             $objPHPExcel=Yii::createComponent(‘application.extensions.PHPExcel.PHPExcel’);
            $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue(‘A1’, ‘Ini di A No 1 ya’)
                        ->setCellValue(‘B2’, ‘kalau ini B 2’)
                        ->setCellValue(‘C1’, ‘Ini di C1’)
                        ->setCellValue(‘D2’, ‘Terakhir di D 2’);
            // Redirect output to a client’s web browser (Excel2007)
            header(‘Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’);
            header(‘Content-Disposition: attachment;filename=”contoh01.xlsx”‘);
            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’);
            unset($objPHPExcel);
        }

  4. Hasilnya:

Informasi lebih lanjut silahkan mengunjungi:
1. https://phpexcel.codeplex.com/documentation .
2. http://www.yiiframework.com/forum/index.php/topic/29225-tip-using-phpexcel-with-yii/ .

Perhatian, artikel ini telah diupdate di http://www.proweb.co.id/articles/web_application/setup_phpexcel_yii.html .

Kunjungi www.proweb.co.id untuk menambah wawasan anda.

PHPExcel pada Yii
× Ada yang dapat saya bantu ? Available on SundayMondayTuesdayWednesdayThursdayFridaySaturday