Last active
March 2, 2018 03:30
-
-
Save bayareawebpro/34bda1fedc3619d020c490601ff42387 to your computer and use it in GitHub Desktop.
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
<?php | |
$results = $this->model->get(array('id','column1','column2','column3', 'etc')); | |
$fileName = 'my-export-'.Carbon::now()->timestamp; | |
$export = $this->excel->create($fileName, function($excel) use ($results) { | |
$excel->setTitle('Our new awesome title') | |
->setCreator('Maatwebsite') | |
->setCompany('Maatwebsite') | |
->setDescription('A demonstration'); | |
$excel->sheet('Sheetname', function($sheet) use ($results) { | |
foreach($results as $index => $result){ | |
//Increment Overide Zero-based Index | |
$index++; | |
//Get Field Names & Data as Array | |
$attributes = $result->getAttributes(); | |
//Set Field Names or Data for Row | |
$sheet->row($index, ($index == 1 ? array_keys($attributes) : $attributes)); | |
} | |
$sheet->setColumnFormat(array( | |
'A' => '0', //id column is integer (column1) | |
'B' => '0', //user_id column is integer (column2) | |
)); | |
}); | |
}); | |
return response()->download($export->download('xls')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment