title: Identifying worksheet index while Looping through worksheets, via getWorksheetIterator(), with PHPExcel
body: <p>I'm using the PHPExcel library to read an Excel file with many worksheets and perform processing on it.  Now I have no problem looping through each worksheet.  However, I want to extract the index of each worksheet and print it out and I'm not sure how to do this.  Sure, I can make my own counter and be done with it.  But there must be a built-in method with the getWorksheetIterator() method, no?</p>
  
  <p>That is, how do I extract the current worksheet iterator?</p>
  
  <p>Thank you for any help.</p>
  
  <p>Here is the documentation's looping example, for reference, slightly modified with the inclusion of the worksheetiterator method:</p>
  
  <pre><code>&lt;?php
  $objReader = PHPExcel_IOFactory::createReader('Excel2007');
  $objReader-&gt;setReadDataOnly(true);
  
  $objPHPExcel = $objReader-&gt;load("test.xlsx");
  $objWorksheet = $objPHPExcel-&gt;getActiveSheet();
  
  $CurrentWorkSheetIndex = 0; 
  
  foreach ($objPHPExcel-&gt;getWorksheetIterator() as $worksheet) {
      echo 'WorkSheet' . $CurrentWorkSheetIndex++ . "\n";
      echo '&lt;table&gt;' . "\n";
      foreach ($objWorksheet-&gt;getRowIterator() as $row) {
        echo '&lt;tr&gt;' . "\n";
  
        $cellIterator = $row-&gt;getCellIterator();
        $cellIterator-&gt;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 '&lt;td&gt;' . $cell-&gt;getValue() . '&lt;/td&gt;' . "\n";
        }
  
        echo '&lt;/tr&gt;' . "\n";
      }
      echo '&lt;/table&gt;' . "\n";
  }
  ?&gt;
  </code></pre>