Created
November 28, 2017 06:12
-
-
Save chetans9/dda7add3d23c4d42c530eeb37cac0b95 to your computer and use it in GitHub Desktop.
Laravel Export Database to Excel sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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