0

I followed this link - PHPExcel integration into Zend Framework

Copied files/folder as mentioned -

> /library
>     /PHPExcel
>     /PHPExcel.php

And added in application.ini file-

autoloaderNamespaces[] = "PHPExcel_"
autoloaderNamespaces[] = "PHPExcel"

Now under mysite\application\modules\admin\controllers and in MysiteController.php I am using this, in this manner -

public function getExcelDataAction() 
{
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->setActiveSheetIndex(0)->mergeCells('A1:D1');
    $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Swapnesh');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $filename = "my-data-sheet".".xlsx";
    $objWriter->save($filename);    
}

Following error occurred -

Fatal error: Class 'PHPExcel' not found in C:\webserver\mysite\application\modules\admin\controllers\MysiteController.php on line 526

Let me know how can i make it working in Zend( beginner in zend)

Community
  • 1
  • 1
swapnesh
  • 26,318
  • 22
  • 94
  • 126
  • can you try `$objPHPExcel = new PHPExcel_PHPExcel();` – Nandakumar V Feb 27 '13 at 10:07
  • @NandakumarV Sure let me gave it a try – swapnesh Feb 27 '13 at 10:13
  • @NandakumarV sorry not working ..throwing this class not exists PHPExcel_PHPExcel – swapnesh Feb 27 '13 at 10:18
  • is the `PHPExcel` added in the included paths. * use `print_r(get_include_path())` – Nandakumar V Feb 27 '13 at 10:27
  • if the class does not have the naming convention (FOLDER_CLASS) than include it by your own: `include PATH_TO_LIB.'/PHPExcel/PHPExcel.php';` – bitWorking Feb 27 '13 at 10:35
  • or write your own autoloader and push it into Zend's one with `pushAutoloader`. [http://framework.zend.com/manual/1.12/en/zend.loader.autoloader.html](http://framework.zend.com/manual/1.12/en/zend.loader.autoloader.html) – bitWorking Feb 27 '13 at 10:38
  • @redreggae thx it worked for me using autoloader technique :) – swapnesh Feb 27 '13 at 10:43
  • possible duplicate of [PHPExcel class not found in Zend Autoloader](http://stackoverflow.com/questions/8816426/phpexcel-class-not-found-in-zend-autoloader) – David Weinraub Feb 27 '13 at 12:01
  • Actually, it looks like the structure of PHPExcel has changed since that answer I referenced. But the general technique of pushing a custom autoloader onto the ZF autoloader stack still applies for libs that are not PSR-0 compliant. – David Weinraub Feb 27 '13 at 12:06

1 Answers1

1

For my implementation PHPExcel was the last thing to fire so I didn't need Zends own autoloader anymore after initiation PHPExcel and thus created my own workaround like this.

//In controller, I call a norlmal Zend Model

$excelModel = new Application_Model_Excel();

//The exelmodel (which lives in Application/Models/Excel.php) looks like this

<?php
spl_autoload_unregister(array('Zend_Loader_Autoloader','autoload'));
require_once('PHPExcel/Classes/PHPExcel.php');
class Application_Model_Excel extends PHPExcel
{


}
?>

This is most certainly not the best way to do it, but works without a hitch in my app

Lobo
  • 566
  • 1
  • 7
  • 20