Je rencontre un problème sur le réalisation d'un fichier Excel.
Les donnée provienne de la BDD Myql.
Je réalise unE recherche via unE page .php et le résultat sous forme de table comporte plusieurs données, avec la possibilité d'extraire ce table sous forme d'un fichier Excel.
Code : Tout sélectionner
....
$spreadsheet = new PHPExcel();
$spreadsheet->setActiveSheetIndex(0);
$worksheet = $spreadsheet->getActiveSheet();
$default_border = array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
'color' => array('rgb'=>'1006A3')
);
$style_header = array(
'borders' => array(
'bottom' => $default_border,
'left' => $default_border,
'top' => $default_border,
'right' => $default_border,
),
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb'=>'C6C6C7'),
),
'font' => array(
'bold' => true,
)
);
$style_header1 = array(
'borders' => array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN
)
)
);
$currencyFormat = '#,#0.## \€;[Red]-#,#0.## \€';
$numberFormat = '#,#0.##;[Red]-#,#0.##';
$worksheet->getStyle('A1:J1')->applyFromArray( $style_header );
$worksheet->getStyle('A1:J9')->applyFromArray( $style_header1 );
$worksheet->getStyle('A1:J9')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,));
$worksheet->getColumnDimensionByColumn(0)->setWidth(20);
$worksheet->SetCellValueByColumnAndRow(0, 1, 'Réf. Acquéreur');
$worksheet->SetCellValueByColumnAndRow(0, 2, ''. $donnees['name'] . ' '. $donnees['firstname'] . '');
$worksheet->getColumnDimensionByColumn(1)->setWidth(20);
$worksheet->getStyle('B2:B100')->getNumberFormat()->setFormatCode($currencyFormat);
$worksheet->getColumnDimensionByColumn(2)->setWidth(20);
$worksheet->SetCellValueByColumnAndRow(2, 1, 'Source');
$worksheet->SetCellValueByColumnAndRow(2, 2, ''. $donnees['sources'] . '');
$worksheet->getColumnDimensionByColumn(9)->setWidth(20);
$worksheet->SetCellValueByColumnAndRow(9, 1, 'Qualité');
$worksheet->SetCellValueByColumnAndRow(9, 2, ''. $donnees['good_quality'] . '');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="PROPOSITION AUTOMATIQUE POUR LE PRODUIT DV-'.$donnees['nb_rooms'] .''. $_GET['id'] .'.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = new PHPExcel_Writer_Excel2007($spreadsheet);
$objWriter->save('php://output');
?>
<?php
}
$reponse->closeCursor();
?>
je pense que je dois faire une boucle (foreach) mais je n'arrive pas, ou le tableau est vide, ou il y a une seul donnée.
Merci de votre aide,