Problem Creating Active Worksheet Object

Topics: Developer Forum
Apr 25, 2010 at 8:21 PM

I am getting an error trying to access the worksheet object.  I get the following error:  Fatal error: Call to undefined method PHPExcel_Reader_Excel2007::getActiveSheet() in /Applications/XAMPP/xamppfiles/htdocs/com.sonarioadmin/application/php/sonarioAdminServices/loadData.php on line 182

The following is a code snippet:

$objReader = PHPExcel_IOFactory::createReader('Excel2007');

 $objReader->setReadDataOnly(true); $objReader->load($toFile);

$objWorksheet = $objReader->getActiveSheet();


This code comes directly from the documentation.  Please advise.

Apr 25, 2010 at 8:37 PM

Whereabouts is this code in the documentation?

$objReader is the file reader, and a call to the load() method returns a PHPExcel object, which is the workbook itself. Worksheets are part of the workbook. Simply loading, without assigning the returned PHPExcel object simply discards what you have loaded. If you assign the returned PHPExcel object to a variable (e.g. $objWorkBook), then you can access the worksheets in that object using the getActiveSheet() method of the PHPExcel class, which then returns the worksheet.


$objReader = PHPExcel_IOFactory::createReader('Excel2007'); 
$objWorkBook = $objReader->load($toFile); 
$objWorksheet = $objWorkBook->getActiveSheet();
Apr 25, 2010 at 11:16 PM


Thank you.  I was able to move past this error.  As you can see, I am just trying to learn this.  I am transitioning from writeExcel.

So, on to my next issue.  Is the $objReader an object?  I get another undefined when I do the following:


I get an undefined on the columnIndexFromString method:  Fatal error: Call to undefined method PHPExcel_Reader_Excel2007::columnIndexFromString() in /Applications/XAMPP/xamppfiles/htdocs/com.sonarioadmin/application/php/sonarioAdminServices/loadData.php on line 191

Apr 25, 2010 at 11:25 PM



Please disregard the last post.  Dumb error.


Thank you..