PHPExcel: exporter les données provenant de la BDD
Bonjour,
je veux exporter vers Excel une liste dont les données proviennent de ma BDD en utilisant PhpExcel. Le problème c'est que seule dernière première ligne de ma table BDD s'affiche.
Mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| require('../script/dbConnexion.php');
require 'Classes/PHPExcel.php';
require 'Classes/PHPExcel/Writer/Excel2007.php';
$workbook = new PHPExcel;
$sheet = $workbook->getActiveSheet();
$sheet->setCellValueByColumnAndRow(1, 1, 'CIVILITE');
$sheet->setCellValueByColumnAndRow(2, 1, 'NOM');
$sheet->setCellValueByColumnAndRow(3, 1, 'PRENOM');
$sheet->setCellValueByColumnAndRow(4, 1, 'SOCIETE');
$sheet->setCellValueByColumnAndRow(5, 1, 'FONCTION');
$sheet->setCellValueByColumnAndRow(6, 1, 'PAYS');
$sheet->setCellValueByColumnAndRow(7, 1, 'VISA');
$sheet->setCellValueByColumnAndRow(8, 1, 'CONTACT');
$sheet->setCellValueByColumnAndRow(9, 1, 'E-MAIL');
$query = 'SELECT * FROM preinscription WHERE lieu = "'.$_SESSION['lieu'].'" ORDER BY dateinscription DESC';
$query = $connect_db->query($query);
$query->setFetchMode(PDO::FETCH_NUM);
$list = $query->fetchAll();
foreach($list as $data) {
for($i=0; $i<=9; $i++){
$info = $data[$i];
$sheet->setCellValueByColumnAndRow($i, 2, $data[$i]);
}
}
$writer = new PHPExcel_Writer_Excel2007($workbook);
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition:inline;filename=liste participants.xlsx ');
$writer->save('php://output'); |
Comment récupérer toutes les lignes durant l'exportation ?