Search code examples
phpkohanaphpexcel

Why does PHPExcel try to create a class name out of the Excel file name when used inside Kohana?


I am trying to build the PHPExcel library into an application built with the Kohana PHP framework.

In a test app outside the Kohana framework, I can create and read Excel files fine.

And inside the Kohana application, creating a file works:

$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Test Generator")
    ->setTitle("Test Excel5 File");
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Hello');
$objPHPExcel->getActiveSheet()->setTitle('Test Sheet');
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('test123.xls'); //created in the root directory of application

However, when inside the Kohana framework when I try to read a file with this code:

$objReader = PHPExcel_IOFactory::createReader('test123.xls');

I get this error:

alt text

How can I prevent PHPExcel/Kohana from trying to create a class name out of the Excel file name?


Solution

  • The createReader() method expects the filetype as a parameter (eg Excel2007, Excel5, Excel2003XML, OOCalc, Gnumeric, CSV), not the filename.

    // Use the IOFactory to instantiate a reader of the correct type
    $objReader = PHPExcel_IOFactory::createReader('Excel5'); 
    // Use the reader to load the file, and return a PHPExcel object
    $objPHPExcel = $objReader->load('test123.xls');