I need to read an Excel file and record it on my database. I'm using Laravel + Maatwebsite/Laravel-excel to Read the file. With my currently code I get no errors but no data is shown in the browser:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
Use Excel;
class ImportController extends Controller
{
public function index()
{
Excel::load('test.xls', function($reader) {
$result = $reader->get();
foreach ($result as $key => $value) {
echo $value->situation;
}
})->get();
}
}
var_dump($result)
object(Maatwebsite\\Excel\\Collections\\RowCollection)#634 (2) { ["title":protected]=> string(9) "Worksheet" ["items":protected]=> array(161) { [0]=> object(Maatwebsite\\Excel\\Collections\\CellCollection)#646 (2) { ["title":protected]=> NULL ["items":protected]=> array(1) { [0]=> NULL } } 1 =>
You can loop the result via:
// Loop through all sheets
$reader->each(function($sheet) {
// Loop through all rows
$sheet->each(function($row) {
});
});
On http://www.maatwebsite.nl/laravel-excel/docs/import you can find more information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.