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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
<?php
include 'PHPExcel.php';
include 'PHPExcel/Writer/Excel2007.php';
$workbook = new PHPExcel;
$sheet = $workbook->getActiveSheet();
// Tu imposes le choix 2 pour un affichage Html sur Deux colonnes
if($formchoix=="2")
{
$requete="select nom, prenom, tel, fax, mobile, mail, lieudetravail, adresse, fonction, machine.codemachine, codepostal, ville, site from employe, machine, jointure where employe.codee=jointure.codee and jointure.codemachine=machine.codemachine and employe.codee='$formselection' group by machine.codemachine;";
$resultat=mysql_query($requete);
while ($ligneresultat = mysql_fetch_array($resultat))
{
if($ligneresultatbis=mysql_fetch_array($resultat))
{
// Traitement 2 colonnes
}
else
{
// Traitement la dernière colonne si impair des enregistrements
}
}
echo "<br>"."<table border=1 width=150 height=80 align=center bgcolor=#BCBCBC>";
echo "<tr height 20>";
echo "<td align=center>"."<a href='javascript:history.back()'>Retour</a>"."</td>";
echo "</tr>";
echo "</table>";
}
// Choix 3 pour un affichage Excell
if($formchoix=="3")
{
$requete="select nom, prenom, tel, fax, mobile, mail, lieudetravail, adresse, fonction, machine.codemachine, codepostal, ville, site from employe, machine, jointure where employe.codee=jointure.codee and jointure.codemachine=machine.codemachine and employe.codee='$formselection' group by machine.codemachine;";
$resultat=mysql_query($requete);
while ($ligneresultat = mysql_fetch_array($resultat))
{
// Pour chaque champ et de A1 à A13
$sheet->setCellValue('A1',$ligneresultat['nom']);
$sheet->setCellValue('A2',$ligneresultat['prenom']);
// Etc
}
// Finalisation des résultats
$writer = new PHPExcel_Writer_Excel2007($workbook);
$writer->setOffice2003Compatibility(true);
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition:inline;filename=exportationphp.xlsx ');
$writer->save('php://output');
} |
Partager