Today, using TP PHPExcel to do excel import and export, error:

Class ‘Admin\Action\PHPExcel_IOFactory’ not found

I used:

import("Org.Util.PHPExcel");
import("Org.Util.PHPExcel.Writer.Excel5");
import("Org.Util.PHPExcel.IOFactory.php");
$objReader = PHPExcel_IOFactory::createReader('Excel5');
Copy the code

Check out the import code

var_dump(class_exists(‘PHPExcel_IOFactory’)); // Return true…

That’s a strange question. Check the import source code and import the class file at the end of the output, as follows:

/private/var/www/backend/ThinkPHP/Library/Org/Util/PHPExcel.class.php /private/var/www/backend/ThinkPHP/Library/Org/Util/PHPExcel/Writer/Excel5.class.php / private/var/WWW/backend/ThinkPHP/Library/Org/Util/PHPExcel IOFactory/PHP class. PHP looked at because ‘import ()’, Import () suffixes files with ‘.class.php’ by default. At the same time, the ‘.’ is replaced by ‘/’, resulting in incorrect file path resolution.

Solution:

Online call the way is not correct, correct way:

import("Org.Util.PHPExcel");
import("Org.Util.PHPExcel.Writer.Excel5", '', '.php');
import("Org.Util.PHPExcel.IOFactory", '', '.php');
Copy the code

The imported files should be ok this time

This may be related to version 3.2.3

One more special note:

$objReader = \PHPExcel_IOFactory::createReader(‘Excel5’);

Must start with “, namespace or something!