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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| <?php
include("./config/config.inc.php");
include './Classes/PHPExcel.php';
include './Classes/PHPExcel/Writer/Excel2007.php';
// Variable pour fichier excel
$workbook = new PHPExcel;
$sheet = $workbook->getActiveSheet();
$sheet->getColumnDimension('A')->setAutoSize(true);
$sheet->getColumnDimension('B')->setAutoSize(true);
$sheet->getColumnDimension('C')->setAutoSize(true);
$sheet->getColumnDimension('D')->setAutoSize(true);
$sheet->getColumnDimension('E')->setAutoSize(true);
$sheet->getColumnDimension('F')->setAutoSize(true);
$sheet->getColumnDimension('G')->setAutoSize(true);
$sheet->getColumnDimension('H')->setAutoSize(true);
$sheet->getColumnDimension('I')->setAutoSize(true);
$styleA1 = $sheet->getStyle('A1');
$styleFont = $styleA1->getFont()
->applyFromArray(array(
'bold'=>true,
'size'=>11,
'name'=>'Arial',
'color'=>array(
'rgb'=>'000000')));
$sheet->duplicateStyle($styleA1,'A1:J1');
$sql1.=" ORDER BY field_1 DESC,field_2 ASC, field_3 ASC";
$requete = mysql_query($sql1, $cnx) or die('Erreur SQL !'.$sql1.'<br>'.mysql_error());
// Traitement
$nb = mysql_num_rows($requete);
if ($nb >=1){
echo ('<img style="border:0;" alt="Sauvegarder" src="./pages/regie/media/save.png"><a style="text-decoration:none;" href=\'/backups/regie/' . 'export' . '_' . date('dmY_h_i') . '.xlsx' . '\'> Sauvegarder</a>');
echo '<table cellpadding="0" cellspacing="0" id="tableprint" width="100%">';
echo '<tr class="tdexport"><td></td><td>Versé le</td><td>Dans l\'espace</td><td>Nature</td><td>Civ.</td><td>Prénom</td><td>Nom</td><td>Prix</td><td>En</td></tr>';
$sheet1 = 0;
while($data = mysql_fetch_array($requete))
{
$field_0 = mysql_real_escape_string(stripcslashes(utf8_decode($data['field_0'])));
$field_1 = mysql_real_escape_string(stripcslashes(utf8_decode(date('d/m/Y', strtotime($data['field_1'])))));
$field_2 = mysql_real_escape_string(stripcslashes(utf8_decode($data['field_2'])));
$field_3 = mysql_real_escape_string(stripcslashes(utf8_decode($data['field_3'])));
$field_4 = mysql_real_escape_string(stripcslashes(utf8_decode($data['field_4'])));
$field_5 = mysql_real_escape_string(stripcslashes(utf8_decode($data['field_5'])));
$field_6 = mysql_real_escape_string(stripcslashes(utf8_decode($data['field_6'])));
$field_7 = mysql_real_escape_string(stripcslashes(utf8_decode($data['field_7'])));
$field_8 = mysql_real_escape_string(stripcslashes(utf8_decode($data['field_8'])));
$field_9 = mysql_real_escape_string(stripcslashes(utf8_decode($data['field_9'])));
echo'<tr class="trexport">';
if (isset($data['field_9']) && !empty($data['field_9']))
echo'<td class="someClass" title="Commentaire : '.$data['field_9'].'" style="text-align:center;">
<img border=0 width=12 height=12 src="pages/regie/media/tip.png">
</td>';
if (empty($data['field_9'])) echo'<tr class="trexport"><td></td>';
echo'<td class="trexport" style="text-align:center;">'.date("d/m/Y", strtotime($data['field_1'])).'</td>
<td class="trexport">'.$data['field_2'].'</td>
<td class="trexport">'.$data['field_3'].'</td>
<td class="trexport">'.$data['field_4'].'</td>
<td class="trexport">'.$data['field_5'].'</td>
<td class="trexport">'.$data['field_6'].'</td>
<td class="trexport" style="text-align:right;">'.$data['field_7'].' </td>
<td class="trexport" style="text-align:center;">'.$data['field_8'].'</td>
</tr>';
$datarow=2;
if($sheet1) $workbook->createSheet();
$workbook->setActiveSheetIndex($sheet1);
$sheet->setCellValue('A1','Par');
$sheet->setCellValue('B1','Versé le');
$sheet->setCellValue('C1','Dans l\'espace');
$sheet->setCellValue('D1','Nature');
$sheet->setCellValue('E1','Civilité');
$sheet->setCellValue('F1','Prénom');
$sheet->setCellValue('G1','Nom');
$sheet->setCellValue('H1','Prix');
$sheet->setCellValue('I1','Versé en');
$sheet->setCellValue('J1','Commentaires');
extract($data);
$sheet->getCell('A'.$datarow)->setValue($field_0);
$sheet->getCell('B'.$datarow)->setValue($field_1);
$sheet->getCell('C'.$datarow)->setValue($field_2);
$sheet->getCell('D'.$datarow)->setValue($field_3);
$sheet->getCell('E'.$datarow)->setValue($field_4);
$sheet->getCell('F'.$datarow)->setValue($field_5);
$sheet->getCell('G'.$datarow)->setValue($field_6);
$sheet->getCell('H'.$datarow)->setValue($field_7);
$sheet->getCell('I'.$datarow)->setValue($field_8);
$sheet->getCell('J'.$datarow)->setValue($field_9);
$datarow++;
}
$workbook->setActiveSheetIndex(0);
$writer = new PHPExcel_Writer_Excel2007($workbook);
$writer->setOffice2003Compatibility(true);
$records = './backups/regie/' . 'export' . '_' . date('dmY_h_i') .'.xlsx';
$writer->save($records);
echo '</table><br />';
?> |
Partager