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

Tag Archives: Codeigniter Excel

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

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.