title: PHPExcel switch between xls and xlsx
body: <p>I am writing a script that reads .xls and .xlsx files from mail attachments. I'm trying to make the script switch between readers based on the file extension using the identify method.</p>
  
  <pre><code>$strSheetNameResult = 'QA Result';
  $strSheetNameComments = 'QA Comments'; 
  
  foreach($aPaths as $strPath) {
      try {
          $strFileType = PHPExcel_IOFactory::identify($strPath);
          echo $strFileType;
  
          $oReader = PHPExcel_IOFactory::createReader($strFileType);
  
          $oReader-&gt;setLoadSheetsOnly($strSheetNameResult);
  
          $oSheetData = $oReader-&gt;load($strPath)-&gt;getActiveSheet();
  </code></pre>
  
  <p>.xls works just fine, but as soon as it encounters an .xlsx file it doesn't use the right reader and gives me an error: `Fatal error: </p>
  
  <blockquote>
    <p>Call to a member function getCell() on a non-object in C:\xampp\htdocs\cronjob\Test.php on line 37`</p>
  </blockquote>
  
  <p>line 37: </p>
  
  <pre><code>$aSheetData['strProjectName'] = $oSheetData-&gt;getCell('B4')-&gt;getValue();
  </code></pre>
  
  <p>I think this error is caused because it's not using the right reader.</p>
  
  <p><code>$aPaths</code>: </p>
  
  <pre><code>Array(
      [0] =&gt; C:\xampp\tmp\105943-632345.xls
      [1] =&gt; C:\xampp\tmp\112047-634744.xlsx
      [2] =&gt; C:\xampp\tmp\112069-634917.xls
      [3] =&gt; C:\xampp\tmp\113840-634955.xls
      [4] =&gt; C:\xampp\tmp\115760-635374.xlsx
      [5] =&gt; C:\xampp\tmp\120294-637780.xls
      [6] =&gt; C:\xampp\tmp\120801-638144.xls
      [7] =&gt; C:\xampp\tmp\121098-638118.xls
      [8] =&gt; C:\xampp\tmp\124831-641137.xlsx
      [9] =&gt; C:\xampp\tmp\127680-642962.xls
      [10] =&gt; C:\xampp\tmp\127689-642665.xls
      [11] =&gt; C:\xampp\tmp\127692-642784.xls
      [12] =&gt; C:\xampp\tmp\127700-643048.xls
      [13] =&gt; C:\xampp\tmp\127708-643096.xls
      [14] =&gt; C:\xampp\tmp\128771-642241.xls
      [15] =&gt; C:\xampp\tmp\129082-647219.xls
      [16] =&gt; C:\xampp\tmp\129629-647241.xls
      [17] =&gt; C:\xampp\tmp\134488-647334.xls
      [18] =&gt; C:\xampp\tmp\134500-646313.xls
      [19] =&gt; C:\xampp\tmp\134508-644581.xls
      [20] =&gt; C:\xampp\tmp\134511-646521.xls
      [21] =&gt; C:\xampp\tmp\134512-646136.xls
      [22] =&gt; C:\xampp\tmp\134561-650010.xls
  </code></pre>
  
  <p>)</p>
  
  <p>Does anybody have an idea why this isn't working, or a different way to switch between readers?</p>