找不到“CI_Excel”类

时间:2017-01-19 05:07:48

标签: php excel codeigniter phpexcel

当我加载excel库时出现此错误。我按照Tutorial中的所有内容进行了操作,但仍然出现了一些错误

我正在使用codeigniter框架。

  

第196行的/var/www/html/warehouse/system/core/Common.php中找不到“CI_Excel”类

这是我的控制器

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');
}
}

这是我的图书馆中的Excel课程

<?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 个答案:

答案 0 :(得分:1)

尝试这样......这里工作得很完美。

Setp1:下载PHPExcel。(在此下载:http://phpexcel.codeplex.com/

Setp2:解压缩或解压缩下载的PHPExcel lib文件并复制application/librares

中的整个文件夹

然后

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

如果你想按照教程的方式进行..试试这个......

<?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();
    }

}