Неустранимая ошибка CodeIgniter: класс «PHPExcel_IOFactory» не найден

Я работаю над проектом, в котором мне нужно импортировать данные из файла Excel (.xlsx) в таблицу в базе данных.

Я уже написал код для контроллера import.php:

if($this->input->post('send')=='add'):
    $config['upload_path'] =  'media/result';
    //Only allow this type of extensions 
    $config['allowed_types'] = 'xlsx|csv';
    $this->load->library('upload', $config);
    // if any error occurs 
    if ( ! $this->upload->do_upload('upload_file1'))
    {
        $error = array('error' => $this->upload->display_errors());
    }
    //if successfully uploaded the file 
    else
    {
        $upload_data = $this->upload->data();
        $file_name = $upload_data['file_name'];
        //load library phpExcel
        $this->load->library("Excel");
        //here i used microsoft excel 2007
        $objReader = PHPExcel_IOFactory::createReader('Excel2007');
        //set to read only
        $objReader->setReadDataOnly(true);
        //load excel file
        $objPHPExcel = $objReader->load('upload/'.$file_name);
        $sheetnumber = 0;
        foreach ($objPHPExcel->getWorksheetIterator() as $sheet)
        {
            $s = $sheet->getTitle(); // get the sheet name 
            $sheet= str_replace(' ', '', $s); // remove the spaces between sheet name 
            $sheet= strtolower($sheet); 
            $objWorksheet = $objPHPExcel->getSheetByName($s);
            $lastRow = $objPHPExcel->setActiveSheetIndex($sheetnumber)->getHighestRow(); 
            $sheetnumber++;

            if($sheet=='student')// if sheet name is student 
            {
                //loop from first data until last data
                for($j=2; $j<=$lastRow; $j++)
                {
                    $classement = $objWorksheet->getCellByColumnAndRow(1,$j)->getValue();
                    $dossard = $objWorksheet->getCellByColumnAndRow(2,$j)->getValue();
                    $nom = $objWorksheet->getCellByColumnAndRow(3,$j)->getValue();
                    $sexe = $objWorksheet->getCellByColumnAndRow(4,$j)->getValue();
                    $cat = $objWorksheet->getCellByColumnAndRow(5,$j)->getValue();
                    $pays = $objWorksheet->getCellByColumnAndRow(6,$j)->getValue();
                    $temps = $objWorksheet->getCellByColumnAndRow(7,$j)->getValue();
                    $tempsreel = $objWorksheet->getCellByColumnAndRow(8,$j)->getValue();
                    $ecart = $objWorksheet->getCellByColumnAndRow(9,$j)->getValue();
                    $moyenne = $objWorksheet->getCellByColumnAndRow(10,$j)->getValue();
                    if($classement != '' || $dossard != ''|| $nom != ''|| $sexe != '' || $cat != '' || $pays != '' || $temps != '' || $tempsreel != '' || $ecart != '' || $moyenne != '')
                    {
                        $excel = array(
                            'Classement'=>$classement,
                            'dossard'=>$dossard,
                            'nomprenom'=>$nom,
                            'sexe'=>$sexe,
                            'cat'=>$cat,
                            'pays'=>$pays,
                            'temps'=>$temps,
                            'temspreel'=>$tempsreel,
                            'ecart'=>$ecart,
                            'moyenne'=>$moyenne
                        );
                        $this->db->insert('mt_result',$excel);
                        $result=($this->db->affected_rows()!= 1)? false:true;
                        if($result == true)
                        {
                            $this->session->set_flashdata('msg', 'Member Details Uploaded Successfully');
                            redirect('Result/');
                        }
                        else
                        {
                            $this->session->set_flashdata('msg1', 'Member Details Uploading Failed');
                            redirect('Result/');
                        }
                    }
                    else
                    {
                        $this->session->set_flashdata('msg1', 'Failed To Upload!Contents are not Matched');
                        redirect('Result/');
                    }		
                }// loop ends 
            }
        }
    }
endif;	

Всякий раз, когда я вызываю этот контроллер, я получаю следующую ошибку:

Произошла ошибка PHP

Серьезность: ошибка

Сообщение: Класс 'PHPExcel_IOFactory' не найден

Имя файла: контроллеры/Result.php

Номер строки: 229

Как решить эту проблему?


person user3633379    schedule 04.03.2016    source источник


Ответы (1)


Попробуйте использовать $this->Excel->createReader('Excel2007') вместо PHPExcel_IOFactory::createReader('Excel2007')

person Maninderpreet Singh    schedule 04.03.2016
comment
я пробую, но получаю эту ошибку: Сообщение: Неопределенное свойство: Результат::$Excel - person user3633379; 04.03.2016
comment
Это моя библиотека Excel: ‹?php if (!defined('BASEPATH')) exit('Прямой доступ к сценарию не разрешен'); require_once ПУТЬ ПРИЛОЖЕНИЯ./ Third_Party/PHPExcel.php; require_once ПУТЬ ПРИЛОЖЕНИЯ . / Third_Party/PHPExcel/IOFactory.php; класс Excel расширяет PHPExcel { public function __construct() { parent::__construct(); } } - person user3633379; 04.03.2016
comment
require_once('excel-библиотека/классы/PHPExcel.php'); $excelFile = xlsx/data.xlsx; $pathInfo = информация о пути($excelFile); $type = $pathInfo['extension'] == 'xlsx' ? «Excel2007»: «Excel5»; $objReader = PHPExcel_IOFactory::createReader($type); $objPHPExcel = $objReader-›load($excelFile); foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { $worksheets[$worksheet->getTitle()] = $worksheet->toArray(); } это мой код для чтения Excel - person Maninderpreet Singh; 04.03.2016