Difficulty setting up ExcelPHP

I am trying to use require to load the ExcelPHP API to work with 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 try to run the following code:

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

$ mySheet = new PHPExcel ();

I am getting fatal error:

Note: Using 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 tried commenting out line 31 in the Autoloader.php file and it prevents 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? Thank you in advance!

+3


source to share


3 answers


Load the PHPExcel class in your request once, not the autoloader (as Seth said). Case sensitivity is also a potential problem, because your scripts won't flow without errors if you don't get them right:

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

      

it should be



require_once('classes/PHPExcel.php');

      

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

+3


source


Instead of the current require statement, you should call

require_once('classes/PHPExcel.php');

      



This file defines the constant PHPEXCEL_ROOT

you are missing and then calls require_once()

in the startup file. It also loads the main class PHPExcel

one that the entire library uses.

+3


source


It might be too late as PHPExcel turns to the PHPSpread page, but if you're still using PHPExcel and want to use an autoloader, all you have to do is define the PHPExcel root before the autoloader is required.

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

      

I am using this composer in my own mvc framework

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

      

0


source







All Articles