【问题标题】:Laravel Maatwebsite Export to excel not workingLaravel Maatwebsite 导出到 excel 不起作用
【发布时间】:2019-05-15 13:49:29
【问题描述】:

我正在使用 Laravel 5.6 和 Laravel-Maat Excel 3.1 版。即使我参考了官方文档,但在将数据导出到 excel 时仍然面临很多问题。

以下是来自 git Click Here to view 的特定文档的链接

我正在尝试将一些数据导出到 excel 文件。但我没有得到工作,它们也没有显示错误。

下面是我的代码

php artisan make:export StudentAttendanceExport --model=Models\Student\StudentAttendenceModel

文件App\Exports\StudentAttendanceExport

    <?php

namespace App\Exports;

use App\Models\Student\StudentAttendenceModel;
use Maatwebsite\Excel\Concerns\FromCollection;

class StudentAttendanceExport implements FromCollection
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return StudentAttendenceModel::all();
    }
}

在我的控制器Reports\ReportsFormProcessController

  namespace App\Http\Controllers\Reports;

  use Illuminate\Http\Request;
  use App\Http\Controllers\Controller;
  use Illuminate\Support\Facades\Response;
  use Illuminate\Support\Facades\Redirect;
  use Illuminate\Support\Facades\Validator;
  use Illuminate\Support\Facades\Input;
  use Illuminate\Support\Facades\URL;
  use Illuminate\Support\Facades\Config;
  use Illuminate\Support\Facades\Cookie;
  use Illuminate\Support\Facades\Session;
  use Illuminate\Support\Facades\View;
  use Illuminate\Support\Facades\File;
  use Illuminate\Support\Facades\Log;
  use App\Models\Student\StudentAttendenceModel;
  //EXCEL
  use App\Exports\StudentAttendanceExport;
  use Maatwebsite\Excel\Facades\Excel; 

    class ReportsFormProcessController extends Controller {
          public function __construct() {
                  parent::__construct();
          }     

            protected function processStdAttendance($data) {
                return Excel::download(new StudentAttendenceModel, 'users.xlsx');
            }

   }

在上面的链接中,他们说Find your users.xlsx in your downloads folder!,但是在哪个路径中搜索了所有目录,但仍然没有找到。

提前致谢

【问题讨论】:

    标签: php excel laravel maatwebsite-excel laravel-excel


    【解决方案1】:

    使用StudentAttendanceExport insted of StudentAttendenceModel

    protected function processStdAttendance($data) {
             return Excel::download(new StudentAttendanceExport, 'users.xlsx');
             //return Excel::download(new StudentAttendenceModel, 'users.xlsx');
    }
    

    【讨论】:

    • 感谢您的回答。
    • 嗨 Dhruv Raval 请求为我的问题提供解决方案 QUESTION LINK 提前致谢
    猜你喜欢
    • 2021-05-26
    • 2019-05-20
    • 2019-06-17
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2020-09-04
    相关资源
    最近更新 更多