PHPExcel integration into Zend Framework
Place the PHPExcel library into the /library folder, like this:
/application
...
/library
/PHPExcel
/PHPExcel.php
Next, in your application.ini config file, add the following:
autoloaderNamespaces[] = "PHPExcel_"
autoloaderNamespaces[] = "PHPExcel"
That should do it. Autoloader takes care of the rest, and you can just start using the example code to read an Excel file.
Update: Added the extra autoloaderNamespace as suggested by commenters
Related videos on Youtube
lony
I'm a software consultant from Germany mostly working in "THE" cloud. I try to teach myself more about machine learning and functional programming on the side.
Updated on June 04, 2022Comments
-
lony almost 2 years
how can I integrate the PHPExcel into my Zend app.
My actual folder structure is the following:
/application controllers views etc... /library My Zend PHPExcel /public index.php
I already include 'My' libs by using (in index.php):
require_once 'Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('My_');
Now I also want to use PHPExcel inside one of my controllers like:
$exc = PHPExcel_IOFactory::load('test.xls'); $excelWorksheet = $exc->getActiveSheet();
What do I have to do to make it work and get rid of the
Class 'PHPExcel_IOFactory' not found
Exception?Thank you.
-lonyP.S.: A simple
$autoloader->registerNamespace('PHPExcel_');
is not working. I tested it. -
wimvds about 13 yearsWell, from the snippet you posted above your problem is quite obvious, move all of the PHPExcel source one level up, so IOFactory.php is located in library/PHPExcel/IOFactory.php instead of library/PHPExcel/PHPExcel/IOFactory.php. That should do the trick (and you can ditch the require_once).
-
lony about 13 yearsAs described in my question I tried to use
$autoloader->registerNamespace('PHPExcel_');
and it was not working. Your solution only move the setting from theindex.php
toapplication.ini
, but it is still not running. -
Miljar about 13 yearsDo you have the same setup in your /library folder? The base PHPExcel.php file is right under /library, and then the rest of the classes is under /library/PHPExcel. I implemented this just yesterday, without any problems
-
Stephen Fuhry about 13 yearsThe only problem with this is that it makes adding PHPExcel as an svn:external either difficult (separate external for PHPExcel.php), or impossible.
-
lony almost 13 yearsHm, looks really like the solution I wanted. I try it out. Thank you.
-
Andron almost 13 yearsSo I placed PHPExcel library into the /library folder, added line to ini file and (!) updated my index.php file:
set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'),realpath(APPLICATION_PATH . '/../library/PHPExcel'),get_include_path())));
-
cwhisperer over 12 yearsI did it this way, but when in the controller I call $xlsObj = new PHPExcel(); it returns the error Fatal error: Class 'PHPExcel' not found in...
-
signpainter almost 12 yearsFor me the above solution didn't work either, resulting in class not found exception. Adding not only
autoloaderNamespaces[] = "PHPExcel_"
but alsoautoloaderNamespaces[] = "PHPExcel"
did the trick for me.