IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Problème Export Excel depuis passage en PHP 5


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 20
    Par défaut Problème Export Excel depuis passage en PHP 5
    Bonjour tout le monde et bonne année, si vous pouviez m'aider je vous en serait très reconnaissant!

    J'ai une page qui génère des statistiques :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    <?php  
    include "base.php";
    include_once("excel.php");
     
    if ($_SESSION["nummembre"]=="") {header("Location: index.php"); exit;}
     
    $datedebut=@$_GET["datedebut"];
    $datefin=@$_GET["datefin"];
    $inter=@$_GET["inter"];
    $numob=@$_GET["numob"];
    $nomclient=@$_GET["nomclient"];
    $numcoeff=@$_GET["numcoeff"];
    $titre=@$_GET["titre"];
    $tech=@$_GET["tech"];
     
     
     
    if ($datedebut=="") {$datedebut=date("d/m/Y",time()-30*24*60*60);}
    if ($datefin=="") {$datefin=date("d/m/Y");}
     
    $datedebut2=substr($datedebut,6,4)."-".substr($datedebut,3,2)."-".substr($datedebut,0,2)." 00:00:00";
    $datefin2=substr($datefin,6,4)."-".substr($datefin,3,2)."-".substr($datefin,0,2)." 23:59:59";
     
    //if ($nb>0) { for ($x=1;$x<=$nb;$x++){$choixentite[]=@$_GET["entite$x"]; $sqlentite.=" interventions.nument = '".$choixentite[$x-1]."' or";}	 }
    //else
    	//{ 	
    	for ($x=1;$x<=10;$x++)
    	{
    		if ($_SESSION["nument"]==$x)
    		{
    			$choixentite[]=$x; 
    		}
    		else
    		{
    			$choixentite[]=""; 
    		}
    	}
    	//}
    //$sqlentite=substr($sqlentite,0,strlen($sqlentite)-2);
     
     
    //exportation vers excel 
    if(isset($_GET["Excel"]))
    {
    	mettreDansExcel($datedebut,$datefin,$numcoeff,$inter,$numob,$nomclient,$tech);
    }
     
    if(isset($_GET["subclient"]))
    {
    	statClients($datedebut,$datefin,$nomclient);
    }
     
    if(isset($_GET["subtech"]))
    {
    	statTechs($datedebut,$datefin,$tech);
    }
     
    ?>
     
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Menu du haut</title>
    <style type="text/css">
    <!--
    body {
    	background-color: #e8e8e0;
    	margin-left: 0px;
    	margin-top: 0px;
    	margin-right: 0px;
    	margin-bottom: 0px;
    }
    -->
    </style>
    <link href="styles/style.css" rel="stylesheet" type="text/css">
    <style type="text/css">
    <!--
    .Style1 {
    	color: #FF0000;
    	font-weight: bold;
    }
    -->
    </style>
    </head>
     
    <body>
    <script>
    		function NoError()  {  return true;  } 
    		window.onerror=NoError;
     
    </script>
    <?php  if ($_SESSION["seslimited"]==1) { exit ; } ?>
     
    <form name="form" method="get" action="">     
     
    <table width='99%' align='center' border='0' cellpadding='0' cellspacing='0' class="fondtableau">
    	<tr class='entete1'>
    		<td colspan='2'>
    			<table width="100%"  border="0" cellspacing="0" cellpadding="0">
    				<tr>
    					<td width='50'>&nbsp;STATISTIQUES</td>
    					<td width="5"><img src="images/newbarre2vert.gif" width="5" height="13"></td>
    					<td class="barreorange">&nbsp;</td>
    				</tr>
    			</table>
    		</td>
    	</tr>
    </table>
    <?php  if ($_SESSION["status"]!=1) {?>
    <table class='fond1' width='99%' align='center' cellpadding="0" cellspacing="0">
      <tr>
    <?php 
    // extraction des différentes entités
    $sql="select * from entites"; $result=mysql_query($sql); $x=0;
     
    $x=0;
    while($ligne=mysql_fetch_array($result)) 
    {
    	$nument=$ligne["nument"]; $nom=$ligne["nom"]; $x++;
    	$nomentite[$nument]=$nom;
    	?> <td  class="fondbleu2"><input  name="entite<?php  echo $x?>" type="checkbox" id="entite" value="<?php  echo $nument ;?>" <?php  if ($choixentite[$x-1]!="") { echo "checked";}?>><?php  echo $nom ;?></td> <?php 
    	if ($x %5 ==0) { echo "</tr><tr>";}
    }
    ?>
    </tr><tr><td class="fondbleu2" colspan='<?php  echo $x ;?>'><div style='cursor:hand' align="center">TOUS</div></td></tr></table>
    <?php  } else {?>
     
     
    <?php 
    // extraction des différentes entités
    $sql="select * from entites"; 
    $result=mysql_query($sql); 
    $x=0;
     
    while($ligne=mysql_fetch_array($result)) 
    {
    	$nument=$ligne["nument"]; $nom=$ligne["nom"]; $x++;
    	$nomentite[$nument]=$nom;
    	?> <input  name="entite<?php  echo $x?>" type="hidden" id="entite" value="<?php  echo $nument ;?>">
     
    <?php  } ?>
     
    <?php  } ?>
     
    <table width="99%" border="0"   align='center' cellpadding="0" cellspacing="0" class="fond1">
        <tr class="fondbleu2">
    		<td>P&eacute;riode&nbsp;
    			<input name="datedebut" title="Date de début" type="text" id="datedebut" value="<?php  echo $datedebut;?>" size="6">
    			&agrave;
    			<input name="datefin" title="Date de fin" type="text" id="datefin" value="<?php  echo $datefin ;?>" size="6"> 
    		</td>
    		<td>
    			<select name="numcoeff" style="width: 80px" id="numcoeff">
    				<option value="">Tous coeff</option>				
    				<?php 
    					$sql="select * from coeffcps where coeff>0 order by coeff, type ";
    					$result=mysql_query($sql);
     
    					while($ligne=mysql_fetch_array($result))
    					{
    					$numcoeff2=$ligne["numcoeff"]; 	$type=$ligne["type"]; 	$coeff=$ligne["coeff"]; $type.=" (C$coeff)";
    				?>
    				      <option <?php  if (@$numcoeff==$numcoeff2) { echo " selected ";} ?> value="<?php  echo $numcoeff2 ?>"><?php  echo $type?></option>
    				<?php  
    				  }
    				?>
    			</select>
    		</td>
    		<td colspan="2">
    			<select style="width: 80px" name="inter">
    				<option value="">Tous types</option>
    				<?php  
    				$sql="select * from typeinter";$result=mysql_query($sql);$x=0;
     
    				while($ligne=mysql_fetch_array($result))
    				{
    				$x++;$numinter2=$ligne["numinter"]; $inter2=$ligne["inter"]; 
    				?>	  
    					<option <?php  if($inter2==@$inter){echo"selected";}?> value="<?php  echo $inter2 ?>"><?php  echo $inter2 ;?></option>
    				<?php  
    				} ?>
    			</select>
    		</td>
    		<td>
    			<select style="width: 90px" name="numob">
    				<option value="">Tous domaines</option>
    				<?php  $sql="select * from typeobjets";$result=mysql_query($sql);$x=0;
     
    				while($ligne=mysql_fetch_array($result))
    				{
    				$x++; $numob2=$ligne["numob"];  $objet=$ligne["objet"]; 
    				?>
    			          <option <?php  if($numob2==@$numob){echo"selected";}?>  value="<?php  echo $numob2 ?>"><?php  echo $objet ;?></option>
    			          <?php  
    				} ?>
    	          </select>
    		</td>
        </tr>
    </table>
    <table width="99%" border="0"   align='center' cellpadding="0" cellspacing="0" class="fond1">
        <tr class="fondbleu2">
    		<td width="50%" align="left">
    			Client : 
    			<input name="nomclient" title="Client" type="text" id="nomclient" value="<?php  echo $nomclient;?>" size="12">
    		</td>
    		<td width="50%" align="center">
    			<input name="subclient"  type="submit" value="Stats Clients"  align="bottom" title="Fichier excel des statistiques Clients">
    		</td>
    	</tr>
    	<tr class="fondbleu2">
    		<td width="60%" align="left">
    			Tech :
    		  	<select name="tech" id="tech">
    				<option value="">Tous les techs</option>
    				<?php  
    					$sql="select * from membres where status=2 or status=4 or status=9 order by nom";
    					$result=mysql_query($sql);
    				?>
    				<?php 
    					while($ligne=mysql_fetch_array($result))
    					{
    					$nummembre=$ligne["nummembre"]; 	$nom=$ligne["nom"]; 	$status=$ligne["status"]; 
    					if ($status==2) { $nom.=" (Techn)";}
    					if ($status==4) { $nom.=" (Ext)";}
    					if ($status==9) { $nom.=" (Sup)";}
    				?>
    				      <option <?php  if (@$tech==$nummembre) { echo " selected ";} ?> value="<?php  echo $nummembre ?>"><?php  echo $nom?></option>
    				<?php  
    				  }
    				?>
    			</select>
    		</td>
    		<td width="40%" align="center">
    			<input name="subtech"  type="submit" value="Stats techniciens"  align="bottom" title="Fichier excel des statistiques Techniciens">
    		</td>
        </tr>
    </table>
    <table width="99%" border="0"   align='center' cellpadding="0" cellspacing="0" class="fond1">
    	<tr class="fondbleu2">
    		<td align="center">
    			<input name="Excel" type="submit" value="Exporter vers Excel">		
    		</td>
    	</tr>
    </table>
     
    </form>
     
    </body>
    </html>
    La page excel.php :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    <?php 
     
    	function bonFormat($chaine)
    	//remplace les \n et \r par des ' '
    	{
    		$chaine=str_replace("\n"," ",$chaine);
    		$chaine=str_replace("\r"," ",$chaine);
     
    		return $chaine;
    	}
     
    	function numToMembre()
    	//retourne le tableau avec l'ensemble des membres et leurs numéros
    	{
    		$req='SELECT nummembre, nom FROM membres';
    		$result=mysql_query($req);
     
    		while($ligne=mysql_fetch_array($result))
    		{
    			$tab[$ligne["nummembre"]]=$ligne["nom"];
    		}
     
    		return $tab;
    	}
     
    	function numToClient($nb)
    	//retourne le nom du client en fonction du numéro
    	{
    		$req='SELECT nom FROM clients WHERE code='.$nb;
    		$result=mysql_query($req);
     
    		$ligne=mysql_fetch_array($result);
    		return $ligne["nom"];
    	}
     
    	function ecrireExcel($info)
    	{
    		define("FILENAME","C:/Program Files/EasyPHP5.3.0/www/flytech/recherche.xls");
     
    		if(file_exists(FILENAME))
    		{
    		        unlink(FILENAME);
    		}
     
    		$excel=new COM("Excel.application");
    		$excel->sheetsinnewworkbook=1;
    		$excel->Workbooks->Add();
    		$book=$excel->Workbooks(1);
    		$sheet=$book->Worksheets(1);
    		$sheet->Name="Statistiques";
     
    		$titre=array("Intervention","Date de création","Client","Objet","Type","Domaine","Début","Fin","Durée","Technicien","Description","Coefficient");
     
    		#ajoute les titres
    		$j=65;
    		foreach($titre as $val)
    		{
    			$cell=$sheet->Range(chr($j).'1'); 
    			$cell->value=$val;
    			$cell->Font->bold = true;
    			$j++;
    		}
     
    		$cle=array_keys($info);
    		sort($cle);
     
    		#ajoute les données dans les cellules
    		$j=3;
    		foreach($cle as $c)
    		{
    			$temp=$info[$c];
    			$taille=count($temp);
    			$i=1;
     
    			while ($i <= $taille)
    			{
    				$cell=$sheet->Range('A'.$j); 
    				$cell->value=$info[$c][$i]["num"];
    				$cell=$sheet->Range('B'.$j); 
    				$cell->value=$info[$c][$i]["creation"];
    				$cell=$sheet->Range('C'.$j); 
    				$cell->value=$info[$c][$i]["nomC"];
    				$cell=$sheet->Range('D'.$j); 
     
    				if($i==1)
    				{
    					$cell->value=$info[$c][$i]["objet"];
    					$cell=$sheet->Range('E'.$j); 
    					$cell->value=$info[$c][$i]["typeinter"];
    					$cell=$sheet->Range('F'.$j); 
    					$cell->value=$info[$c][$i]["typeobjet"]; 
    				}
     
    				$cell=$sheet->Range('G'.$j);
    				$cell->value=$info[$c][$i]["debut"];
    				$cell=$sheet->Range('H'.$j); 
    				$cell->value=$info[$c][$i]["fin"];
    				$cell=$sheet->Range('I'.$j); 
    				$cell->value=$info[$c][$i]["temps"];
    				$cell=$sheet->Range('J'.$j); 
    				$cell->value=$info[$c][$i]["nomM"];
    				$cell=$sheet->Range('K'.$j); 
    				$cell->value=$info[$c][$i]["rem"];
    				$cell=$sheet->Range('L'.$j); 
    				$cell->value=$info[$c][$i]["coeff"];
     
    				$i++;
    				$j++;
    			}			
    		}
     
    		$j=65;
    		for($j=65;$j<77;$j++)
    		{
    			$cell=$sheet->Range(chr($j).':'.chr($j));
    			$cell->EntireColumn->AutoFit();
    			$cell->HorizontalAlignment=-4108;
    		}
     
    		//$cell=$sheet->Select();
     
    		$book->saveas(FILENAME);
    		unset($sheet);
    		unset($book);
    		$excel->Workbooks->Close();
    		$excel->Quit();
    		unset($excel);			
    	}
     
    	function ecrireExcelStatTech($info,$t)
    	{
    		define("FILENAME","C:/Program Files/EasyPHP5.3.0/www/flytech/Statistiques_Techniciens.xls");
     
    		if(file_exists(FILENAME))
    		{
    		        unlink(FILENAME);
    		}
     
    		$excel=new COM("Excel.application");
    		$excel->sheetsinnewworkbook=1;
    		$excel->Workbooks->Add();
    		$book=$excel->Workbooks(1);
    		$sheet=$book->Worksheets(1);
    		$sheet->Name="Statistiques";
     
    		//on fait le fichier excel
    		$titre=array("Client","Intervention","Temps effectué","Temps prévu sur site","Temps prévu en atelier","Temps facturé");
     
    		//ajoute les titres
    		$j=66;
    		foreach($titre as $val)
    		{
    			$cell=$sheet->Range(chr($j).'1'); 
    			$cell->value=$val;
    			$cell->Font->bold = true;
    			$j++;
    		}	
     
    		$inter=$info["inter"];
    		$autre=$info["autre"];
    		//cas de tous les tech
    		if($t=="")
    			$membre=recupTech();
    		//cas d'un tech
    		else
    			$membre=array(0 => $t);
     
    		$numToMembre=numToMembre();
     
    		$totalInter=array();
    		$totalClient=array();
    		$totalTps=0;
    		$totalTpsPrevS=0;
    		$totamTpsPrevA=0;
     
    		$j=4;
    		foreach($membre as $mb)
    		{
    			$i=0;
    			$tabI=$inter[$mb];
    			$tabA=$autre[$mb];
     
    			$cell=$sheet->Range('A'.$j); 
    			$cell->value=$numToMembre[$mb];
    			$cell->Font->bold = true;
     
    			$place=$j+2;
    			$total1=0;
    			$total2=0;
     
    			$j++;
     
    			if(isset($tabI[0]["nomM"]))
    			{
     
    				foreach($tabI as $val)
    				{
    					$cell=$sheet->Range('B'.$j); 
    					$cell->value=$val["nomC"];
    					$cell=$sheet->Range('C'.$j); 
    					$cell->value=$val["num"];
    					$cell=$sheet->Range('D'.$j); 
    					$cell->value=$val["tps"];
    					$cell=$sheet->Range('E'.$j); 
    					$cell->value=$val["site"];
    					$cell=$sheet->Range('F'.$j); 
    					$cell->value=$val["atelier"];
    					$cell=$sheet->Range('G'.$j); 
    					$cell->value=$val["duree_facturee"];
     
    					$total1+=$val["tps"];
    					$total2++;
    					$totalTps+=$val["tps"];
    					if(!isset($totalClient[$val["nomC"]]))
    						$totalClient[$val["nomC"]]=1;
    					else
    						$totalClient[$val["nomC"]]++;
    					if(!isset($totalInter[$val["num"]]))
    						$totalInter[$val["num"]]=0;
    					else
    						$totalInter[$val["num"]]++;
    					$totalTpsPrevS+=$val["site"];
    					$totamTpsPrevA+=$val["atelier"];
    					$totamTpsPrevF+=$val["duree_facturee"];
     
    					$j++;
    				}
     
    				if($total2<=5)
    					$j=$place+6;
    				else
    					$j=$j+2;
     
    			}
    			else
    			{
    				$cell=$sheet->Range('B'.$j); 
    				$cell->value="Non renseigné";
    				$cell=$sheet->Range('C'.$j); 
    				$cell->value="Non renseigné";
    				$cell=$sheet->Range('D'.$j); 
    				$cell->value="Non renseigné";
    				$cell=$sheet->Range('E'.$j); 
    				$cell->value="Non renseigné";
    				$cell=$sheet->Range('F'.$j); 
    				$cell->value="Non renseigné";
     
    				$j=$place+6;
    			}
     
    			//on affiche les totaux
     
    			if(isset($autre[$mb]))
    			{
    				$temp=$autre[$mb]["autre"];
    				$vacs=$autre[$mb]["vacs"];
    			}
    			else
    			{
    				$temp="0";
    				$vacs="0";
    			}
     
    			$cell=$sheet->Range('A'.$place);
    			$cell->value="Nb interventions: ".$total2;
    			$cell->Font->Italic= true;
    			$place++;
    			$cell=$sheet->Range('A'.$place);
    			$cell->value="Total en intervention : ".$total1." heures";
    			$cell->Font->Italic= true;
    			$place++;
    			$cell=$sheet->Range('A'.$place);
    			$cell->value="Total autres: ".$temp." heures";
    			$cell->Font->Italic= true;
    			$place++;
    			$cell=$sheet->Range('A'.$place);
    			$cell->value="Total congés: ".$vacs." heures";
    			$cell->Font->Italic= true;
     
     
    		}
     
    		//on affiche les totaux généraux
    		$cell=$sheet->Range('A2');
    		$cell->value="Total: ";
    		$cell->Font->Italic= true;
    		$cell=$sheet->Range('B2');
    		$cell->value=count($totalClient);
    		$cell=$sheet->Range('C2');
    		$cell->value=count($totalInter);
    		$cell=$sheet->Range('D2');
    		$cell->value=$totalTps;
    		$cell=$sheet->Range('E2');
    		$cell->value=$totalTpsPrevS;
    		$cell=$sheet->Range('F2');
    		$cell->value=$totamTpsPrevA;
    		$cell=$sheet->Range('G2');
    		$cell->value=$totamTpsPrevF;
     
    		for($j=65;$j<72;$j++)
    		{
    			$cell=$sheet->Range(chr($j).':'.chr($j));
    			$cell->EntireColumn->AutoFit();
    			$cell->HorizontalAlignment=-4108;
    		}
     
    		$book->saveas(FILENAME);
    		unset($sheet);
    		unset($book);
    		$excel->Workbooks->Close();
    		$excel->Quit();
    		unset($excel);	
    	}
     
    	function ecrireExcelStatClient($info)
    	{
    		define("FILENAME","C:/Program Files/EasyPHP5.3.0/www/flytech/Statistiques_Clients.xls");
    		if(file_exists(FILENAME))
    		{
    		        unlink(FILENAME);
    		}
     
    		$excel=new COM("Excel.application");
    		$excel->sheetsinnewworkbook=1;
    		$excel->Workbooks->Add();
    		$book=$excel->Workbooks(1);
    		$sheet=$book->Worksheets(1);
    		$sheet->Name="Statistiques";
     
    		//on fait le fichier excel
    		$titre=array("Intervention","Technicien","Temps interventions");
     
    		//ajoute les titres
    		$j=66;
    		foreach($titre as $val)
    		{
    			$cell=$sheet->Range(chr($j).'1'); 
    			$cell->value=$val;
    			$cell->Font->bold = true;
    			$j++;
    		}
     
    		$j=4;
     
    		$tab=array_keys($info);
     
    		$totalInter=array();
    		$totalTech=array();
    		$totalHeures=0;
     
    		//on boucle pour afficher les données de $info
    		foreach($tab as $client)
    		{
    			$total1=0;
    			$total2=0;
    			$place=$j+2;
     
    			$cell=$sheet->Range('A'.$j); 
    			$cell->value=numToClient($client);
    			$cell->Font->bold = true;
     
    			$mb=$info[$client];
    			$cleMb=array_keys($mb);
    			$j++;
     
    			foreach($cleMb as $personne)
    			{
    				foreach($mb[$personne] as $val)
    				{
    					$cell=$sheet->Range('B'.$j); 
    					$cell->value=$val["num"];
    					$cell=$sheet->Range('C'.$j); 
    					$cell->value=$personne;
    					$cell=$sheet->Range('D'.$j); 
    					$cell->value=$val["tps"];
     
    					$j++;
    					$total1+=$val["tps"];
    					$total2++;
    					$totalHeures+=$val["tps"];
    					if(!isset($totalInter[$val["num"]]))
    						$totalInter[$val["num"]]=0;
    					else
    						$totalInter[$val["num"]]++;
    					if(!isset($totalTech[$personne]))
    						$totalTech[$personne]=0;
    					else
    						$totalTech[$personne]++;
    				}
    			}
    			if($total2<=2)
    				$j=$place+4;
    			else
    				$j+=2;
     
    			//on affiche les totaux
    			$cell=$sheet->Range('A'.$place);
    			$cell->value="Nb interventions: ".$total2;
    			$cell->Font->Italic= true;
    			$place++;
    			$cell=$sheet->Range('A'.$place);
    			$cell->value="Total effectué: ".$total1." heures";
    			$cell->Font->Italic= true;
    		}
     
    		//on affiche les totaux généraux
    		$cell=$sheet->Range('A2');
    		$cell->value="Total: ";
    		$cell->Font->Italic= true;
    		$cell=$sheet->Range('B2');
    		$cell->value=count($totalInter);
    		$cell=$sheet->Range('C2');
    		$cell->value=count($totalTech);
    		$cell=$sheet->Range('D2');
    		$cell->value=$totalHeures;
     
    		//on centre et met les colonnes à la bonne dimension
    		for($j=65;$j<69;$j++)
    		{
    			$cell=$sheet->Range(chr($j).':'.chr($j));
    			$cell->EntireColumn->AutoFit();
    			$cell->HorizontalAlignment=-4108;
    		}
     
    		$book->saveas(FILENAME);
    		unset($sheet);
    		unset($book);
    		$excel->Workbooks->Close();
    		$excel->Quit();
    		unset($excel);
    	}
     
    	function recupTech()
    	//récupère la liste des techniciens se trouvant dans le planning
    	{
     
    		$req='SELECT M.nummembre as nummembre FROM membres M WHERE  M.figurepla=1 AND M.nument=2 AND M.status<>8 AND M.nummembre NOT IN (23,75,82) GROUP BY M.nummembre';
    		$result=mysql_query($req);
     
    		while($ligne=mysql_fetch_assoc($result))
    		{
    			$tab[]=$ligne["nummembre"];
    		}
    		return $tab;
    	}
     
    	function recupClientStat($deb,$fin,$client)
    	//récupère la liste des Client ayant été concerné entre $deb et $fin
    	{
    		if($client!="")
    			$req='SELECT I.code 
    			FROM detailtemps D, interventions I, clients C 
    			WHERE C.code=I.code AND D.num=I.num AND Locate("'.$client.'",C.nom) AND D.datefin<>"0000-00-00 00:00:00" AND D.datefin>="'.$deb.'" AND D.datefin<="'.$fin.'" GROUP BY I.code';
    		else
    			$req='SELECT I.code 
    			FROM detailtemps D, interventions I
    			WHERE D.num=I.num AND D.datefin<>"0000-00-00 00:00:00" AND D.datefin>="'.$deb.'" AND D.datefin<="'.$fin.'" GROUP BY I.code';
     
    		$result=mysql_query($req);
     
    		while($ligne=@mysql_fetch_assoc($result))
    		{
    			$tab[]=$ligne['code'];
    		}
    		return @$tab;
    	}
     
    	function recupClient($client)
    	//récupère tous les clients dont $client est contenu dans le nom de la bdd
    	{
     
    		$req='SELECT code , nom FROM clients WHERE Locate("'.$client.'",nom)';
    		$result=mysql_query($req);
    		while($ligne=mysql_fetch_assoc($result))
    		{
    			$listeClient[$ligne["nom"]]=$ligne["code"];
    		}
    		return $listeClient;
    	}
     
    	function recupListeInter($deb,$fin,$type,$domaine,$client)
    	//récupère les numéros d'interventions correspondant à la recherche
    	{
    		$condition='';
     
    		$tab=explode("/",$deb);
    		$deb=$tab[2].'-'.$tab[1].'-'.$tab[0];
     
    		$tab=explode("/",$fin);
    		$fin=$tab[2].'-'.$tab[1].'-'.$tab[0];
     
    		if($type!='')
    			$condition.=' AND numinter='.$type;
    		if($domaine!='')
    			$condition.=' AND numob='.$domaine;
     
    		if($condition!='')
    			$condition=substr($condition,4).' AND ';
     
    		$listeClient='';
     
    		//on fait la liste des clients pour la requête
    		if($client!='')
    		{
    			$lc=recupClient($client);
    			foreach($lc as $val)
    				$listeClient.=$val.',';	
     
    			$listeClient='code IN('.substr($listeClient,0,strlen($listeClient)-1).') AND';
    		}
     
    		$req='SELECT num FROM interventions WHERE '.$condition.' '.$listeClient.' date>="'.$deb.'" AND date<="'.$fin.'"';
    		$result=mysql_query($req);
     
    		while($ligne=mysql_fetch_assoc($result))
    		{
    			$listeInter[]=$ligne["num"];
    		}
     
    		return $listeInter;
    	}
     
    	function chercheInfo($datedebut,$datefin,$coeff,$type,$domaine,$client,$tech)
    	//recherche toutes les infos nécessaires et retourne un tableau
    	{
    		$listeInter=recupListeInter($datedebut,$datefin,$type,$domaine,$client);
     
    		$condition='';
     
    		if($tech!='')
    			$condition.=' AND D.nummembre='.$tech;
    		if($coeff!='')
    			$condition.=' AND D.numcoeff='.$coeff;
    		if($condition!='')
    			$condition=' AND '.substr($condition,4);
     
    		$resultat=array();
     
    		foreach($listeInter as $val)
    		{
    			$result=mysql_query("SELECT count(*) FROM detailtemps WHERE num=".$val);
    			$ligne=mysql_fetch_assoc($result);
    			if($ligne["count(*)"]>0)
    			{
    				$req='SELECT C.nom as nomC,I.dat,I.description, S.coeff, D.rem,D.datedeb,D.datefin,M.nom as nomM, A.inter, B.objet,D.temps
    						FROM interventions I, clients C, detailtemps D, coeffcps S,membres M,typeinter A, typeobjets B 
    						WHERE I.code=C.code AND D.num=I.num AND D.numcoeff=S.numcoeff AND M.nummembre=D.nummembre AND I.numob=B.numob AND I.numinter=A.numinter AND I.num='.$val.' '.$condition;
    				$choix=1;
    			}
    			else
    			{
    				$req='SELECT C.nom as nomC,I.dat,I.description,A.inter,B.objet 
    						FROM interventions I, clients C, typeinter A, typeobjets B 
    						WHERE I.code=C.code AND I.numob=B.numob AND I.numinter=A.numinter AND I.num='.$val.''.$condition;
    				$choix=2;
    			}
     
    			$result=mysql_query($req);
     
    			$j=1;
    			$temp2=array();
    			while($ligne=mysql_fetch_assoc($result))
    			{	
    				$temp=array();
     
    				$temp["num"]=$val;
    				$temp["nomC"]=bonFormat($ligne["nomC"]);
    				$temp["creation"]=$ligne["date"];
    				$temp["objet"]=bonFormat($ligne["description"]);
    				$temp["typeinter"]=$ligne["inter"];
    				$temp["typeobjet"]=$ligne["objet"];
     
    				if($choix==1)
    				{
    					$temp["coeff"]=$ligne["coeff"];
    					$temp["rem"]=bonFormat($ligne["description"]);
    					$temp["debut"]=$ligne["datedeb"];
    					$temp["fin"]=$ligne["datefin"];
    					$temp["nomM"]=$ligne["nomM"];
    					$temp["temps"]=$ligne["temps"];
    				}
    				else
    				{
    					$temp["nomM"]="non renseigné";
    					$temp["coeff"]="non renseigné";
    					$temp["rem"]="non renseigné";
    					$temp["debut"]="non renseigné";
    					$temp["fin"]="non renseigné";
    					$temp["coeff"]="non renseigné";
    					$temp["temps"]="non renseigné";
    				}
     
    				$temp2[$j]=$temp;
    				$j++;
    			}
     
    			if(count($temp2)!=0)
    				$resultat[$val]=$temp2;
    		}
    		return $resultat;
    	}
     
    	function mettreDansExcel($datedebut,$datefin,$coeff,$type,$domaine,$client,$tech)
    	{
    		if($type!='')
    		{
    			//on récupère le numéro du type de l'intervention
    			$req='SELECT numinter FROM typeinter WHERE inter="'.$type.'"';
    			$result=mysql_query($req);
    			$res=mysql_fetch_assoc($result);
     
    			$type=$res["numinter"];
    		}
     
    		$resultat=chercheInfo($datedebut,$datefin,$coeff,$type,$domaine,$client,$tech);
    		ecrireExcel($resultat);
     
     
    		$fichier = "C:/Program Files/EasyPHP5.3.0/www/flytech/recherche.xls";
     
    		// téléchargement du fichier
    		$fichier_nom = basename($fichier);
    		$fichier_taille = filesize($fichier);
    		header("Content-disposition: attachment; filename=".$fichier_nom);
    		header("Content-Transfer-Encoding: binary");
    		header("Content-Length: ".$fichier_taille);
    		header("Pragma: no-cache, public");
    		header("Cache-Control: public, no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    		header("Expires: 0");
    		readfile($fichier); 
     
    	}
     
    	function infoStatTechs($deb,$fin,$t)
    	//fonction qui récupère les informations nécessaires sur les techniciens entre $deb et $fin
    	{
    		$tab=explode("/",$deb);
    		$deb=$tab[2].'-'.$tab[1].'-'.$tab[0];
     
    		$tab=explode("/",$fin);
    		$fin=$tab[2].'-'.$tab[1].'-'.$tab[0];
     
    		if($t=="")
    			$tech=recupTech();
    		else
    			$tech=array(0 => $t);
     
    		//Pour chaque technicien on récupère les informations sur les interventions nécessaires
    		foreach($tech as $val)
    		{	
    			$req='SELECT D.num, SUM(D.temps) as temps, M.nom as nomM, C.nom as nomC, I.dureesite, I.dureeatelier, I.duree_facturee FROM detailtemps D, clients C, interventions I, membres M WHERE D.num=I.num AND I.code=C.code AND D.nummembre=M.nummembre AND D.nummembre='.$val.' AND D.datefin>="'.$deb.'" AND D.datefin<="'.$fin.'" GROUP BY D.num';
     
    			$result=mysql_query($req);
     
    			$temp2=array();			
    			while($ligne=mysql_fetch_array($result))
    			{
    				$temp=array();
    				$temp["num"]=$ligne["num"];
    				$temp["tps"]=$ligne["temps"];
    				$temp["nomM"]=$ligne["nomM"];
    				$temp["nomC"]=$ligne["nomC"];
    				$temp["site"]=$ligne["dureesite"];
    				$temp["atelier"]=$ligne["dureeatelier"];
    				$temp["duree_facturee"]=$ligne["duree_facturee"];
    				$temp2[]=$temp;
    			}
    			$inter[$val]=$temp2;	
    		}
     
    		//Pour chaque technicien on récupère les informations sur le reste
    		foreach($tech as $val)
    		{	
    			//tout sauf les vacances
    			$req='SELECT SUM(DATE_FORMAT(P.datefin,"%H:%i:%s")-DATE_FORMAT(P.datedebut,"%H:%i:%s")) as temps
    					FROM planning P, membres M 
    					WHERE  P.nummembre=M.nummembre AND P.num=0 AND P.nummembre='.$val.' AND datefin>="'.$deb.'" AND datefin<="'.$fin.'" AND numtype<>1
    					';
     
    			$result=mysql_query($req);
    			$ligne=mysql_fetch_array($result);
    			if(!isset($ligne["temps"]))
    				$autres[$val]["autre"]=0;
    			else
    				$autres[$val]["autre"]=$ligne["temps"];	
     
     
    			//vacances
    			$req='SELECT SUM(DATE_FORMAT(P.datefin,"%H:%i:%s")-DATE_FORMAT(P.datedebut,"%H:%i:%s")) as temps
    					FROM planning P, membres M 
    					WHERE  P.nummembre=M.nummembre AND P.num=0 AND P.nummembre='.$val.' AND datefin>="'.$deb.'" AND datefin<="'.$fin.'" AND numtype=1
    					';
    			$result=mysql_query($req);
    			$ligne=mysql_fetch_array($result);
    			if(!isset($ligne["temps"]))
    				$autres[$val]["vacs"]=0;
    			else
    				$autres[$val]["vacs"]=$ligne["temps"];
     
    		}
     
    		$stat["inter"]=$inter;
    		$stat["autre"]=$autres;
     
    		return $stat;
    	}
     
    	function infoStatClients($deb,$fin,$client)
    	//fonction qui récupère les informations nécessaire sur les clients entre $deb et $fin
    	{
     
    		$tab=explode("/",$deb);
    		$deb=$tab[2].'-'.$tab[1].'-'.$tab[0];
     
    		$tab=explode("/",$fin);
    		$fin=$tab[2].'-'.$tab[1].'-'.$tab[0];
     
    		$client=recupClientStat($deb,$fin,$client);
    		$statClient=array();
     
    		foreach($client as $val)
    		{
    			$req='SELECT D.num, M.nom as nomM, C.nom as nomC, SUM(D.temps) as temps	FROM detailtemps D, clients C, interventions I, membres M WHERE D.num=I.num AND I.code=C.code AND M.nummembre=D.nummembre AND I.code='.$val.' AND D.datefin>="'.$deb.'" AND D.datefin<="'.$fin.'" GROUP BY D.num,M.nom';
     
    			$result=mysql_query($req);
    			$tempMembre=array();
     
    			while($ligne=mysql_fetch_array($result))
    			{
    				$temp=array();
     
    				$temp1["num"]=$ligne["num"];
    				$temp1["nomC"]=$ligne["nomC"];
    				$temp1["tps"]=$ligne["temps"];
     
    				$tempMembre[$ligne["nomM"]][]=$temp1;
    			}
     
    			$statClient[$val]=$tempMembre;
    		}
     
    		return $statClient;
    	}
     
    	function statTechs($deb,$fin,$tech)
    	//fonction permettant le téléchargement du fichier excel des statistiques sur les techiciens
    	{
    		$info=infoStatTechs($deb,$fin,$tech);
    		ecrireExcelStatTech($info,$tech);
     
    		$fichier = "C:/Program Files/EasyPHP5.3.0/www/flytech/Statistiques_Techniciens.xls";
     
    		// téléchargement du fichier
    		$fichier_nom = basename($fichier);
    		$fichier_taille = filesize($fichier);
    		header("Content-disposition: attachment; filename=".$fichier_nom);
    		header("Content-Transfer-Encoding: binary");
    		header("Content-Length: ".$fichier_taille);
    		header("Pragma: no-cache, public");
    		header("Cache-Control: public, no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    		header("Expires: 0");
    		readfile($fichier);		
    	}
     
    	function statClients($deb,$fin,$client)
    	//fonction permettant le téléchargement du fichier excel des statistiques sur les Clients
    	{
    		$info=infoStatClients($deb,$fin,$client);
    		ecrireExcelStatClient($info);
     
    		$fichier = "C:/Program Files/EasyPHP5.3.0/www/flytech/Statistiques_Clients.xls";
     
     
    		// téléchargement du fichier
    		$fichier_nom = basename($fichier);
    		$fichier_taille = filesize($fichier);
    		header("Content-disposition: attachment; filename=".$fichier_nom);
    		header("Content-Transfer-Encoding: binary");
    		header("Content-Length: ".$fichier_taille);
    		header("Pragma: no-cache, public");
    		header("Cache-Control: public, no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    		header("Expires: 0");
    		readfile($fichier);	
     
    	}
    ?>
    Et la base de données en pièce jointe...

    Avant que je passe en PHP 5 tout allait bien...
    J'ai déjà regardé ce que je pouvais faire mais je désespère...
    Merci d'avance
    Fichiers attachés Fichiers attachés

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Et quel est ton problème precisemment ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 20
    Par défaut
    Le fichier excel s'ouvre mais il n'y a que des caractères bizzares et des erreurs PHP comme Invalid argument supplied for foreach() ou expects parameter 1 to be resource...

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Tu as peut être des situations anormales que tu ne traites et qui sont maintenant signalés en PHP5.

    Il faut que tu debug.
    Par exemple pour l'erreur sur foreach() contrôle avec var_dump() ce que contient la variable que tu utilises et ensuite remonte dans ton code pour comprendre pourquoi elle contient ça plutôt qu'un tableau etc.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

Discussions similaires

  1. Problème exportation heure depuis Excel vers Access
    Par AstroZelda dans le forum Général VBA
    Réponses: 0
    Dernier message: 10/06/2015, 15h13
  2. [IIS 7.5] Problème Export Excel PHP avec IIS 7.5
    Par sunyeeon dans le forum IIS
    Réponses: 0
    Dernier message: 04/11/2014, 17h26
  3. [C#2.0]Problème export Excel
    Par SLE dans le forum Windows Forms
    Réponses: 2
    Dernier message: 07/07/2006, 10h17
  4. Problème export excel
    Par eddyG dans le forum Access
    Réponses: 4
    Dernier message: 04/07/2006, 18h42
  5. [Tableaux] Problème export excel
    Par la fouine dans le forum Langage
    Réponses: 1
    Dernier message: 02/06/2006, 07h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo