Read sheet 2

Topics: Developer Forum, User Forum
Nov 13, 2010 at 12:48 AM

Just downloaded this product today and am very impressed so far, with the exception of the documentation.

I have read in my xlsx spreadsheet and looped through the first sheet. Very simple.  It has 5 sheets and I am having trouble getting to any other than the first.  Here is the code I am using which was straight from the documentation.  You can see I tried to utilize setActiveSheet, but that threw the error "Call to undefined method PHPExcel::setActiveSheet()".


$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("cmt_school_data.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();
echo '<table border=1>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
  echo '<tr>' . "\n";
  $cellIterator = $row->getCellIterator();
  $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
                                                     // even if it is not set.
                                                     // By default, only cells
                                                     // that are set will be
                                                     // iterated.
  foreach ($cellIterator as $cell) {
    echo '<td>' . $cell->getValue() . '</td>' . "\n";
  echo '</tr>' . "\n";
echo '</table>' . "\n";


Nov 13, 2010 at 11:39 AM

As you've already discovered, setActiveSheet() doesn't exist: setActiveSheetIndex() and setActiveSheetIndexByName() are the two methods available for changing the active sheet.


Take a look at the /Documentation/API folder in the production download which contains a complete set of PHPDocumentor API docs.