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

vandan's avatar
Level 13

how to Excel file export with client name?

hello guys i want to export my excel file with client name its dynamic so how to do it?

here is my code

Excel::create(config('constants.scripts-new-name.'.$script_id), 
	function($excel) use ($excelArray,$state,$language,$finalArr) {
                	if(isset($excelArray) && count($excelArray) >0)
                	{
                    	$excel->sheet($state." ".strtoupper($language), function($sheet) use ($excelArray)
                    	{
                        		$sheet->fromArray($excelArray);
                       		$sheet->setWidth(array(
                            		'A'     =>  80,
                            		'B'     =>  10,
                            		'C'     =>  10,
                            		'D'     =>  20,
                            		'E'     =>  30
                        		));
                    	});
                		}
                	foreach($finalArr as $k => $v)
                	{
                    	$excel->sheet(strtoupper($k), function($sheet) use ($v)
                    	{
                       		$sheet->fromArray($v);

                        		$sheet->setWidth(array(
                            		'A'     =>  80,
                            		'B'     =>  20,
                            		'C'     =>  10,
                            		'D'     =>  20,
                            		'E'     =>  30
                        		));
                    	});
                	}
            	})
            	->download("xlsx");
0 likes
10 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Do you mean the file name?

Excel::create($clientModel->name,
1 like
vandan's avatar
Level 13

@sinnbeck yes its working thank you

but i have one more issue can you please help me

current i export file then filename like "Self TPV lead verification - ABC Energy Illinois 12-17-2020 07_31 AM.xlsx"

in file name time is like now print 07_31 but i want 7:31 so :(colon ) is not supported in maatwebsite excel laravel?

i use this format

$currentDateTime = Carbon::now();
$currentDateTime->format('m-d-Y H:i A');
Sinnbeck's avatar

I dont think : is allowed in filenames at all. Are you able to create a file on you computer with : in the name?

1 like
vandan's avatar
Level 13

@sinnbeck yes i try in my computer its create file with colon but in my excel create function not working so its possible or not?

Sinnbeck's avatar

Oh. Didnt think windows supported : in filenames. I would assume : arent allowed as some OS does not support them.

I am quite sure that the excel package replaces them. You can consider creating a PR to allow :

1 like
Sinnbeck's avatar

A PR is a Pull Request. It means that you clone the official repo to your own computer, make changes, and then push them back to the official package repo. The own can then merge your changes in if they like them.

1 like
Snapey's avatar

You should avoid using : in filenames

Its not universally supported and will just cause issues for users of the file

1 like

Please or to participate in this conversation.