首页 > 技术文章 > thinkphp5 PHPExcel 引入与报错解决

jasonLiu2018 2019-12-25 11:28 原文

文件目录

 

 

 

引入文件

use think\facade\App;
require_once App::getRootPath().'/extend/PHPExcel/PHPExcel.php';

 

 

 

 

报错:

PHPExcel报错ZipArchive::locateName():

Excel版本问题。
解决方法:判断当前版本。
//   \PHPExcel_IOFactory  前面缺少斜杠会报错  找不到类
$objReader = \PHPExcel_IOFactory::createReader('Excel2007'); 

if(!$objReader->canRead($file_name)){
  $objReader = \PHPExcel_IOFactory::createReader('Excel5');
}
  $objPHPExcel = $objReader->load($file,$encode='utf-8');

亲试,有效。

 

PHPExcel_IOFactory' not found

//   \PHPExcel_IOFactory  前面缺少斜杠会报错  找不到类

$objReader = \PHPExcel_IOFactory::createReader('Excel5');

推荐阅读