PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 23, 2022

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

 October 23, 2022     kohana, php, phpexcel     No comments   

Issue

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'); 


Answered By - Mark Baker
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing