Welcome Guest, Not a member yet? Register   Sign In
Php excel reader as a codeigniter library
#1

[eluser]jon.breakdesign[/eluser]
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.

Quote: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:

Code:
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:

Code:
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 "<br><br><hr>";
        }

    }

Anyway I hope this makes life more convenient for somebody.
#2

[eluser]jon.breakdesign[/eluser]
You can grab the files Here
#3

[eluser]patos[/eluser]
Hi,
You've done exactly what i need today. can you reupload them?
thanks.
#4

[eluser]jon.breakdesign[/eluser]
Here You goSmile
#5

[eluser]patos[/eluser]
thanks. i'll spend a real weekend ;-)
#6

[eluser]thor[/eluser]
is there any way you can read "special" informations from the excel file, such as color of cells etc ?
#7

[eluser]e-mike[/eluser]
I'm using an other good PHP Excel Reader that I want to share.

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

[eluser]vile[/eluser]
[quote author="e-mike" date="1247087799"]I'm using an other good PHP Excel Reader that I want to share.

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

how do you add this as codeigniter library?
i cant make them work Sad
#9

[eluser]Seto El Kahfi[/eluser]
Lha endi ki file-e, ra ono nuk. Upload neh dong Big Grin

Above comment is in Javanesse, here the translate:
I can't find the file. Reupload please Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB