Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Fajar's avatar
Level 2

excel export with multiple sheet

hello I want to ask

how do you make an excel export with multiple sheets

I have an attendance table with fields

level, major

I want to group data into

sheets are taken according to major and level

as an example

Level = 1 Department = DKV

name Sheet = DKV1 and all data related to both parameters can be retrieved

thanks for the suggestion

0 likes
3 replies
Fajar's avatar
Level 2

this my code

RekapExport.php

public function __construct(string $keyword)
    {
        $this->jurusan = $keyword;
    }
    public function sheets(): array
    {
        $sheets = [];
        $sheets[] = new SheetXAKL($this->jurusan);
        $sheets[] = new SheetXDKVRPL($this->jurusan);
        return $sheets;
    }

SheetXAKL.php

private $jurusan;
    
    public function __construct(string $jurusan)
    {
        $this->Jurusan = $jurusan;
    }

    public function query()
    {
        return rekap::query()
                    ->where('Jurusan','=','AKL')
                    ->where('Tingkat','=','X');
    }
    public function title(): string
    {
        return 'AKL';
    }

if it's like this I have to create each file for each major and level differ only in parts

public function query()
    {
        return rekap::query()
                    ->where('Jurusan','=','AKL')
                    ->where('Tingkat','=','X');
    }

and call the file here

public function sheets(): array
    {
        $sheets = [];
        $sheets[] = new SheetXAKL($this->jurusan);
        $sheets[] = new SheetXDKVRPL($this->jurusan);
        return $sheets;
    }

and this is very inefficient in making code

Please or to participate in this conversation.