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.
http://codeigniter.com/wiki/Excel_Reader_Class/
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
$this->load->library('excel_reader');
Step 3: Set the load path of the Excel file that has been uploaded
For example:
$uploadpath = "/var/www/uploads/test.xls";
Step 4: Run the Excel Reader Library
$this->excel_reader->read($uploadpath);
// Read the first workbook in the file
$worksheetrows =$this->excel_reader->worksheets[0];
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.
echo "<table>";
foreach($worksheetrows as $worksheetrow)
{
echo "<tr>";
for($i=0; $i<worksheetcolumns; $i++)
{
// if the field is not blank -- otherwise CI will throw warnings
if (isset($worksheetrow[$i]))
echo "<td>".$worksheetrow[$i]."</td>";
// empty field
else
echo "<td> </td>";
}
echo "</tr>";
}
echo "</table>";
This should get you going with reading Excel files in CodeIgniter.
Brilliant, Thank you for the information. very useful
Thank you, but how do I ever get special characters working? I’m Icelandic and special characters all turn into �.
Sorry, sorry. Excel reader outputted in ISO format, I just had to utf8_encode($worksheetrow[$i]).
Thank you!
kok nda ada Excel_reader.php nya? boleh minta nda? thx
awesome, very useful
Great tutorial !!
Please could you please email me the Class !!???
In the Wiki is not visible !!!
Email me to: [email protected]
Thanks in advance !!
The excel_reader library is not visible in wiki would you please email me the library .email address :[email protected]
http://codeigniter.com/wiki/Excel_Reader_Class/ no existe ningun archivo????
I don’t see the “excel_reader” library on the CI website for download? Do you know where it can be found.
It looks like the author removed the code from the Code Igniter website.
There’s a PHP Excel reader on Google Code that should have most of the functionality:
http://code.google.com/p/php-excel-reader/downloads/list
anyone who send me the class excel_reader please.
[email protected]
Thanks in advanced
There is some great information here. Thanks! Has anyone tried http://docraptor.com for converting html to pdf or excel? I tried the free version and it was pretty easy.
I have used php Spreadsheet_Excel_Reader and used this class as codeigniter library
$pathToFile = ‘actual file path’
$params = array(‘file’ => $pathToFile, ‘store_extended_info’ => true,’outputEncoding’ => “”);
$this->load->library(‘Spreadsheet_Excel_Reader’, $params);
$this->spreadsheet_excel_reader->read($pathToFile);
Hello,
Please can someone email me the Excel Reader Class
Thanks in Advance 🙂
Hello,
Please can someone email me the Excel Reader Class
Please email it to : [email protected]
Thanks in Advance 🙂
Please can someone email me the Excel Reader Class