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 :

[phpToPDF][Tableau] Aller à la ligne dans une cellule


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2009
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 4
    Points : 10
    Points
    10
    Par défaut [phpToPDF][Tableau] Aller à la ligne dans une cellule
    Bonjour
    Je suis débutant avec FPDF et j'ai besoin d'aide car j'ai une base de donnée contenant des informations sur des documents et je voudrais extraire certaines informations de celle ci dans un tableau récapitulatif en pdf.
    Mon problème est que certain de mes champs sont trop remplit par rapport a la taille de mes cellule donc je voudrais savoir comment faire qu'au bout de X caractère dans une cellule on retourne a la ligne dans cet même cellule.

    Voici mon code pour le 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
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
     
    <?php
    require('fpdf.php');
    require('sav.php');
    class PDF extends FPDF
    {
    //Chargement des données
    function LoadData($file)
    {
        //Lecture des lignes du fichier
        $lines=file($file);
        $data=array();
        foreach($lines as $line)
            $data[]=explode(';',chop($line));
        return $data;
    }
     
    //Tableau amélioré
    function ImprovedTable($header,$data)
    {
        //Largeurs des colonnes
        $w=array(15,20,20,6,15,50,20,4,4,4,4,4,4,4,4,4);
        //En-tête
        for($i=0;$i<count($header);$i++)
            $this->Cell($w[$i],7,$header[$i],1,0,'C');
        $this->Ln();
        //Données
        foreach($data as $row)
        {
            $this->Cell($w[0],6,$row[0],'LR');
            $this->Cell($w[1],6,$row[1],'LR');
            $this->Cell($w[2],6,$row[2],'LR');
            $this->Cell($w[3],6,$row[3],'LR');
    	$this->Cell($w[4],6,$row[4],'LR');
            $this->Cell($w[5],6,$row[5],'LR');
    	$this->Cell($w[6],6,$row[6],'LR');
            $this->Cell($w[7],6,$row[7],'LR');
    	$this->Cell($w[8],6,$row[8],'LR');
            $this->Cell($w[9],6,$row[9],'LR');
    	$this->Cell($w[10],6,$row[10],'LR');
            $this->Cell($w[11],6,$row[11],'LR');
    	$this->Cell($w[12],6,$row[12],'LR');
            $this->Cell($w[13],6,$row[13],'LR');
    	$this->Cell($w[14],6,$row[14],'LR');
            $this->Cell($w[15],6,$row[15],'LR');
            $this->Ln();
        }
        //Trait de terminaison
        $this->Cell(array_sum($w),0,'','T');
    }
     
    }
     
    $pdf=new PDF();
    //Titres des colonnes
    $header=array("lieu","Type de procedure","Domaine","indice","Date d application","Intitulé du document","Ident","RQ","MS","RS","UO","S","C","F","M","L");
    //Chargement des données
    $data=$pdf->LoadData('test.csv');
    $pdf->SetFont('Arial','',5);
    $pdf->AddPage();
    $pdf->ImprovedTable($header,$data);
     
    $pdf->Output();
    ?>

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2009
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 4
    Points : 10
    Points
    10
    Par défaut
    J'ai trouvé voici la reponse si sa peu aider quelqu'un
    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
    <?php
    session_start();
    require('fpdf.php');
     
    class PDF extends FPDF
    {
    //Chargement des données
    function LoadData($file)
    {
        //Lecture des lignes du fichier
        $lines=file($file);
        $data=array();
        foreach($lines as $line)
            $data[]=explode(';',chop($line));
        return $data;
    }
    //Tableau amélioré
    function ImprovedTable($header,$data)
    {
        //Largeurs des colonnes
        $w=array(15,20,20,6,15,50,20,4,4,4,4,4,4,4,4,4);
        //En-tête
        for($i=0;$i<count($header);$i++)
            $this->Cell($w[$i],7,$header[$i],1,0,'C');
        $this->Ln();
        //Données
        foreach($data as $row)
        {
    		$this->Cell($w[0],6,$row[0],'LR');
            $this->Cell($w[1],6,$row[1],'LR');
            $this->Cell($w[2],6,$row[2],'LR');
    		$this->Cell($w[3],6,$row[3],'LR');
    		$this->Cell($w[4],6,$row[4],'LR');
    		$this->Cell($w[5],6,$row[5],'LR');
    		$this->Cell($w[6],6,$row[6],'LR');
    		$this->Cell($w[7],6,$row[7],'LR');
    		$this->Cell($w[8],6,$row[8],'LR');
    		$this->Cell($w[9],6,$row[9],'LR');
    		$this->Cell($w[10],6,$row[10],'LR');
    		$this->Cell($w[11],6,$row[11],'LR');
    		$this->Cell($w[12],6,$row[12],'LR');
    		$this->Cell($w[13],6,$row[13],'LR');
    		$this->Cell($w[14],6,$row[14],'LR');
    		$this->Cell($w[15],6,$row[15],'LR');
            $this->Ln();
        }
        //Trait de terminaison
        $this->Cell(array_sum($w),0,'','T');
    }
     
    function WordWrap(&$text, $maxwidth)
    {
        $text = trim($text);
        if ($text==='')
            return 0;
        $space = $this->GetStringWidth(' ');
        $lines = explode("\n", $text);
        $text = '';
        $count = 0;
     
        foreach ($lines as $line)
        {
            $words = preg_split('/ +/', $line);
            $width = 0;
     
            foreach ($words as $word)
            {
                $wordwidth = $this->GetStringWidth($word);
                if ($wordwidth > $maxwidth)
                {
                    // Word is too long, we cut it
                    for($i=0; $i<strlen($word); $i++)
                    {
                        $wordwidth = $this->GetStringWidth(substr($word, $i, 1));
                        if($width + $wordwidth <= $maxwidth)
                        {
                            $width += $wordwidth;
                            $text .= substr($word, $i, 1);
                        }
                        else
                        {
                            $width = $wordwidth;
                            $text = rtrim($text)."\n".substr($word, $i, 1);
                            $count++;
                        }
                    }
                }
                elseif($width + $wordwidth <= $maxwidth)
                {
                    $width += $wordwidth + $space;
                    $text .= $word.' ';
                }
                else
                {
                    $width = $wordwidth + $space;
                    $text = rtrim($text)."\n".$word.' ';
                    $count++;
                }
            }
            $text = rtrim($text)."\n";
            $count++;
        }
        $text = rtrim($text);
        return $count;
    }
     
     
     
     
    	//----------------------------------------------------------------------------
    	// MULTI CELL
    	// @in $w = largeur de la cellule (occupe toute la ligne si $w == 0)
    	// @in $h = hauteur de la ligne (et non pas de la cellule multi-lignes !!)
    	// @in $txt = texte à insérer
    	// @in $border = spécification de bordure (0,1,'L','T','R','B')
    	// @in $align = spécification d'alignement ('L', 'R', 'C', 'J')
    	// @in $fill = spécification de remplissage (0,1)
    	// @in $cursorPos = placement du curseur après traitement (0=à droite, 1=saut de ligne)
    	//----------------------------------------------------------------------------
    	function multiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = 0, $cursorPos = 1) {
    		// NB : ces contorsions sont rendues nécessaires par le fait que dans la classe de base, 
    		// SetY() a comme effet de bord de replacer le curseur à gauche...
    		if( $cursorPos == 0 ) {
    			$y = $this->GetY();
    			$x = $this->GetX() + $w;
    		}
    		parent::MultiCell($w, $h, $txt, $border, $align, $fill);
    		if( $cursorPos == 0 ) {
    			$this->SetY($y);
    			$this->SetX($x);
    		}
    	}
     
    	function Header()
    	{
    		$this->SetFont('Arial','',14);
    		$this->multiCell('300','6',"{$_SESSION['nonrapport']}                                      Répertoire des documents Qualités et Techniques du Service Métrologie",'0','L','0','0');
    	    //$this->Write(6, "Répertoire des documents Qualités et Techniques du Service Métrologie");
    		$this->Ln();
    		$this->Ln();
    		$this->SetFont('Arial','',8);
    		$this->multiCell('25','3','Lieu d\'Affectation','0','L','0','0');
    		$this->multiCell('30','3','Type de    procedure','0','L','0','0');
    		$this->multiCell('40','3','Domaine','0','L','0','0');
    		$this->multiCell('8','3','ind','0','L','0','0');
    		$this->multiCell('24','3','Date d\'application','0','L','0','0');
    		$this->multiCell('30','3','Ident','0','L','0','0');
    		$this->multiCell('80','3','Intitulé du document','0','L','0','0');
    		$this->multiCell('5','3','R Q','0','L','0','0');
    		$this->multiCell('5','3','M S','0','L','0','0');
    		$this->multiCell('5','3','R S','0','L','0','0');
    		$this->multiCell('5','3','U O','0','L','0','0');
    		$this->multiCell('5','3','S','0','L','0','0');
    		$this->multiCell('5','3','C','0','L','0','0');
    		$this->multiCell('5','3','F','0','L','0','0');
    		$this->multiCell('5','3','M','0','L','0','0');
    		$this->multiCell('5','3','L','0','L','0','1');
    		$this->SetDrawColor(0,80,180);
    		$this->SetLineWidth(1);
    		$this->Line(5, 30, 293, 30);
    		$this->multiCell('5','6',"",'0','L','0','1');
    		//$this->Cell(190,10,"",0,1,'C');
    		//$this->Ln();
    	}
     
    	//Pied de page
    	function Footer()
    	{
    		$this->SetTextColor(220,50,50);
    		$this->SetDrawColor(0,80,180);
    		//$this->Ln();
    		//$this->Ln();
    		//$this->Ln();
    		//$this->Ln();
    		$this->Sety(-17);
    		$this->Line(00, 190, 300, 190);
    		$this->SetFont('Arial','',8);
    	    $this->multiCell('300','6','RQ: responsable qualité ; MS: Métrologie sur site ; RS: Responsable de service ;
    		UO: Responsable Unité Opérationel ; S: Secrétaire ; C: Commercial ; F: Correspondant Formation ; M: Métrologue ; L: Laboratoire','0','C','0','0');
    		$this->SetTextColor(0,0,0);
    		$this->Cell(0,5,'Page '.$this->PageNo().' sur {nb}',0,0,'R');
    	}
     
    }
     
     
     
    //$pdf=new PDF();
    $pdf=new PDF('L','mm','A4');
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->SetFont('Arial','',8);
    mysql_connect("localhost","root","mysql");
    mysql_select_db("documentaire");
    $req = mysql_query("SELECT * FROM repertoire WHERE lieu='{$_SESSION['lieu']}'");
    $pdf->multiCell('5','1',"",'0','J','0','1');
    while($result = mysql_fetch_array($req))
    {
    	//$pdf->multiCell('5','1',"",'0','J','0','1');
    	//$lieu=$result['lieu'];
    	//$nb=$pdf->WordWrap($result['lieu'], 25);
    	$pdf->multiCell('25','3',$result['lieu'],'0','L','0','0');
    	//$type=$result['type'];
    	//$nb=$pdf->WordWrap($result['type'], 25);
    	$pdf->multiCell('30','3',$result['type'],'0','L','0','0');
    	//$dom=$result['domaine'];
    	//$nb=$pdf->WordWrap($result['domaine'], 45);
    	$pdf->multiCell('40','3',$result['domaine'],'0','L','0','0');
    	//$ind=$result['ind'];
    	//$nb=$pdf->WordWrap($result['ind'], 25);
    	$pdf->multiCell('8','3',$result['ind'],'0','L','0','0');
    	//$ap=$result['application'];
    	//$nb=$pdf->WordWrap($result['application'], 23);
    	$pdf->multiCell('24','3',$result['application'],'0','L','0','0');
    	//$rap=$result['rapport'];
    	//$nb=$pdf->WordWrap($result['rapport'], 25);
    	$pdf->multiCell('30','3',$result['rapport'],'0','L','0','0');
    	//$int=$result['intitule'];	
    	//$pdf->SetFont('Arial','',10);
    	//$nb=$pdf->WordWrap($result['intitule'], 50);
    	$pdf->multiCell('80','3',$result['intitule'],'0','L','0','0');
    	//$pdf->SetFont('Arial','',10);
    	//$rq=$result['rq'];
    	//$nb=$pdf->WordWrap($result['rq'], 7);
    	$pdf->multiCell('5','3',$result['rq'],'0','L','0','0');
    	//$ms=$result['ms'];
    	//$nb=$pdf->WordWrap($result['ms'], 7);
    	$pdf->multiCell('5','3',$result['ms'],'0','L','0','0');
    	//$rs=$result['rs'];
    	//$nb=$pdf->WordWrap($result['rs'], 7);
    	$pdf->multiCell('5','3',$result['rs'],'0','L','0','0');
    	//$uo=$result['uo'];
    	//$nb=$pdf->WordWrap($result['uo'], 7);
    	$pdf->multiCell('5','3',$result['uo'],'0','L','0','0');
    	//$s=$result['s'];
    	//$nb=$pdf->WordWrap($result['s'], 7);
    	$pdf->multiCell('5','3',$result['s'],'0','L','0','0');
    	//$c=$result['c'];
    	//$nb=$pdf->WordWrap($result['c'], 7);
    	$pdf->multiCell('5','3',$result['c'],'0','L','0','0');
    	//$f=$result['f'];
    	//$nb=$pdf->WordWrap($result['f'], 7);
    	$pdf->multiCell('5','3',$result['f'],'0','L','0','0');
    	//$m=$result['m'];
    	//$nb=$pdf->WordWrap($result['m'], 7);
    	$pdf->multiCell('5','3',$result['m'],'0','L','0','0');
    	//$l=$result['l'];
    	//$nb=$pdf->WordWrap($result['l'], 7);
    	$pdf->multiCell('5','3',$result['l'],'0','L','0','1');
    	$pdf->multiCell('5','6',"",'0','J','0','1');
    	//$pdf->Cell(190,10,"",0,1,'C');
    	//$pdf->Ln();
     
    }
    $pdf->Output();
    ?>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Retour à la ligne dans une cellule de tableau
    Par v0nv0n dans le forum Tableaux - Graphiques - Images - Flottants
    Réponses: 2
    Dernier message: 20/11/2009, 14h27
  2. [FPDF] Aller à la ligne dans une cellule
    Par pasbonte dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 19/11/2009, 19h39
  3. [JS/ASP] Saut de lignes dans une cellule d'un tableau
    Par Enthau dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 10/03/2009, 17h29
  4. Saut de ligne dans une cellule de tableau
    Par enneite dans le forum Tableaux - Graphiques - Images - Flottants
    Réponses: 3
    Dernier message: 05/12/2007, 13h00
  5. [Affichage] Saut de ligne dans une cellule de tableau
    Par pc.bertineau dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 19/02/2007, 09h54

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