title: To upload Excel and store it in database?
body: <p>I want to upload an Excel file into our webpage, then corresponding data store it in database. And then I want to retrieve all data and display it in table format. I have one code but using that I can't upload all Excel files. Only a single format can be upload.</p>
  
  <p>Below is the function. But there is some restriction.</p>
  
  <pre><code> public function check_excel($filename)
          {   
              $path='./assets/uploads/excel/'.$filename;
              $this-&gt;load-&gt;library('excel');  
              $inputFileType = PHPExcel_IOFactory::identify($path);
              $objReader = PHPExcel_IOFactory::createReader($inputFileType);
              $objPHPExcel = PHPExcel_IOFactory::load($path);
              $sheet = $objPHPExcel-&gt;getSheet(0); 
              $highestRow = $sheet-&gt;getHighestRow();
              $highestColumn = $sheet-&gt;getHighestColumn();
              $xf[]='';
              $result[]='';
              $first_check='';
              $var_check=0;
  
              for ($row = 13; $row &lt;= $highestRow; $row++)
              {           
                  $xf[$row]=$objPHPExcel-&gt;getActiveSheet()-&gt;getCell('A'.$row)-&gt;getXfIndex(); // Get sheet index value
                  if($row&gt;13 &amp;&amp; $row&lt;16) //This block check first kpi data expand or not
                  { 
                      if($xf[$row-1]==$xf[$row]) //check parent and child sheet index value same 
                          $first_check='false';
                      if ($row==15) 
                      {
                          if($xf[$row]==$xf[$row-1] || $xf[$row]==$xf[$row-2]) // check the grand-child sheet index value same in parent and child
                              $first_check='false';
                          else
                          {   
                              $first_check='true';
                              $a=$row-2;
                              $b=$row-1;
                              $check_kpi=$objPHPExcel-&gt;getActiveSheet()-&gt;getCell('A'.$a)-&gt;getXfIndex(); 
                              $check_unit=$objPHPExcel-&gt;getActiveSheet()-&gt;getCell('A'.$b)-&gt;getXfIndex(); 
                              $check_sub_unit=$objPHPExcel-&gt;getActiveSheet()-&gt;getCell('A'.$row)-&gt;getXfIndex(); 
                          }
                      }       
                  }
                  if($first_check=='true') //This block check second kpi to upto last kpi data expand or not 
                  {
                      if($row&gt;15)
                      {
                          if($var_check==1) // This block check the child data expand or not
                          {
                              if($check_unit!=$objPHPExcel-&gt;getActiveSheet()-&gt;getCell('A'.$row)-&gt;getXfIndex())
                              {
                                  $result[$row]='false';
                                  break;
                              }
                          }
                          if($var_check==2) // this block check the grand - child data expand or not
                          {
                              if($check_sub_unit!=$objPHPExcel-&gt;getActiveSheet()-&gt;getCell('A'.$row)-&gt;getXfIndex())
                              {
                                  $result[$row]='false';
                                  break;                          
                              }
                          }
                          if($xf[$row]!=$check_sub_unit)
                          {
                              if($xf[$row]!=$check_unit)
                                  $var_check=1; // var_check value is one, the kpi is present
                              else
                                  $var_check=2; // var_check value is two, the unit is present
                          }
                          else
                              $var_check=0; // var_check value is zero, the sub_unit is present
                      }   
                  }
                  else if($first_check=='false')
                  {
                      $result[$row]='false';
                      break;
                  }           
              }
              $return='true';
              for ($row = 13; $row &lt;= $highestRow; $row++)
              {
                  if(!empty($result[$row]))
                  {
                      if($result[$row]=='false'){
                          $return='false';
                          break;
                      }                   
                  }
              }
              return $return;
          }
  </code></pre>