Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

freedomfflow's avatar

Maatwebsite\Excel - need code for upload & read xlsx

Maatwebsite\Excel package - Need code for uploading an xlsx file and reading through it.

I've installed the package, but the docs seem fragmented and I'm lost trying to simply upload and read a file. If anyone has used this and is willing to paste their code here (include 'use' statements, 'namespace', and methods for uploading and reading) I would be very grateful.

I'm using Laravel 5.1

Thanks!

0 likes
1 reply
bobbybouwmann's avatar

Well uploading has nothing to do with the package, so you can simply Google that.. For reading it's fairly simply.

public function import(Request $request)
{
    $file = $request->file('file'); 
    $file->move(storage_path('imports'), 'import.' . $file-> getClientOriginalExtension());

    Excel::load(storage_path($file . '/' . $file->getFilename()), function ($reader) {
        $reader->each(function ($row) {
            echo $row->column_name;
        });
    });
}
2 likes

Please or to participate in this conversation.