【问题标题】:Can't print Excel file values无法打印 Excel 文件值
【发布时间】:2016-01-22 13:30:23
【问题描述】:

我需要读取一个 Excel 文件并将其记录在我的数据库中。我正在使用 Laravel + Maatwebsite/Laravel-excel 来读取文件。使用我当前的代码,我没有收到任何错误,但浏览器中没有显示任何数据:

<?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]=> 对象(Maatwebsite\Excel\Collections\CellCollection)#646 (2) { ["title":protected]=> NULL ["items":protected]=> array(1) { [0]=> NULL } } 1=>

【问题讨论】:

  • 你在result上发过var_dump吗?

标签: php excel laravel


【解决方案1】:

您可以通过以下方式循环结果:

// Loop through all sheets
$reader->each(function($sheet) {

    // Loop through all rows
    $sheet->each(function($row) {

    });

});

您可以在http://www.maatwebsite.nl/laravel-excel/docs/import 上找到更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    • 2016-08-21
    • 1970-01-01
    相关资源
    最近更新 更多