1
public function export(){
    view('tester');

    $assignments = DB::table('assignments')
        ->join('projects', 'assignments.project_id', '=', 'projects.id')
        ->join('people', 'assignments.person_id', '=', 'people.id')
        ->join('tasks', 'assignments.id', '=', 'tasks.assignment_id')
        ->select('assignments.*', 'projects.name','people.firstname','people.lastname', 'tasks.description','tasks.hours_spent')
        ->get();

    Excel::create('projects', function($excel) use($assignments) {
        $excel->sheet('Sheet 1', function($sheet) use($assignments) {
            $sheet->fromArray($assignments);
        });
    })->export('xls');


}

xlsへのエクスポートをクリックすると

    <form class="form-horizontal" role="form" method="POST" action="{{action('ReportController@export')}}">

                        <input type="hidden" name="_token" value="{{ csrf_token() }}">  
                        <h4>Task Report</h4>
                        <button type="submit" class="btn btn-info btn-sm pull-right" style="margin-right: 10px">
                            Export to XLS format
                        </button>

エラーは DefaultValueBinder.php 行 65 の ErrorException です: クラス stdClass のオブジェクトを文字列に変換できませんでした。この問題を解決する方法を教えてください。

4

3 に答える 3

1

これを簡単かつシンプルに試してください:-

$assignments = json_decode( json_encode($assignments), true);
于 2017-04-07T11:34:04.133 に答える
0
$filename   = "Report-".date('d-m-Y').'_'.time();
Excel::create($filename, function($excel)use($record)  
      {
        $excel->sheet('Sheet 1', function($sheet)use($record)
    {
  $sheet->loadView('view', compact(array('record')));
    $sheet->setOrientation('portrait');
    });

})->export('xls');
exit();

また、ビューを作成してレコードを表示します<table>が、このビューはレイアウト部分を呼び出しません

于 2016-04-26T10:21:25.773 に答える