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 回答
0

如果我使用 DB 来获取数据,我会得到错误....

DefaultValueBinder.php 第 65 行中的 ErrorException:stdClass 类的对象无法转换为字符串

$ret = Excel::create('statsExtract', function($excel) {
    $data = DB::table('thrps')->get();
    $excel->sheet('stats', function($sheet) use($data) {
        $sheet->fromArray($data);
    });
    })->download('xls');

如果我使用 Eloquent 模型进行提取.....它可以工作....

$ret = Excel::create('statsExtract', function($excel) {
    $data = Thrp::all();
    $excel->sheet('stats', function($sheet) use($data) {
        $sheet->fromArray($data);
    });
    })->download('xls');

但是,如果我尝试添加 ->leftJoin 语句,我会收到一个错误,即 leftJoin 不存在 ....

于 2016-04-28T06:37:44.170 回答