title: Read .xlsx and .xls data in codeigniter
body: <p>I want to read the data of .xlsx or .xls file in codeigniter. I have read the other questions related it but nothing works. I have used phpexcel, reader but with no luck. In my project i give the option to upload excel file then i want to read the data and insert it in the database.</p>
  
  <p><strong>Now i am using phpExcel library I have wrote:</strong></p>
  
  <pre><code>    $this-&gt;load-&gt;library('excel');
      $reader= PHPExcel_IOFactory::createReader('Excel2007');
      $reader-&gt;setReadDataOnly(true);
      $path=(FCPATH.'uploads/productfile/'.$_FILES['upload_file']['name']);
      $excel=$reader-&gt;load($path);
      $sheet=$excel-&gt;setActiveSheetIndex(0);
      for($i=0;$i&lt;=1000;$i++)
      {
        $col1= $sheet-&gt;getCellByColumnAndRow(0,$i)-&gt;getValue();
        $col2= $sheet-&gt;getCellByColumnAndRow(1,$i)-&gt;getValue();
        $col3= $sheet-&gt;getCellByColumnAndRow(2,$i)-&gt;getValue();
        var_dump($col1);
      }
  </code></pre>
  
  <p><strong>but it display :</strong></p>
  
  <blockquote>
    <p>Uncaught exception 'PHPExcel_Exception' with message 'You tried to set
    a sheet active by the out of bounds index: 0. The actual number of
    sheets is 0 Please give me some example code.</p>
  </blockquote>
  
  <p><strong>The error</strong>
  <a href="https://i.stack.imgur.com/8Bfni.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Bfni.png" alt="enter image description here"></a>
  Please give me some example code:</p>