Reading Excel files in CodeIgniter is actually very easy once you have the right documentation. The first thing you will need to do is utilize the CodeIgniter “Upload” library and add in the Excel Reader library for reading the files. The documentation on the CodeIgniter website in regards to this Excel Reader library is missing some details in implementation. This tutorial will go through the steps of installing the Excel reader library and getting an example implementation working.
Step 1: Download the Excel Reader Library from CodeIgniter’s website.
Copy and paste the Excel_reader.php section into notepad or a text editor. Save the file in [CodeIgniter Folder]/system/application/libraries/ as Excel_reader.php
Step 2: Load the Library from your CodeIgniter Application
Step 3: Set the load path of the Excel file that has been uploaded
$uploadpath = "/var/www/uploads/test.xls";
Step 4: Run the Excel Reader Library
// Read the first workbook in the file
Step 5: Set number of columns in your Excel file
$worksheetcolumns = 5;
Step 6: Run through the table and output the data
I’ve created a quick function that will go through the entire worksheet and output the data for testing.
foreach($worksheetrows as $worksheetrow)
for($i=0; $i<worksheetcolumns; $i++)
// if the field is not blank -- otherwise CI will throw warnings
// empty field
echo "<td> </td>";
This should get you going with reading Excel files in CodeIgniter.