3

I am attempting to use require to load the ExcelPHP API to manipulate CSV spreadsheets. I am using EasyPHP 12.1 with PHP 5.4.6, Apache 2.4.2, MySQL 5.5.27 and Xdebug 2.2.1. I am on Windows 7.

When I attempt to run the following code:

require_once('classes/PHPexcel/Autoloader.php');

$mySheet = new PHPExcel();

I get a fatal error:

Notice: Use of undefined constant PHPEXCEL_ROOT - assumed 'PHPEXCEL_ROOT' in C:\Program Files\EasyPHP-12.0\www\Classes\Classes\PHPExcel\Autoloader.php on line 73

Fatal error: Class 'PHPExcel_Shared_ZipStreamWrapper' not found in C:\Program Files\EasyPHP-12.0\www\Classes\Classes\PHPExcel\Autoloader.php on line 31

I have tried commenting out line 31 in the Autoloader.php file, and that prevents the the fatal error but then the API won't work and PHP doesn't recognize the PHPExcel class.

Can someone please help me figure out how to get my library to work? Thanks in advance!

3 Answers 3

4

Load the PHPExcel class in your require once, rather than the Autoloader (as Seth) has said. Case-sensitivity is also a potential problem, because your scripts won't transfer without error unless you get it right:

require_once('classes/PHPexcel/Autoloader.php');

should be

require_once('classes/PHPExcel.php');

and the library is PHPExcel, not ExcelPHP as you call it in your subject line

Sign up to request clarification or add additional context in comments.

Comments

3

Instead of your current require statement, you should call

require_once('classes/PHPExcel.php');

That file defines the constant PHPEXCEL_ROOT that you are missing, and then calls require_once() on the autoloader file. It also loads the main class PHPExcel that the whole library uses.

2 Comments

Thank you so much! That fixed everything.
You are welcome. Be sure to mark the response from @MarkBaker as the right answer.
0

This may have come a bit too late as PHPExcel has pivoted to PHPSpreadsheet but if you're still using PHPExcel and you want to use the autoloader, all you have to do is define the PHPExcel root before requiring autoloader.

define('PHPEXCEL_ROOT', dirname(__FILE__).'/');

i use it composer in my custom mvc framework

require_once ROOT . '/vendor/autoload.php';
PHPExcel_Autoloader::Register();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.