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
|
public function executeExcel(sfWebRequest $request)
{
$this->setLayout(false);
$excel = new sfPhpExcel();
$excel->setActiveSheetIndex(0);
$excel->getActiveSheet()->setCellValue('A3',utf8_encode('Référence'));
$excel->getActiveSheet()->setCellValue('B3',utf8_encode('Nom et Prénom'));
$excel->getActiveSheet()->setCellValue('C3',utf8_encode('Département'));
$excel->getActiveSheet()->setCellValue('D3',utf8_encode('Activité'));
$excel->getActiveSheet()->setCellValue('E3',utf8_encode('Activité'));
$excel->getActiveSheet()->setCellValue('F3',utf8_encode('Date'));
$excel->getActiveSheet()->setCellValue('G3',utf8_encode('Colonne test'));
$q = $this->buildQuery();
$repreneurslisting = $q->execute();
$i = 4;
foreach($repreneurslisting as $rep) {
$p = Doctrine_Query::create()
->select('id, nom_rep, prenom_rep, departement_id')
->from('EtatCivilRep r')
->where('r.repreneur_id=?',$rep->getId());
$proprio = $p->fetchOne();
$r = Doctrine_Query::create()
->select('id')
->from('FinanceRep f')
->where('f.repreneur_id=?',$rep->getId());
$finance = $r->fetchOne();
if ($proprio['departement_id']<>"") {
$s = Doctrine_Query::create()
->select('id, nom')
->from('Departement d')
->where('d.id=?',$proprio['departement_id']);
$dep = $s->fetchOne();
$excel->getActiveSheet()->setCellValue('C'.$i,$dep['nom']);
}
if ($rep->getSecteurAct1Id()<>"") {
$t = Doctrine_Query::create()
->select('id')
->from('SecteurAct s')
->where('s.id=?',$rep->getSecteurAct1Id());
$act1 = $t->fetchOne();
$excel->getActiveSheet()->setCellValue('D'.$i,$act1->getNom());
}
if ($rep->getSecteurAct2Id()<>"") {
$u = Doctrine_Query::create()
->select('id')
->from('SecteurAct s')
->where('s.id=?',$rep->getSecteurAct2Id());
$act2 = $u->fetchOne();
$excel->getActiveSheet()->setCellValue('E'.$i,$act2->getNom());
}
$excel->getActiveSheet()->setCellValue('A'.$i,$rep->getNumRepreneur());
$excel->getActiveSheet()->setCellValue('B'.$i,$proprio['nom_rep']." ".$proprio['prenom_rep']);
$excel->getActiveSheet()->setCellValue('F'.$i,date('d/m/Y',strtotime($rep->getDatePremier())));
if (isset($finance['apport_dispo'])) {
$excel->getActiveSheet()->setCellValue('G'.$i,$finance['test_dispo']);
} else {
$excel->getActiveSheet()->setCellValue('G'.$i,0);
}
$i++;
}
$j = $i + 1;
$excel->getActiveSheet()->setCellValue('A'.$j,'TOTAL');
$excel->getActiveSheet()->setCellValue('B'.$j,$i-4);
$excel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', '/xxxx/xxxxx/xxxx/excel/test_excel.php'));
$this->redirect('/excel/repreneur_excel.xls');
} |
Partager