Skip to content

Instantly share code, notes, and snippets.

@chetans9
Created November 28, 2017 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chetans9/dda7add3d23c4d42c530eeb37cac0b95 to your computer and use it in GitHub Desktop.
Save chetans9/dda7add3d23c4d42c530eeb37cac0b95 to your computer and use it in GitHub Desktop.
Laravel Export Database to Excel sheet
$users = new User;
$usersArray = $users->select("col1",'col2','col3')
->where('life_member','1')->get()->toArray();
$storage_path = public_path().'/files';
$curr_date = Carbon::now();
Excel::create('export_life_members',function ($excel) use($usersArray,$curr_date){
// Set the title
$excel->setTitle("Exported Life Members on $curr_date");
$excel->sheet('life_members', function($sheet) use ($usersArray) {
//Write Data to the sheet
$sheet->fromArray($usersArray, null, 'A1', false, true);
//Manipulate data.
//set Column headings to bold
$sheet->cells('A1:E1', function($cells) {
$cells->setFontColor('#000000');
$cells->setFontWeight('bold');
});
});
})->download('xlsx');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment