Problem reading files from server with Excel2007 Writer

Topics: User Forum
Mar 16, 2011 at 9:16 PM
Edited Mar 16, 2011 at 9:17 PM

PHP v 5.2.14

PHPExcel v 1.7.6

Magento v 1.4

I'm trying to read a generated CSV file (not created with PHPExcel) and output it as an .xls file with PHPExcel. I've run into a number of problems with the autoloader because I am trying to utilize this under Magento 1.4, which has its own autoloader.

I can get PHPExcel to start the output process but for some reason it says it can't find the CSV file, but I can clearly see the CSV generated on the server.

Here is a snippet of the ouput code with the path:

$objWriter2007 = PHPExcel_IOFactory::createWriter(Mage::getBaseDir('export').'/'.$file, 'Excel2007');

This results in an error "Firefox can't find the file at..." and then some path that is NOT what it should be for the file.

Anybody have any ideas or used this library from within Magento?

Mar 17, 2011 at 11:29 AM

This discussion on problems with the Joomla autoloader interfering with the PHPExcel autoloader may offer some help. There is also some information on the autoloader in the manual.

Mar 17, 2011 at 5:45 PM

Thanks Mark. I did happen to find that post during my initial search, but I was hesitant to modify the core files of my e-commerce platform. I'll have to check to see if it is using the spl_register method or not. I have also dug into the manual regarding the autoloader, which essentially says the same thing.

It seems like I'm having a path problem, perhaps I can modify the PHPExcel files accordingly.

Mar 17, 2011 at 7:20 PM

Here is an example:

$path_to_PHP_ExcelReader = "PHPExcel/PHPExcel.php";
require_once $path_to_PHP_ExcelReader;
require_once 'PHPExcel/PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();

Error: Fatal error: Class 'PHPExcel_Worksheet' not found