Class 'CI_Excel' not found

2019-06-14 11:37发布

问题:

When I load the library of excel I got this error. I follow everything in this Tutorial and still got some error

Im using codeigniter framework.

Class 'CI_Excel' not found in /var/www/html/warehouse/system/core/Common.php on line 196

this is my controller

class Dashboard extends CI_Controller {

public function __construct(){
    parent::__construct();

    $this->load->library('excel');
    $this->load->model('dashboard_model');
}

public function download(){
    $this->excel->setActiveSheetIndex(0);
    $this->excel->getActiveSheet()->setTitle('Warehouse List');
    //$this->load->database();
    $results = $this->dashboard_model->get_all();
    $this->excel->getActiveSheet()->fromArray($results);
    $filename='Warehouse List.xls';
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="'.$filename.'"');
    header('Cache-Control: max-age=0');
    $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
    $objWriter->save('php://output');
}
}

This is my Excel class in my Libraries

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');  

require_once APPPATH."/third_party/Classes/PHPExcel.php";

class Excel extends PHPExcel {

    public function __construct() {
        parent::__construct();
    }

}

回答1:

Try like this...Here working perfectly.

Setp1 : Download PHPExcel.(download it here: http://phpexcel.codeplex.com/)

Setp2 : Unzip or extract the downloaded PHPExcel lib files and copy whole folder in application/librares

Then

class Dashboard extends CI_Controller {

public function __construct(){
    parent::__construct();

   $this->load->library('PHPExcel/Classes/PHPExcel');
    $this->load->model('dashboard_model');
}
public function create(){
//Create A PHPExcel Object
        $phpexcel=new PHPExcel();
//code more

If you want to follow the way of tutorial..Just try this...

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');  

require_once APPPATH."third_party/Classes/PHPExcel.php";//Your problem was here

class Excel extends PHPExcel {

    public function __construct() {
        parent::__construct();
    }

}