PHPExcel integration into Zend Framework

前端 未结 6 718
忘了有多久
忘了有多久 2021-01-12 12:00

how can I integrate the PHPExcel into my Zend app.

My actual folder structure is the following:

/application
  controllers
  views  
  etc...
/librar         


        
相关标签:
6条回答
  • 2021-01-12 12:15

    It needs to be in your include path.

    If you ever need a custom autoloader for other libraries that don't follow PSR-0, there's this too: Autoload PhpThumb with Zend Framework (disclaimer: I'm the author).

    0 讨论(0)
  • 2021-01-12 12:19

    Additionally I added a "\" on the line where PHPExcel_IOFactory uses In Controller Class:

    public function reporteauditoriaAction()
    {
        $objPHPExcel = new \PHPExcel();
        $objPHPExcel->createSheet();
        $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Alejin Wbn');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
        $objWriter->save("pruebaPhpExcelZend.xlsx"); 
        //$objPHPExcel->disconnectWorksheets();
        //unset($objPHPExcel);
        $consulta= "Reporte Auditoria, Reconocio los Archivos";
        $vista = new ViewModel(array( "consulta"=>$consulta));
        return $vista;        
    }
    
    0 讨论(0)
  • 2021-01-12 12:22

    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

    0 讨论(0)
  • 2021-01-12 12:27

    I have same issue and i solved it update the composer and in my project folder phpoffice saved inside the vendor module (not in lib). And adding "\" on the PHPExcel_IOFactory whereever you seen.

    0 讨论(0)
  • 2021-01-12 12:30

    I know it's 2 years since the question is asked but it may help someone; the easiest way ( not the optimal) is to extract the PHPExcel folder in your Public and then just use the old way ex; (in your controller actions):

                    include 'PHPExcel.php';
                    include 'PHPExcel/Writer/Excel2007.php';
    
                    $myobject = new PHPExcel();
    
    0 讨论(0)
  • 2021-01-12 12:37

    I found one solution:

    require_once 'PHPExcel/PHPExcel/IOFactory.php';

    If somebody has a better one, please keep posting!

    @BoltClock: Thanks for updating the Tags.

    0 讨论(0)
提交回复
热议问题