getSheetCount() failed

Topics: Developer Forum, User Forum
Feb 23, 2009 at 4:32 PM

I am a PHPExcel newbie.  My get sheet count isn't working, when I was getting returns of the highest rows and colums of the default worksheet just fine. Would any of you experts kindly point to me what's missing in my code?
Thanks in advance.

<?php
//Here we set the include path and load the librarires
      require_once('PHPExcel.php');
      require_once('PHPExcel/Reader/IOFactory.php');
      require_once('PHPExcel/Reader/IReadFilter.php');

echo date('H:i:s') . " Starting PHPExcel object<br/>";

      $file = 'some_file.xls';
      $ext  = substr($file, strrpos($file, '.') + 1);
      if    ($ext == 'xls')  $objReader = PHPExcel_IOFactory::createReader('Excel5');
      elseif($ext == 'xlsx') $objReader = PHPExcel_IOFactory::createReader('Excel2007');

      $objReader->setReadDataOnly(TRUE);
      $objPHPexcel = $objReader->load($file);

      $maxRow = $objPHPexcel->getActiveSheet()->getHighestRow();
      $maxCol = $objPHPexcel->getActiveSheet()->getHighestColumn();
echo "Highest column ===> " . $maxCol . " <br/> ";
echo "Highest row    ===> " . $maxRow . " <br/> ";

      $sheetCount = $objPHPExcel->getSheetCount();                  // THIS IS WHERE IT FAILED.

echo date('H:i:s') . " Number of worksheets" . $sheetCount . " <br/> ";

   //$sheet = $objPHPExcel->getSheet(0);
   //echo "Sheet ===> " . $sheet . " \n";
   //$sheet = $objPHPExcel->getSheetByName('NET');
   //echo "Sheet ===> " . $sheet . " \n";
   //$sheet = $objPHPExcel->setActiveSheetIndex(1);
   //echo "Sheet ===> " . $sheet . " \n";

?>

Coordinator
Feb 23, 2009 at 8:59 PM
Edited Feb 23, 2009 at 9:00 PM
Watch out for case-sensitivity in PHP variable names:

$sheetCount = $objPHPExcel->getSheetCount();
should be
$sheetCount = $objPHPexcel->getSheetCount();

watch out for it in the lines you've commented out as well
Feb 23, 2009 at 9:41 PM

Hello Markbaker,

Thank you so much for your time and pointing out my errors. “objPHPexcel” fixed my problem.