【问题标题】:Maatwebsite excel exportMaat网站excel导出
【发布时间】:2018-06-28 15:42:19
【问题描述】:

我有一个使用 maatwebsite 生成文件的简单查询

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use App\MyDB;
use Auth;


 class ReportExport implements FromCollection
{
    public function collection()
    {
        $email = Auth::user()->email;
        return MyDB::MyFunction($email)
                ->select('Reference_Number')->get();
    }
}

一切正常,但如何添加标题?

我尝试查看文档,但它让我更加困惑。 https://laravel-excel.maatwebsite.nl/docs/3.0/export/mapping

【问题讨论】:

    标签: laravel maatwebsite-excel


    【解决方案1】:

    我也必须承认。 Laravel Excel 上的文档试图弄乱你的脑袋。您可以通过向导出类添加 headings 函数来添加标题:

    use Maatwebsite\Excel\Concerns\WithHeadings;
    
     class ReportExport implements FromCollection, WithHeadings
    {
        public function collection()
        {
            $email = Auth::user()->email;
            return MyDB::MyFunction($email)
                    ->select('Reference_Number')->get();
        }
    
        public function headings(): array
            {
                return [
                    'Heading 1',
                    'Heading 2',
                    'Heading 3',  
                ];
            }
    }
    

    【讨论】:

    • 嗨,我需要在哪里添加这个?在 ReportExport 类上?
    • 是的,在您的ReportExport 班级中。
    • 忘记添加一些重要的部分。查看编辑后的帖子。
    • @user3574492 也许你可以帮助我。看看这个:stackoverflow.com/questions/51685886/…
    猜你喜欢
    • 2020-07-18
    • 2018-10-25
    • 1970-01-01
    • 2023-02-01
    • 2018-01-22
    • 2018-04-04
    • 1970-01-01
    • 2022-08-19
    • 2022-09-30
    相关资源
    最近更新 更多