ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Php excel reader as a codeigniter library

May 21, 2008 9:11am

Subscribe [7]
  • #1 / May 21, 2008 9:11am

    jon.breakdesign

    2 posts

    Hi

    When looking through the forums for a library to read excel files I came across this thread

    http://ellislab.com/forums/viewthread/47299/


    and after reading through it tried out the excel reader in the wiki. It seemed a bit buggy
    so I read over Derek’s comments noting.

    Actually, I need one to read excel.  In the past I’ve used the excellent Excel reader (http://sourceforge.net/projects/phpexcelreader) but I was just hoping that someone had already taken it and coded it up as a CI library.

    Thanks both.


    So I Downloaded that lib and used it briefly as Derek did:

    require('Spreadsheet_Excel_Reader.php');
    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding('CP1251'); // Set output Encoding.
    $data->read($filename); // relative path to .xls that was uploaded earlier
        
    for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
         for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
              echo "\"".$data->sheets[0]['cells'][$i][$j]."\",";
         }
    echo "\n";            
    }

    but after looking over the files it seemed they could be used as a lib without much alteration. So I altered them slightly and the reader seems to be running fine as a lib.

    example code usage:

    public function bulk_upload()
        {
            $this->load->library('spreadsheet_excel_reader');
            
            $this->spreadsheet_excel_reader->setOutputEncoding('CP1251'); // Set output Encoding.
            $this->spreadsheet_excel_reader->read('uploads/outlet_participation/test.xls'); // relative path to .xls that was uploaded earlier
            
            $rows = $this->spreadsheet_excel_reader->sheets[0]['cells'];
            $row_count = count($this->spreadsheet_excel_reader->sheets[0]['cells']);
            echo 'my row count is'.$row_count;
        
            for ($i = 2; $i <= $row_count; $i++) {
                var_dump($rows[$i]);
                echo "
    
    <hr>";
            }
    
        }

    Anyway I hope this makes life more convenient for somebody.

  • #2 / May 21, 2008 9:19am

    jon.breakdesign

    2 posts

    You can grab the files Here

  • #3 / Sep 25, 2008 12:08pm

    patos

    7 posts

    Hi,
    You’ve done exactly what i need today. can you reupload them?
    thanks.

  • #4 / Sep 25, 2008 1:27pm

    jon.breakdesign

    2 posts

    Here You go:)

  • #5 / Sep 26, 2008 7:31am

    patos

    7 posts

    thanks. i’ll spend a real weekend 😉

  • #6 / Sep 26, 2008 10:16am

    thor

    3 posts

    is there any way you can read “special” informations from the excel file, such as color of cells etc ?

  • #7 / Jul 08, 2009 1:16pm

    e-mike

    12 posts

    I’m using an other good PHP Excel Reader that I want to share.

    http://code.google.com/p/php-excel-reader/

  • #8 / Nov 16, 2009 10:04pm

    vile

    41 posts

    I’m using an other good PHP Excel Reader that I want to share.

    http://code.google.com/p/php-excel-reader/

    how do you add this as codeigniter library?
    i cant make them work :(

  • #9 / Mar 12, 2012 4:22am

    Seto El Kahfi

    7 posts

    Lha endi ki file-e, ra ono nuk. Upload neh dong :D

    Above comment is in Javanesse, here the translate:
    I can’t find the file. Reupload please :D

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases