Skip to content
Advertisement

Laravel – Multisheet Excel

I tried to export my data in multi sheet Excel. But I face the error like

SymfonyComponentErrorHandlerErrorFatalError Class AppExportsReportExport contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (MaatwebsiteExcelConcernsFromQuery::query)

MaatwebsiteExcelSheet::formatColumn(): Argument #2 ($format) must be of type string, array given, called in C:xampphtdocshealthcarevendormaatwebsiteexcelsrcSheet.php on line 395

My controller coding is

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

ReportExport

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 AppModelsProviderinfo;

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',
        ];
    }
}

Using Providerid to get the data from the providerinfo table.

Advertisement

Answer

Your ReportGeneralExport class contains a lot of implements there.

I see WithTitle but no implementation of:

public function title(): string;

Either implement it or remove WithTitle from your implements.

I also see WithColumnFormatting but no implementation of:

public function columnFormats(): array;

Either implement it or remove WithColumnFormatting from your implements.

Also remove the ->get() from your query:

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

As per the documentation it says:

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

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement