• PHP
  • Ruby on Rails
  • MySQL
  • Linux
    • SELINUX
    • Fedora
    • debian
  • Apache
  • nginx
  • AJAX
Albertech.net

CodeIgniter: Reading Excel Files

April 20, 2010 3:06 pm / Albertech.net

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>&nbsp; </td>";
     }
     echo "</tr>";
} 
echo "</table>";

This should get you going with reading Excel files in CodeIgniter.

Share this:

  • Facebook
  • Google
  • Twitter
  • Print
  • Email
Posted in: Frameworks, PHP / Tagged: codeigniter excel

16 Thoughts on “CodeIgniter: Reading Excel Files”

  1. karen on May 7, 2010 at 3:59 am said:

    Brilliant, Thank you for the information. very useful

  2. Egill on June 29, 2010 at 4:32 pm said:

    Thank you, but how do I ever get special characters working? I’m Icelandic and special characters all turn into �.

  3. Egill on June 29, 2010 at 5:15 pm said:

    Sorry, sorry. Excel reader outputted in ISO format, I just had to utf8_encode($worksheetrow[$i]).

    Thank you!

  4. rey1024 on August 17, 2010 at 9:30 am said:

    kok nda ada Excel_reader.php nya? boleh minta nda? thx

  5. Irfan Suleman on September 17, 2010 at 4:03 am said:

    awesome, very useful

  6. Lucas on November 11, 2010 at 7:22 pm said:

    Great tutorial !!

    Please could you please email me the Class !!???
    In the Wiki is not visible !!!
    Email me to: [email protected]

    Thanks in advance !!

  7. Thasneem on January 14, 2011 at 1:08 am said:

    The excel_reader library is not visible in wiki would you please email me the library .email address :[email protected]

  8. Toyzafao on January 29, 2011 at 12:18 pm said:

    http://codeigniter.com/wiki/Excel_Reader_Class/ no existe ningun archivo????

  9. Bryan on February 3, 2011 at 12:58 pm said:

    I don’t see the “excel_reader” library on the CI website for download? Do you know where it can be found.

  10. admin on February 21, 2011 at 8:06 pm said:

    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

  11. Ariful Islam on February 23, 2011 at 6:37 am said:

    anyone who send me the class excel_reader please.
    [email protected]

    Thanks in advanced

  12. Julia on May 5, 2011 at 3:07 pm said:

    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.

  13. Thasneem on May 8, 2011 at 11:28 pm said:

    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);

  14. rohit on June 28, 2011 at 4:06 am said:

    Hello,
    Please can someone email me the Excel Reader Class

    Thanks in Advance 🙂

  15. Rohit on June 29, 2011 at 2:11 am said:

    Hello,
    Please can someone email me the Excel Reader Class

    Please email it to : [email protected]

    Thanks in Advance 🙂

  16. Denis on July 20, 2011 at 6:04 am said:

    Please can someone email me the Excel Reader Class

Post Navigation

← Previous Post
Next Post →

Categories

  • AJAX
  • Android
  • Apache
  • Canon Cameras
  • Cloud
  • CMS
  • Computer Mods
  • Conferences
  • Deals
  • debian
  • Fedora
  • Flash
  • Frameworks
  • git
  • Hardware
  • HTML
  • IDE
  • iPhone
  • iPhone App Review
  • jQuery
  • Linux
  • Mac OS X
  • MySQL
  • nginx
  • PHP
  • portfolio
  • Puppet
  • Ruby on Rails
  • Script Reviews
  • SELINUX
  • Software
  • Software Review
  • SQL Server
  • statistics
  • Tech
  • Tomcat
  • Uncategorized
  • VMWARE
  • VPS
  • Windows
  • wordpress
  • Zend Framework

Blogroll

  • DragonAl Flickr
  • Dropbox – Free 2GB Account
  • James' Blog
  • Javascript Compressor
  • PHP Builder Community
  • PHP-Princess.net
  • Rubular – Regular Expression Validator
  • The Scale-Out Blog
  • Tiny MCE

Tags

activation AJAX android antec Apache AWS awstats canon coda codeigniter debian enclosure external free G1 install vmware tools Internet Explorer iphone 5 jquery Linux mx-1 MySQL office 2007 OSX photoshop PHP plugin plugins portfolio redesigned website review rewrite script security SELinux ssh tinymce tutorial upgrade VMWARE vmware server wordpress wordpress mu XSS zend framework
© Copyright 2013 Albertech.net
Infinity Theme by DesignCoral / WordPress
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.