1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public function exportCSV() {
header("Content-Type: application/ms-xls");
header("Content-Disposition: force-download; filename=\"Données participants éco-certification.csv");
header("Content-Transfer-Encoding: application/ms-xls\n");
// tell the browser we want to save it instead of displaying it
$a = Input::get('agence');
$csv = '';
$csv .= "CODE AGENCE ; MATRICULE ; NOM , PRENOM ; SCORE ; DATE \n";
if ($a == "all") {
$candidats = Candidat::all();
} else {
$agence = Agence::where('code', '=', $a)->first();
$candidats = $agence->candidats;
}
foreach ($candidats as $candidat) {
$csv .= $candidat->agence->code .";". $candidat->matricule .";". $candidat->nom.";". $candidat->prenom.";". $candidat->score.";". date_format(new DateTime($candidat->answered_at), 'd/m/Y') ."\n";
}
echo mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8');
} |
Partager