title: How to use PHPSpreadsheet in CodeIgniter 3 to read data from Excel (.xlsx and .xls) file?
body: <p>Recently in one of my CodeIgniter based project, I need to read data from Excel file ( .xlsx and .xls ) and insert those data into MySQL. Unfortunately, I did not use <strong>PHPSpreadsheet</strong> before (as I did not require to work with Excel :( ).</p>
  <p>So far what I did was, download the <strong>PHPSpreadsheet</strong> from Github and extract it to the root directory of my <strong>CodeIgniter</strong> Project.</p>
  <p><a href="https://i.stack.imgur.com/HFzN3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HFzN3.png" alt="enter image description here" /></a>
  PHPSpreadsheet in CodeIgniter root directory.</p>
  <p><a href="https://i.stack.imgur.com/q6RT2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q6RT2.png" alt="enter image description here" /></a>
  File Structure of PHPSpreadsheet.</p>
  <p>So far I've tried to import the official docs example into my CI apps:</p>
  <pre><code>&lt;?php
      defined('BASEPATH') OR exit('No direct script access allowed');
      use PhpOffice\PhpSpreadsheet\IOFactory;
      class Welcome extends CI_Controller {
         function __construct() {
             parent::__construct();
         }
  
         public function index()
         {
             $inputFileType = 'Xlsx';
             $inputFileName = 'test.xlsx';
             $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
      /**  Load $inputFileName to a Spreadsheet Object  **/
            $spreadsheet = $reader-&gt;load($inputFileName);
            print_r( $spreadsheet );
      }
  }
  </code></pre>
  <p>But it shows the following error!!
  <a href="https://i.stack.imgur.com/9evxl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9evxl.png" alt="enter image description here" /></a></p>
  <p>Can anyone tell me how can I use <strong>PHPSpreadsheet</strong> in <strong>CodeIgniter</strong> to read data from Excel file and store them into MySQL database?</p>
  <ul>
  <li>Thanks</li>
  </ul>