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
| define("FILENAME",$dossier. $fichier);
$excel=new COM("Excel.application");
$excel->sheetsinnewworkbook=1;
$excel->Workbooks->open($dossier . $fichier);
$book=$excel->Workbooks(1);
$sheet=$book->Worksheets(1);
$i = 1;
while($cell=$sheet->Range('A'.$i) != ""){ $i = $i+ 1; }
$i = $i -1;
$u = 2;
for($u=2; $u<=$i; $u++){
$cell=$sheet->Range('A'.$u);
$date=$cell->value;
$cell=$sheet->Range('B'.$u);
$affectation=$cell->value;
$cell=$sheet->Range('C'.$u);
$gestionnaire=$cell->value;
//PUBLIPOSTAGE
if($u ==2){
$filena="fichier.rtf";
if(file_exists($filena)){
$fp = fopen ($filen, 'r');
$content = fread($fp, filesize($filena));
fclose ($fp);
}
}
$content=str_replace("[date]",utf8_decode($date),$content); $content=str_replace("[affectation]",utf8_decode($affectation),$content);
$content=str_replace("[gestionnaire]",utf8_decode($gestionnaire),$content);
if($u>2){$texte.=" \page ".$content;}
$fp = fopen ( $filena, 'a+' );
fputs($fp,$texte);
fclose ( $fp );
if($u==$i){
header("Content-Type: application/msword" );
header("Content-Disposition: attachment; filename='fichier_final.doc'");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
echo $content;
}
}
//FIN PUBLIPOSTAGE
unset($sheet);
unset($book);
$excel->Workbooks->Close();
$excel->Quit();
unset($excel); |
Partager