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

bcoder72's avatar

How to export multiple sheet in laravel Excel

i have ExcelController:

 public function dataList(Request $request){
 $data=Mutidbill::select('MUTIDBILL2.TGL_PENCAIRAN','MUTIDBILL2.NPWP','MUTIDBILL2.NO_SPM','MUTIDBILL2.TGL_PENCAIRAN','MUTIDBILL2.NPWPINPUT','MUTIDBILL2.KD_OBJ_PAJAK','MUTIDBILL2.NILBELANJAPJK') ->where('BULAN','=', $request->bulan)->where('TAHUN','=', $request->tahunPph)->get();
 return Excel::download(function($excel) use ($data) {
        // first Sheet
 $excel->sheet('42152223', new ExcelExport($data));
        
        // second Sheet 
 $excel->sheet('Dasar Pemotongan', new SecondSheetExport($data));
        }, 'test.xlsx');
    }

and it downloaded and no data in excel. before it i use

return Excel::download(new ExcelExport($data), 'TEST.xlsx');

its work and showed the data, can you find where ther problem? thank you

0 likes
0 replies

Please or to participate in this conversation.