Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel integration into Zend Framework

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.
-lony

P.S.: A simple $autoloader->registerNamespace('PHPExcel_'); is not working. I tested it.

like image 533
lony Avatar asked Jan 20 '11 01:01

lony


People also ask

Is Phpexcel deprecated?

PHP Excel was officially deprecated in 2017 and permanently archived in 2019. PHP Excel has not be maintained for years and must not be used anymore. All users must migrate to its direct successor PhpSpreadsheet, or another alternative.

Is Zend Framework Good?

The Zend framework makes web development easy, and can complete tasks quickly and efficiently. The ZF doesn't come as a whole unit that doesn't budge at all. It is decoupled, meaning the components come as an individual library , so the developers need to load only the required components.

What is Zend framework used for?

Zend Framework is a collection of professional PHP packages with more than 570 million installations. It can be used to develop web applications and services using PHP 5.6+, and provides 100% object-oriented code using a broad spectrum of language features.


1 Answers

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

like image 59
Miljar Avatar answered Oct 17 '22 02:10

Miljar