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

Bibliothèques et frameworks PHP Discussion :

[PHPExcel] Problème de style


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2014
    Messages : 4
    Points : 1
    Points
    1
    Par défaut [PHPExcel] Problème de style
    Bonjours, j'ai un projet en cours ou je dois récupérer un Excel à partir d'un html qui me montre une liste. J'utilise code igniter au passage.

    Cependant j'arrive bien à télécharger mon fichier Excel mais impossible d'avoir une mise en forme correct... (autosize des largeurs de colones ou récupération du css de mon affichage web).

    Mon export_manager

    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
    public function export_excel()
        {
     
             if($this->input->post("html")){
                $filename = "export.xlsx";   
                $path_name = TMPPATH.'export.xlsx';
                 $html_content = iconv("UTF-8", "CP1252", $this->input->post("html"));
                $html_content = str_replace('$and$', '&', $html_content);
     
                if(file_exists($path_name)){
                    unlink($path_name);
                }
     
                //$this->load->library('zend');
                $this->load->library('phpexcel');
     
              //    PHPExcel_Autoloader::Load("PHPExcel_Reader_HTML");
              //    PHPExcel_Autoloader::Load("PHPExcel_Writer_Excel2007");
                $tmpfile=time().'.html';
                file_put_contents($tmpfile, $html_content);
     
                $reader = new PHPExcel_Reader_HTML;
                $content = $reader->load($tmpfile);
     
                $objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
                $objWriter->save($path_name);
     
                /* Ne marche pas
                 
                $objet = PHPExcel_IOFactory::createReader('Excel2007');
                $objet->setReadDataOnly(true);
                $excel = $objet->load('tmp/export.xlsx');
                $sheet = $excel->getSheet(0);
     
                for($col = 'A'; $col !== 'G'; $col++)
                {
                 $sheet->getActiveSheet()
                 ->getColumnDimension($col)
                 ->setAutoSize(true);
                }
     
                $writer = PHPExcel_IOFactory::createWriter($excel);
                $writer->save('tmp/Export.xlsx'); <br>
                     
            */ 
     
                unlink($tmpfile);  
                echo json_encode(array("filename" => $path_name));
             }    
        }
     
        public function download_excel()
        {
     
                $this->load->helper('download');
                $filename = "export.xlsx";
                $path_name = TMPPATH.$filename;
                $data =  file_get_contents($path_name);
                force_download($filename,$data);
                return true;
     
        }
    Mon script admin:

    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
     $( "#export_excel" ).click(function() {
            var html_content = $("#export_excel_content").html();
     
     
            alert(html_content);
            /*
            var options = {
                "url": "export_manager/export_xlsx",
                "data": "data=" + html_content,
                "type": "post",
            }
           $.ajax(options);
            */
     
            $.blockUI({ message: "<h3 class='h3-w95'>Fichier en cours de création...</h3>" ,});
            var url = "export_manager/export_excel";
            html_content= html_content.replace("&","$and$");
     
            $.ajax({
                type: "POST",
                url: url,
                data:  "html="+html_content,
     
            })
            .done(function( json ){
                if(json["filename"] != "null"){
                    window.location.href = "export_manager/download_excel";
                }
     
                $.unblockUI();
            });
     
     
     
        });
     
     
     
    });
    Je cherche depuis une semaine et soit en suivant le tuto j'applique le style mais sans les données. Soit l'inverse...

  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
    Points : 44 155
    Points
    44 155
    Par défaut
    Que je comprenne bien : tu as un tableau HTML et tu veux le convertir en tableau Excel qui reprenne le style CSS du tableau HTML ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2014
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    Effectivement. Actuellement le fichier que je génère ne possède pas l'autosize(true) ou encore ne convertit pas les champs en texte donc effacement des 0, pas de couleurs. Merci pour l'aide j'avoue séché depuis un moment.
    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
    <div id="export_pdf_content" class="table-responsive">
    <input type="hidden" id="titre_pdf" value="Liste des prospect / clients" />
    <table id="export_excel_content" class="table table-hover table-bordered table-condensed ">
    	    <thead>
    	    	<tr>
    	    		<th><?php echo $this->translate('Nom'); ?></th>
    	    		<th><?php echo $this->translate('Ville'); ?></th>
    	    		<th><?php echo $this->translate('Tel. domicile'); ?></th>
    	    		<th><?php echo $this->translate('Tel. portable'); ?></th>	    		
    	    		<th><?php echo $this->translate('Tel. professionnel'); ?></th>	    		
    	    		<th><?php echo $this->translate('Email'); ?></th>	
    	    		<th></th>    		
    	    	</tr>
    	    </thead>
    	   	<tbody>
    		<?php 		
    		foreach ($object_list as $prospect_client) :				
    			?>	
    				<tr <?php echo $statuts_client[$prospect_client['id_statut_client']]['couleur'] ? 'style="background-color:#'.$statuts_client[$prospect_client['id_statut_client']]['couleur'].'"' : ''; ?>>
    					<td align="center"><?php 				
    						$civilite = Civilite::get_name_from_id($prospect_client['id_civilite']);
    						echo $prospect_client['nom'].' '.$prospect_client['prenom'].' ('.$civilite.')';
    					?></td>				
    					<td align="center"><?php echo $prospect_client['ville'];?></td>				
    					<?php
    						//récupère le premier contact affecté à un client pour afficher ses coordonnées
    						$first_contact = Contact::get_first_contact_by_id_client($prospect_client['id_prospect_client']);						
    					?>
    					<td align="center"><?php echo ($first_contact) ? $first_contact['telephone_domicile'] : '';?></td>				
    					<td align="center"><?php echo  ($first_contact) ? $first_contact['telephone_mobile'] : '';?></td>				
    					<td align="center"><?php echo  ($first_contact) ? $first_contact['telephone_professionnel'] : '';?></td>				
    					<td align="center"><?php echo ($first_contact) ? $first_contact['email'] : '';?></td>
    					<td align="center"><a class="action gray" title="<?php echo $this->translate('Informations');?>" 
    						href="<?php echo base_url('admin/prospect_client/view/'.$prospect_client['id_prospect_client']); ?>">
    						<span class="glyphicon glyphicon-info-sign"></span></a></td>			
    				</tr>
    		<?php endforeach;?>
    		</tbody>
    	</table>
    </div>
     
    <div>
            <a id="btnExport" href="#" download=""></a>
    </div>
    Ce qui donne en html:
    Nom : Capture.PNG
Affichages : 286
Taille : 30,4 Ko

    Et en Excel:
    Nom : test.PNG
Affichages : 274
Taille : 15,0 Ko

  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
    Points : 44 155
    Points
    44 155
    Par défaut
    Le plus fiable je pense est de definir tes styles Excel toi même.
    Je pense pas si PHPExcel sait traiter ça.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2014
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    yep seulement je n'y arrive pas non plus ^^.
    Remarque j'ai reussi l'import au moins...
    Si tu as une idée ou chercher. (mots clefs).
    Sachant que je n'ai pas le droit d'utiliser un fichier excel existant comme base pour mes documents ^^.
    Le plus fun est la

  6. #6
    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
    Points : 44 155
    Points
    44 155
    Par défaut
    Je voulais dire "Il vaut mieux que tu le spécifies manuellement dans la création de ton fichier par PHPExcel car je ne pense pas qu'il sache lire les styles HTML"
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  7. #7
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2014
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    Aurais-tu un bout de code à me donner (par exemple l'implémentation d'un autosize dans mon code ?)...
    Car je galère vraiment pas mal (et comme je suis en stage ^^ je cherche désespérément)

Discussions similaires

  1. Problème de style
    Par kjmfr dans le forum Mise en page CSS
    Réponses: 4
    Dernier message: 07/01/2007, 12h56
  2. Problème de style
    Par krokmitaine dans le forum Delphi
    Réponses: 7
    Dernier message: 13/09/2006, 12h01
  3. Problème de style avec firefox
    Par 12_darte_12 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 21/03/2006, 16h17
  4. [VB.NET] Problème tabpage + Style XP
    Par rikidi dans le forum Windows Forms
    Réponses: 2
    Dernier message: 03/08/2005, 16h01

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