找不到 Codeigniter PHPExcel Class 'PHPExcel_IOFactory'
Codeigniter PHPExcel Class 'PHPExcel_IOFactory' not found
我已经按照这里的教程学习了
https://arjunphp.com/how-to-use-phpexcel-with-codeigniter/
这里
http://www.ahowto.net/php/easily-integrateload-phpexcel-into-codeigniter-framework/
但是,我仍然收到 PHPExcel_IOFactory 未找到错误。我在这方面没有找到太多帮助。是否有替代 excel 插件或有办法解决这个问题?
这是我的控制器结构
public function __construct() {
parent::__construct();
$this->load->library('Excel');
}
这是我的控制器上传功能
$objReader= PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel= PHPExcel_IOFactory::load($document_folder."/".$file_name.".".$file_extension);
// $this->response($objPHPExcel);
$objPHPExcel=$objReader->load($document_folder."/".$file_name.".".$file_extension);
$totalrows=$objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
$objWorksheet=$objPHPExcel->setActiveSheetIndex(0);
for($i=2;$i<=$totalrows;$i++){ //2 is one row after the header rows
$title= $objWorksheet->getCellByColumnAndRow(0,$i)->getValue();
$first_name= $objWorksheet->getCellByColumnAndRow(1,$i)->getValue();
$last_name= $objWorksheet->getCellByColumnAndRow(2,$i)->getValue();
$date_of_birth= $objWorksheet->getCellByColumnAndRow(3,$i)->getValue();
$email=$objWorksheet->getCellByColumnAndRow(4,$i)->getValue();
$phone_number=$objWorksheet->getCellByColumnAndRow(5,$i)->getValue();
$company=$objWorksheet->getCellByColumnAndRow(6,$i)->getValue();
$input=array(
'title'=>$title,
'first_name'=>$first_name,
'last_name'=>$last_name,
'date_of_birth'=>$date_of_birth,
'email'=>$email,
'phone_number'=>$phone_number,
'company'=>$company,
);
您必须记住 PHPExcel 就是 PHP,CodeIgniter 也是如此。您不必通过另一个库加载 PHPExcel。事实上,它对你没有任何作用。我将所有 PHPExcel 文件放在 /third_party/ 中,然后执行此操作:
require_once( APPPATH . 'third_party/PHPExcel-1.8/Classes/PHPExcel.php');
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
请注意,在示例中我使用的是 v1.8
如果你想在多个方法中使用$objReader
,那么只需将其设为class 属性。所以 $this->objReader
相反。
我已经按照这里的教程学习了
https://arjunphp.com/how-to-use-phpexcel-with-codeigniter/
这里
http://www.ahowto.net/php/easily-integrateload-phpexcel-into-codeigniter-framework/
但是,我仍然收到 PHPExcel_IOFactory 未找到错误。我在这方面没有找到太多帮助。是否有替代 excel 插件或有办法解决这个问题?
这是我的控制器结构
public function __construct() {
parent::__construct();
$this->load->library('Excel');
}
这是我的控制器上传功能
$objReader= PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel= PHPExcel_IOFactory::load($document_folder."/".$file_name.".".$file_extension);
// $this->response($objPHPExcel);
$objPHPExcel=$objReader->load($document_folder."/".$file_name.".".$file_extension);
$totalrows=$objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
$objWorksheet=$objPHPExcel->setActiveSheetIndex(0);
for($i=2;$i<=$totalrows;$i++){ //2 is one row after the header rows
$title= $objWorksheet->getCellByColumnAndRow(0,$i)->getValue();
$first_name= $objWorksheet->getCellByColumnAndRow(1,$i)->getValue();
$last_name= $objWorksheet->getCellByColumnAndRow(2,$i)->getValue();
$date_of_birth= $objWorksheet->getCellByColumnAndRow(3,$i)->getValue();
$email=$objWorksheet->getCellByColumnAndRow(4,$i)->getValue();
$phone_number=$objWorksheet->getCellByColumnAndRow(5,$i)->getValue();
$company=$objWorksheet->getCellByColumnAndRow(6,$i)->getValue();
$input=array(
'title'=>$title,
'first_name'=>$first_name,
'last_name'=>$last_name,
'date_of_birth'=>$date_of_birth,
'email'=>$email,
'phone_number'=>$phone_number,
'company'=>$company,
);
您必须记住 PHPExcel 就是 PHP,CodeIgniter 也是如此。您不必通过另一个库加载 PHPExcel。事实上,它对你没有任何作用。我将所有 PHPExcel 文件放在 /third_party/ 中,然后执行此操作:
require_once( APPPATH . 'third_party/PHPExcel-1.8/Classes/PHPExcel.php');
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
请注意,在示例中我使用的是 v1.8
如果你想在多个方法中使用$objReader
,那么只需将其设为class 属性。所以 $this->objReader
相反。