title: PHPExcel reader -- help required
body: <p>I m using <a href="http://phpexcel.codeplex.com/" rel="nofollow noreferrer">PHPExcel</a> to read data from Excel sheet and store in mysql table, till now i m able to upload .xls  as well as .xlsx file and after uploading the xls i got below table structure of data</p>
  
  <pre><code>name    start_date              end_date               city
  one 11/25/2011 3:30:00 PM   11/29/2011 4:40:00 AM   Jaipur
  two 10/22/2011 5:30:00 PM   10/25/2011 6:30:00 AM   Kota
  three  3/10/2011 2:30:00 PM 3/11/2011 12:30:00 AM   Bikaner
                                                      chandigarh
  </code></pre>
  
  <p>now i have some problems, please suggest me the optimized method </p>
  
  <ol>
  <li>how do we get the sheet name ( bcoz in one excel there are 7 sheets )</li>
  <li><p>for now what i do to store these
  data into db, below is the code snippet</p>
  
  <pre><code>$inputFileName = "test.xls";  
  $inputFileType = PHPExcel_IOFactory::identify($inputFileName);  
  $objReader = PHPExcel_IOFactory::createReader($inputFileType);  
  $objReader-&gt;setReadDataOnly(true);  
  /**  Load $inputFileName to a PHPExcel Object  **/  
  $objPHPExcel = $objReader-&gt;load($inputFileName);  
  $total_sheets=$objPHPExcel-&gt;getSheetCount(); // here 4  
  $allSheetName=$objPHPExcel-&gt;getSheetNames(); // array ([0]=&gt;'student',[1]=&gt;'teacher',[2]=&gt;'school',[3]=&gt;'college')  
  $objWorksheet = $objPHPExcel-&gt;setActiveSheetIndex(0); // first sheet  
  $highestRow = $objWorksheet-&gt;getHighestRow(); // here 5  
  $highestColumn = $objWorksheet-&gt;getHighestColumn(); // here 'E'  
  $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);  // here 5  
  for ($row = 1; $row &lt;= $highestRow; ++$row) {  
      for ($col = 0; $col &lt;= $highestColumnIndex; ++$col) {  
      $value=$objWorksheet-&gt;getCellByColumnAndRow($col, $row)-&gt;getValue();  
          if(is_array($arr_data) ) { $arr_data[$row-1][$col]=$value; }  
      }  
  }
  print_r($arr_data);
  </code></pre></li>
  </ol>
  
  <p>and this returns</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [0] =&gt; name
          [1] =&gt; start_date
          [2] =&gt; end_date
          [3] =&gt; city
          [4] =&gt;         
      )
  
  [1] =&gt; Array
      (
          [0] =&gt; one  
          [1] =&gt; 40568.645833333
          [2] =&gt; 40570.5
          [3] =&gt; Jaipur
          [4] =&gt; 
      )
  [2] =&gt; Array
      (
          [0] =&gt; two 
          [1] =&gt; 40568.645833333
          [2] =&gt; 40570.5
          [3] =&gt; Kota
          [4] =&gt; 
      )
  [3] =&gt; Array
      (
          [0] =&gt; three
          [1] =&gt; 40568.645833333
          [2] =&gt; 40570.5
          [3] =&gt; Bikaner
          [4] =&gt; 
       )
    [4] =&gt; Array
      (
          [0] =&gt; 
          [1] =&gt; 
          [2] =&gt; 
          [3] =&gt; Chandigarh
          [4] =&gt; 
      )
  
  )
  </code></pre>
  
  <p>i need  that   </p>
  
  <ul>
  <li>header of each excel sheet (i.e. first row) become key of array($arr_data) and   </li>
  <li>rest become the value of array.  </li>
  <li>time changed into some integer value, that shoud be same as in  excel sheet  </li>
  <li>blank field ( i.e.blank header column ) of array in all row should be truncated (here [4]  )  </li>
  <li>if first field of an excel sheet (or combined condition on some
  fields) is not fulfilled then that row should not be added into array  </li>
  </ul>
  
  <p>i.e. desired array should look like   </p>
  
  <pre><code>Array  
      (  
      [0] =&gt; Array  
      (  
        [name] =&gt; one  
        [start_date] =&gt; 11/25/2011 3:30:00 PM  
        [end_date] =&gt; 11/29/2011 4:40:00 AM  
        [city] =&gt; Jaipur  
      )  
      [1] =&gt; Array  
      (  
        [name] =&gt; two  
        [start_date] =&gt; 10/22/2011 5:30:00 PM  
        [end_date] =&gt; 10/25/2011 6:30:00 AM  
        [city] =&gt; Kota  
      )  
      [2] =&gt; Array  
      (  
        [name] =&gt; three  
        [start_date] =&gt; 3/10/2011 2:30:00 PM  
        [end_date] =&gt; 3/11/2011 12:30:00 AM  
        [city] =&gt; Bikaner  
      )  
  )
  </code></pre>
  
  <p>and after that i store data into my db using mysql action on desired array.</p>
  
  <ul>
  <li>is there any other short method to store above data in db </li>
  </ul>
  
  <h3>Note: Please do not refer manual( it is really really very bad )... just tell me the methods name..</h3>
  
  <h2>update</h2>
  
  <p>@Mark Thanks for your solution, it helps me a lot, but still some problems are there</p>
  
  <ul>
  <li>how to handle empty/blank cell in excel sheet..bcoz when any cell are empty then it display a notice </li>
  </ul>
  
  <blockquote>
    <p>Notice: Undefined index: C in C:\xampp\htdocs\xls_reader\Tests\excel2007.php
    on line 60<br>
    Notice: Undefined index: D in C:\xampp\htdocs\xls_reader\Tests\excel2007.php
    on line 60</p>
  </blockquote>
  
  <p>whereas line 60 is </p>
  
  <pre><code>foreach($headingsArray as $columnKey =&gt; $columnHeading) { 
      $namedDataArray[$r][$columnHeading] = $dataRow[$row]$columnKey];
  }
  </code></pre>
  
  <ul>
  <li>how to set conditions before retrieving array of complete data i.e. if i want that if first and second column are empty/blank in any row then that row should not be added in our desired array</li>
  </ul>
  
  <p>thanks</p>