Laravel - 多页 Excel

Laravel - Multisheet Excel

我尝试在多个 sheet Excel 中导出我的数据。但是我遇到了

这样的错误

Symfony\Component\ErrorHandler\Error\FatalError Class App\Exports\ReportExport 包含 1 个抽象方法,因此必须声明为抽象方法或实现其余方法 (Maatwebsite\Excel\Concerns\FromQuery::query)

Maatwebsite\Excel\Sheet::formatColumn():参数 #2 ($format) 必须是字符串类型,给定数组,在第 395 行的 C:\xampp\htdocs\healthcare\vendor\maatwebsite\excel\src\Sheet.php 中调用

我的控制器编码是

public function exportproviders($id)
    {
        
        $providerid = $id;  
    
        return Excel::download(new ReportExport($providerid), 'users.xlsx');
    }

报表导出


class ReportExport implements WithMultipleSheets
{
  
    use Exportable;
    public function __construct(int $providerid)
    {
        $this->providerid = $providerid;
        
    }
    public function sheets(): array
    {
        $sheets = [
            new ReportGeneralExport($this->providerid),
            new ReportPracticeExport($this->providerid),
            new ReportEducationExport($this->providerid),
            new ReportWorkingExport($this->providerid),
            new ReportCertificateExport($this->providerid),
            new ReportReferenceExport($this->providerid),
            new ReportQuestionsExport($this->providerid),
            new ReportDocumentsExport($this->providerid),
        ];

        return $sheets;
    }
}

ReportGeneralExport

use App\Models\Providerinfo;

class ReportGeneralExport implements FromQuery, WithHeadings, WithTitle, ShouldAutoSize, WithColumnFormatting, WithMapping
{
    use Exportable;

    public function __construct(int $providerid)
    {
        $this->providerid = $providerid;
    }

    public function map($row): array
    {
        return [
            $row['providername'],
            $row['middlename'],
            $row['lastname'],
            $row['email'],
            $row['official_email'],
            $row['home_address'],
            $row['home_city'],
            $row['home_state'],
            $row['home_country'],
            $row['home_zipcode'],
            $row['mail_address'],
        ];
    }
    public function query()
    {
        return Providerinfo::where('id',$this->providerid)->get();
    }

    public function headings(): array
    {
        return [
            'First Name',
            'Middle Name',
            'Last Name',
            'Email Id',
            'Other Email Id',
            'Home Address',
            'Home City',
            'Home State',
            'Home Country',
            'Home Zipcode',
            'Mail Address',
        ];
    }
}

使用 Providerid 从 providerinfo table.

获取数据

你的 ReportGeneralExport class 里面有很多工具。

我看到 WithTitle 但没有实施:

public function title(): string;

要么实现它,要么从你的工具中移除 WithTitle

我也看到 WithColumnFormatting 但没有实施:

public function columnFormats(): array;

实施它或从您的工具中移除 WithColumnFormatting

同时从您的查询中删除 ->get()

    public function query()
    {
        return Providerinfo::where('id',$this->providerid)->get();
    }

根据 documentation 它说:

Be sure to not ->get() the results!