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

Crazylife's avatar

How to set the grand total with col span using Maatwebsite/Laravel-Excel?

I pull the data from database and export to xls file, i showed header and content, but how can i include the grand total with colspan based on column to the excel?

// header, content

$someArray = [];$total_qr = "";  $total = "";
            foreach ($results as $key => $r) {
                $row = array();
                $row['No.'] = $key+1;
                foreach($groupOption as $go) {
                    if ($go == 1) {
                        $row['Name'] = $r->name;
                    }
                    if ($go == 2) {
                        $row['Address'] = $r->address;
                    }
                    }

            
                //$row['Total'] =  $r->total;
                   $paArray[] = $row;
            }
   
            
            $today = Carbon::now()->toDateString();
        $myFile=  Excel::create('Report_'. $today, function($excel) use ($someArray )
            {
                $excel->setTitle('Report');
                $excel->sheet('Report', function($sheet) use ($someArray ) {
                    $sheet->fromArray($someArray , null, 'A1', true);
                });
            });
    }

Currently, i show my header and content in excel. Butow can i set e.g. grand total at the end of the content with colspan?? Thanks.

0 likes
0 replies

Please or to participate in this conversation.