mercredi 27 janvier 2016

Reading excel file in Laravel

I'm using Maatwebsite's library for reading and creating excel file. The creating was easy and somehow intuitive, but when it comes to reading one, I simply can't figure it out.

This is how my excel file looks like: enter image description here

I figured out how to loop through rows, but what confused me that $row in my example is really type of string, so I can't do $row->something;

In my controller I want to read it like this:

 Excel::load('storage\\exports\\'. $fName, function($reader) {
    $reader->each(function($sheet) {
        Log::warning("sheet happens");

        // Loop through rows            
        $sheet->each(function($row) {
            Log::warning($row);
        });

    });
});

This gives me output

[2016-01-28 06:42:05] local.WARNING: sheet happens  
[2016-01-28 06:42:05] local.WARNING:   
[2016-01-28 06:42:05] local.WARNING:   
[2016-01-28 06:42:05] local.WARNING:   
[2016-01-28 06:42:05] local.WARNING:   
[2016-01-28 06:42:05] local.WARNING:   
[2016-01-28 06:42:05] local.WARNING:   
[2016-01-28 06:42:05] local.WARNING: sheet happens  
[2016-01-28 06:42:05] local.WARNING: ocjena  
[2016-01-28 06:42:05] local.WARNING: Kolokvijum 1 (%)  
[2016-01-28 06:42:05] local.WARNING: Kolokvijum 2  
[2016-01-28 06:42:05] local.WARNING: Kolokvijum 2 (%)  
[2016-01-28 06:42:05] local.WARNING: Završni ispit (%)  
[2016-01-28 06:42:05] local.WARNING: Završni ispit  

It confused me that output is not in the right order.

It confused me that my row is type of string. Why?

Is it possible to access specific cells like we do in matrix: $table[$row][$column]; ?

If you can't answer my question I would really apreciate if you have any piece of working code since there is not very much docs online.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/23udDYS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire