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 :

Faire une exportation de ma base de données à partir d'une requête


Sujet :

Langage PHP

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut Faire une exportation de ma base de données à partir d'une requête
    Bonjour à tous.

    J'ai une page php exécutant une requete et affichant le résultat dans un tableau, etc.

    Maintenant, je dois exporter le résultat de ma requête de mysql sous forme de classeur excel, et la proposer en chargement sur ma page. Comment faire ?

  2. #2
    Modérateur
    Avatar de Vil'Coyote
    Homme Profil pro
    Développeur adélia & Web
    Inscrit en
    Février 2008
    Messages
    4 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur adélia & Web
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2008
    Messages : 4 583
    Points : 7 503
    Points
    7 503
    Par défaut
    phpexcel

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    Euh merci mais c'est un peu complexe quand même
    Et puis ça me dis pas vraiment comment faire pour créer un classeur excel via php avec le résultat de ma requête.
    Si quelqu'un veut bien me guider pour ça, ça serait vraiment trop sympa parce que là je suis totalement largué pour ce truc.

  4. #4
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Regardes sur le forum par exemple ici

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    J'ai beau regarder, j'ai vraiment du mal, je doit adapter ce truc à un code de près de 500 lignes que je galère à améliorer depuis 1 semaine.

    Par exemple, un petit bout de mon code :

    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
    $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);
     
     
    if (mysql_num_rows($resultat) == 0) 
    {
    	echo "<table border=1 width=550 height=80 align=center bgcolor=#BCBCBC>";
    	echo "<tr height 20>";
    	echo "<td align=center>"."<b>"."Aucun enregistrement ne correspond"."</b>"."</td>";
    	echo "</tr>";
    	echo "</table>";
    } 
    else
    {
     
    	while ($ligneresultat = mysql_fetch_array($resultat))
    	{
     
    		if($ligneresultatbis=mysql_fetch_array($resultat))
    		{
    			echo "<table border=1 width=600 height=80 align=left bgcolor=#BCBCBC>";
    			echo "<tr height=20>";
    			echo "<td>"."Nom"."</td>";
    			echo "<td>".$ligneresultat['nom']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Prénom"."</td>";
    			echo "<td>".$ligneresultat['prenom']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Téléphone"."</td>";
    			echo "<td>".$ligneresultat['tel']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Fax"."</td>";
    			echo "<td>".$ligneresultat['fax']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Mobile"."</td>";
    			echo "<td>".$ligneresultat['mobile']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."E-mail"."</td>";
    			echo "<td>".$ligneresultat['mail']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Lieu de travail"."</td>";
    			echo "<td>".$ligneresultat['lieudetravail']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Adresse physique"."</td>";
    			echo "<td>".$ligneresultat['adresse']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Fonction"."</td>";
    			echo "<td>".$ligneresultat['fonction']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Code machine"."</td>";
    			echo "<td>".$ligneresultat['codemachine']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Code postal"."</td>";
    			echo "<td>".$ligneresultat['codepostal']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Ville"."</td>";
    			echo "<td>".$ligneresultat['ville']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Site"."</td>";
    			echo "<td>".$ligneresultat['site']."</td>";
    			echo "</tr>";
    			echo "</table>";
     
    			echo "<table border=1 width=600 height=80 align=right bgcolor=#BCBCBC>";
    			echo "<tr height=20>";
    			echo "<td>"."Nom"."</td>";
    			echo "<td>".$ligneresultatbis['nom']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Prénom"."</td>";
    			echo "<td>".$ligneresultatbis['prenom']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Téléphone"."</td>";
    			echo "<td>".$ligneresultatbis['tel']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Fax"."</td>";
    			echo "<td>".$ligneresultatbis['fax']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Mobile"."</td>";
    			echo "<td>".$ligneresultatbis['mobile']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."E-mail"."</td>";
    			echo "<td>".$ligneresultatbis['mail']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Lieu de travail"."</td>";
    			echo "<td>".$ligneresultatbis['lieudetravail']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Adresse physique"."</td>";
    			echo "<td>".$ligneresultatbis['adresse']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Fonction"."</td>";
    			echo "<td>".$ligneresultatbis['fonction']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Code machine"."</td>";
    			echo "<td>".$ligneresultatbis['codemachine']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Code postal"."</td>";
    			echo "<td>".$ligneresultatbis['codepostal']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Ville"."</td>";
    			echo "<td>".$ligneresultatbis['ville']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Site"."</td>";
    			echo "<td>".$ligneresultatbis['site']."</td>";
    			echo "</tr>";
    			echo "</table>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>";
    		}
    		else
    		{
    			echo "<table border=1 width=600 height=80 align=center bgcolor=#BCBCBC>";
    			echo "<tr height=20>";
    			echo "<td>"."Nom"."</td>";
    			echo "<td>".$ligneresultat['nom']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Prénom"."</td>";
    			echo "<td>".$ligneresultat['prenom']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Téléphone"."</td>";
    			echo "<td>".$ligneresultat['tel']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Fax"."</td>";
    			echo "<td>".$ligneresultat['fax']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Mobile"."</td>";
    			echo "<td>".$ligneresultat['mobile']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."E-mail"."</td>";
    			echo "<td>".$ligneresultat['mail']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Lieu de travail"."</td>";
    			echo "<td>".$ligneresultat['lieudetravail']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Adresse physique"."</td>";
    			echo "<td>".$ligneresultat['adresse']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Fonction"."</td>";
    			echo "<td>".$ligneresultat['fonction']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Code machine"."</td>";
    			echo "<td>".$ligneresultat['codemachine']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Code postal"."</td>";
    			echo "<td>".$ligneresultat['codepostal']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Ville"."</td>";
    			echo "<td>".$ligneresultat['ville']."</td>";
    			echo "</tr>";
    			echo "<tr height=20>";
    			echo "<td>"."Site"."</td>";
    			echo "<td>".$ligneresultat['site']."</td>";
    			echo "</tr>";
    			echo "</table>";
     
    		}
     
      	}
     
     
    }
    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>";
    Ca me fait un super beau tableau de la forme :
    Code employé employe1
    Nom nom1
    Prénom prenom1
    etc etc1
    Mais bien aligné en colonne bien sur

    Suite à ce tableau, je doit faire un bouton (pas de problème) qui quand je clique dessus me met tout les résultat de ma requête dans un tableau excel enregistré en xls (là problème) sous la forme :

    Codeemploye Nom Prenom etc
    employe1 nom1 prenom1 etc1
    employe2 nom2 prenom2 etc2
    Mais ce truc pour Excel c'est du chinois et j'ai besoin d'aide, qu'on m'explique carrement quoi

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    Deja, si j'ai bien compris, il faut que je charge une bibliothèque ?

  7. #7
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Et mais je me rappele, c moi qui te la fait ton algorithme

    Cette algorithme était pour tout mettre sur deux colonnes et la tu en as pas besoin DONC après l'affichage tu recommence une boucle toute simple comme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    	while ($ligneresultat = mysql_fetch_array($resultat))
    	{
     
    	      // Traitement $ligneresultat['nom]'; vers excell
    	      // Traitement $ligneresultat['prenom']; vers excell
                      ...
                  }
    En utilisant le début de code:
    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
     
    include 'PHPExcel.php';
    include 'PHPExcel/Writer/Excel2007.php';
     
    $workbook = new PHPExcel;
     
    $sheet = $workbook->getActiveSheet();
     
    //Dans ta boucle
    $sheet->setCellValue('A1','Une des valeurs');
     
     
    // Fin boucle
    $writer = new PHPExcel_Writer_Excel2007($workbook);
     
    // Affichage Excell verx navigateur comme demandé 
    header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
     header('Content-Disposition:inline;filename=Fichier.xlsx ');
     $writer->save('php://output');

  8. #8
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Oui je sais, j'ai fais ça rapide mais tu devrais déjà obtenir quelque chose

  9. #9
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    Oui c'était moi
    Enfin tu remarquera que je l'ai quand même pas mal trifouillé

    Et si tout ce que j'ai fait j'en ai besoin, je devais permettre un affichage propre et rapide des données demandées.

    Mais maintenant je doit en faire un classeur excel que j'utiliserai plus tard en le proposant en téléchargement sur une page php pour que d'autres services de l'entreprise où je suis en stage puisse s'en servir pour se mettre à jour

  10. #10
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    Donc les includes, je doit les télécharger ?

  11. #11
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Oui,

    Si tu suis le début du lien que je t'ai donné, c bien expliqué

    Pour le reste, tu mets ta boucle de lecture de ta requête entre les remarques comme indiqué plus haut, ensuite avec une petite lecture de comment créer les cellules, tu devrait avoir un résultat déjà potable.

    Désolé, je suis pris par le temps (mais demain j'aurais plus le loisir ...) Essayes déjà de nous créer un petit quelquechose

  12. #12
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    T'excuse pas, tu es ma plus grande ressource de savoir en matière de php et ma plus grande aide alors t'excuse pas
    Oui je vais essayer ça alors
    Merci beaucoup de prendre un peu de temps pour aider le pauvre type un peu paummé que je suis, au cerveau cramé à force de se perdre dans un super code php

  13. #13
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    Ca y est j'ai télécharger la librairie, j'ai fait ce que m'a dis le lien que tu m'a envoyé plus tôt.
    Ca établi bien un lien avec excel, il ouvre bien un classeur, mais incompatible avec les données que j'ai. En faite je n'ai plu que des tableaux d'erreur. J'ai peut être mal extrait quelque chose ou je sais pas.

  14. #14
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Donnes nous ton code actuel pour voir ?

  15. #15
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    Voila la partie concerné de mon code

    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
    <html>
    <?php
     
    include 'PHPExcel.php';
    include 'PHPExcel/Writer/Excel2007.php';
     
    $workbook = new PHPExcel;
    $sheet = $workbook->getActiveSheet();
     
     
    $connection=mysql_connect("localhost", "root", "") or die ("message d'erreur".mysql_error($connection));
    $base=("test");
     
    if(!$connection)
    	die("connection impossible");
     
    	$mabasededonnee=$base;
    	mysql_select_db($mabasededonnee) or die ("pas de connection");
    	$formchoix=$_POST["formchoix"];
    	$formselection=$_POST["formselection"];
     
    	if($formchoix=="1")
    	{
    		echo "<table border=1 width=550 height=80 align=center bgcolor=#BCBCBC>";
    		echo "<tr height 20>";
    		echo "<td align=center>"."<b>"."Veuillez faire un choix"."</b>"."</td>";
    		echo "</tr>";
    		echo "<tr height 20>";
    		echo "<td align=center>"."<a href='javascript:history.back()'>Retour</a>"."</td>";
    		echo "</tr>";
    		echo "</table>";
     
    	}
    	else
    	{
    		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);
     
     
     
    			if (mysql_num_rows($resultat) == 0) 
    			{
    					echo "<table border=1 width=550 height=80 align=center bgcolor=#BCBCBC>";
    					echo "<tr height 20>";
    					echo "<td align=center>"."<b>"."Aucun enregistrement ne correspond"."</b>"."</td>";
    					echo "</tr>";
    					echo "</table>";
    			} 
    			else
    			{
     
     
     
    				while ($ligneresultat = mysql_fetch_array($resultat))
    				{
     
    					if($ligneresultatbis=mysql_fetch_array($resultat))
    					{
     
    					echo "<table border=1 width=600 height=80 align=left bgcolor=#BCBCBC>";
    					echo "<tr height=20>";
    					echo "<td>"."Nom"."</td>";
    					echo "<td>".$ligneresultat['nom']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Prénom"."</td>";
    					echo "<td>".$ligneresultat['prenom']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Téléphone"."</td>";
    					echo "<td>".$ligneresultat['tel']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Fax"."</td>";
    					echo "<td>".$ligneresultat['fax']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Mobile"."</td>";
    					echo "<td>".$ligneresultat['mobile']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."E-mail"."</td>";
    					echo "<td>".$ligneresultat['mail']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Lieu de travail"."</td>";
    					echo "<td>".$ligneresultat['lieudetravail']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Adresse physique"."</td>";
    					echo "<td>".$ligneresultat['adresse']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Fonction"."</td>";
    					echo "<td>".$ligneresultat['fonction']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Code machine"."</td>";
    					echo "<td>".$ligneresultat['codemachine']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Code postal"."</td>";
    					echo "<td>".$ligneresultat['codepostal']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Ville"."</td>";
    					echo "<td>".$ligneresultat['ville']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Site"."</td>";
    					echo "<td>".$ligneresultat['site']."</td>";
    					echo "</tr>";
    					echo "</table>";
     
     
    					echo "<table border=1 width=600 height=80 align=right bgcolor=#BCBCBC>";
    					echo "<tr height=20>";
    					echo "<td>"."Nom"."</td>";
    					echo "<td>".$ligneresultatbis['nom']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Prénom"."</td>";
    					echo "<td>".$ligneresultatbis['prenom']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Téléphone"."</td>";
    					echo "<td>".$ligneresultatbis['tel']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Fax"."</td>";
    					echo "<td>".$ligneresultatbis['fax']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Mobile"."</td>";
    					echo "<td>".$ligneresultatbis['mobile']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."E-mail"."</td>";
    					echo "<td>".$ligneresultatbis['mail']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Lieu de travail"."</td>";
    					echo "<td>".$ligneresultatbis['lieudetravail']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Adresse physique"."</td>";
    					echo "<td>".$ligneresultatbis['adresse']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Fonction"."</td>";
    					echo "<td>".$ligneresultatbis['fonction']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Code machine"."</td>";
    					echo "<td>".$ligneresultatbis['codemachine']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Code postal"."</td>";
    					echo "<td>".$ligneresultatbis['codepostal']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Ville"."</td>";
    					echo "<td>".$ligneresultatbis['ville']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Site"."</td>";
    					echo "<td>".$ligneresultatbis['site']."</td>";
    					echo "</tr>";
    					echo "</table>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>"."<br>";
     
    					}
    					else
    					{
    					echo "<table border=1 width=600 height=80 align=center bgcolor=#BCBCBC>";
    					echo "<tr height=20>";
    					echo "<td>"."Nom"."</td>";
    					echo "<td>".$ligneresultat['nom']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Prénom"."</td>";
    					echo "<td>".$ligneresultat['prenom']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Téléphone"."</td>";
    					echo "<td>".$ligneresultat['tel']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Fax"."</td>";
    					echo "<td>".$ligneresultat['fax']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Mobile"."</td>";
    					echo "<td>".$ligneresultat['mobile']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."E-mail"."</td>";
    					echo "<td>".$ligneresultat['mail']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Lieu de travail"."</td>";
    					echo "<td>".$ligneresultat['lieudetravail']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Adresse physique"."</td>";
    					echo "<td>".$ligneresultat['adresse']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Fonction"."</td>";
    					echo "<td>".$ligneresultat['fonction']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Code machine"."</td>";
    					echo "<td>".$ligneresultat['codemachine']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Code postal"."</td>";
    					echo "<td>".$ligneresultat['codepostal']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Ville"."</td>";
    					echo "<td>".$ligneresultat['ville']."</td>";
    					echo "</tr>";
    					echo "<tr height=20>";
    					echo "<td>"."Site"."</td>";
    					echo "<td>".$ligneresultat['site']."</td>";
    					echo "</tr>";
    					echo "</table>";
     
    					$sheet->setCellValue('A1','Code barre');
     
    					}
     
    					$sheet->setCellValue('A1','Code barre');
     
      				}
     
    				$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('$ligneresultat');
     
    			}
     
    			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>";
     
    		}

  16. #16
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Ouuuutchhhh

    Je t'avais dis de refaire une boucle

    Je verais un code comme celui-ci (j'ai allégé des endroits mais je pense qu'il est compréhenssible)
    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
     
    <?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');
     
    		}

  17. #17
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    Ok merci Fench je vais essayer ça de ce pas

  18. #18
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    Voilà j'ai essayé, mais ça me met tioujours le message :

    Impossible d'ouvrir le fichier "exportationphp.xslx" car son format ou son extension n'est pas valide. Vérifiez que le fichier n'est pas endommagé et que son extension correspond bien au format du fichier.

  19. #19
    Nouveau membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2012
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2012
    Messages : 81
    Points : 36
    Points
    36
    Par défaut
    Peut etre que j'ai mal sortie les bidules et les machins de la librairie PHPExcel ?

    De plus, en admettant que ça marche, de A1 à A13 j'ai mis Nom, Prénom, Téléphone .... et de B1 à B13 j'ai mis les ligneresultat.
    Mais comme je peut avoir plusieurs ligne avec ma requete, je fait comment aussi pour mettre la suite en C1 à C13, D1 à D13, etc ?

  20. #20
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Crée un fichier de ce nom avec les entêtes A1{nom} B1{prenom} etc ...

    Ensuite dans ta boucle, utilises $sheet->setCellValueByColumnAndRow(col, Row, value);
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    $rowIndex=1;
                            while ($ligneresultat = mysql_fetch_array($resultat))
                            {
                                // Pour chaque champ et de A1 à A13
                                $sheet->setCellValueByColumnAndRow(1, $rowIndex, $ligneresultat['nom']);
                               $sheet->setCellValueByColumnAndRow(2, $rowIndex, $ligneresultat['prenom']);                           
                                // Etc
                                 $rowIndex++;
                            }

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Mettre en place une base de données à partir d'une sauvegarde
    Par snopims dans le forum MS SQL Server
    Réponses: 6
    Dernier message: 16/09/2008, 10h13
  2. Réponses: 8
    Dernier message: 14/02/2008, 18h04
  3. [C#2.0] Mettre à jour la base de données à partir d'une DataTable
    Par Rodie dans le forum Accès aux données
    Réponses: 6
    Dernier message: 16/05/2007, 14h24
  4. Réponses: 1
    Dernier message: 02/02/2007, 10h29
  5. [MySQL] Enregistrer dans une base de données à partir d'une liste déroulante
    Par snakejl dans le forum PHP & Base de données
    Réponses: 12
    Dernier message: 17/05/2006, 16h32

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