createReaderForFile not working corretly

Topics: User Forum
Dec 10, 2010 at 3:21 PM
Edited Dec 10, 2010 at 3:36 PM

got the following code:

    set_include_path(get_include_path() . PATH_SEPARATOR . 'PHPExcel/Classes/');
require_once 'PHPExcel/Classes/PHPExcel.php';
require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php';
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;
PHPExcel_Settings::setCacheStorageMethod($cacheMethod);
$objReader = PHPExcel_IOFactory::createReaderForFile($file);
$objReader->setReadDataOnly(true); // line 639

 

When I run under localhost it works correctly, however, when I run on my webhost, I get this error:
Fatal error: Call to undefined method PHPExcel_Reader_CSV::setReadDataOnly() in
             /home/listinve/public_html/libs/class/Inventory.class.php on line 639

I am using 1.7.4 on BOTH installations.

$file is "133_inventory DEC-9.xlsx"; the file being parsed is an Excel XLSX file. I do not understand why it would be creating a CSV reader.

file uploaded to this workitem: http://phpexcel.codeplex.com/workitem/14857

Any ideas?

Coordinator
Dec 10, 2010 at 5:46 PM

PHPExcel will create a CSV Reader when using the PHPExcel_IOFactory::createReaderForFile() method if the file cannot be identified as any of the other supported file types. An xlsx file will fail the Excel2007 Reader identification tests for a number of reasons, defined in the canRead() method for the reader. In the case of an xlsx file that can be read on one server, but not on another, this is most likely because ZipArchive class is not available on the server where it fails.

Dec 10, 2010 at 10:21 PM
Edited Dec 10, 2010 at 10:25 PM

I am not sure if ZipArchive is istalled.

I have PHP Version 5.2.12.

But php_info() doesn't show ZipArchive, just Zip and GZip.

Read PHP Info

And it is not installed locally with PHP Version 5.2.11.

Coordinator
Dec 10, 2010 at 10:33 PM

ZipArchive is the class implemented by the zip extension, so it should be there.

Can you try executing the following code:

$objReader = new PHPExcel_Reader_Excel2007();
$valid = $objReader->canRead($file);
var_dump($valid);

If this returns a boolean false, then look at the code in the canRead() method and put in some echo statements to identify just which test it's failing on.

Dec 14, 2010 at 5:53 PM

That code returns bool(true)

Now, when I run the code above in a separate unit (as shown below), I don't get the error I observed in my original post but I get this error:

 

Fatal error: Call to a member function attach() on a non-object in /home/listinve/public_html/PHPExcel/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php on line 99

 

 

  $file = 'file_uploads/133_inventory DEC-9.xlsx';
  set_include_path(get_include_path() . PATH_SEPARATOR . 'PHPExcel/Classes/');
  require_once 'PHPExcel/Classes/PHPExcel.php';
  require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php';

  $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;
  PHPExcel_Settings::setCacheStorageMethod($cacheMethod);
  $objReader = PHPExcel_IOFactory::createReaderForFile($file);
  $objReader->setReadDataOnly(true); 
$objPHPExcel = $objReader->load($file); $objWorksheet = $objPHPExcel->getActiveSheet(); $objPHPExcel->disconnectWorksheets(); unset($cacheMethod); unset($objReader); unset($objPHPExcel);

 

 

What could be causing this now?