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

PHP & Base de données Discussion :

Extraction d'un fichier Excel Entre deux dates (Date debut et Date fin)


Sujet :

PHP & Base de données

  1. #1
    Membre du Club
    Femme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Juin 2014
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2014
    Messages : 51
    Points : 40
    Points
    40
    Par défaut Extraction d'un fichier Excel Entre deux dates (Date debut et Date fin)
    bonjour ,
    je fais l'exportation d'un fichier excel contenant tous les donnés enregistrés dans la base, au niveau de mon interface j'affiche liste des donnés entre deux dates, je veux faire même chose pour le fichier excel qu'il n'affiche que les donnés entre deux dates .

    J'ai pas réussi à faire ceci pendant l'extraction: je vous communique le code de la fonction d'affiche et puis le code de la fonction d'extraction .
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     function FindDisqueDate($d_debut,$d_fin) {
            $cnx = new Connection();
            try {
                $sql = "SELECT * FROM disque WHERE D_T BETWEEN '$d_debut' And '$d_fin'  ";
                return $cnx->getDB()->query($sql)->fetchAll(2);
            } catch (PDOException $e) {
                echo $e->getMessage() . "<br>";
                echo "la requete n'est pas valide";
                exit;
            } 
        }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     function generatecsv(){
    	$this->layout = 'layout';
    		$this->loadModel('disque');
    		$dis = new Disque();
    		$disque = $dis->OutCSV();//$d_debut,$d_fin);
    		echo json_encode(0);
    		exit;
    	}

    ici c'est le code de la fonction d'exportation :
    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
    function OutCSV() {
    	error_reporting(E_ALL);
    	ini_set('display_errors', TRUE);
    	ini_set('display_startup_errors', TRUE);
    	require_once ROOT.'lib/PHPExcel.php';
    		$cnx = new Connection();
    		$table = 'disque';
    		$result = $cnx->getDB()->query("SHOW COLUMNS FROM ".$table."");
    		$data = array('Serial Number', ' Capacity ',' Model ',' Wiping Final Status ',' Wiping Duration ',' Date Time ',' Description ',' Number On Hours ',' SMART STATUS ');	 
    		$values = $cnx->getDB()->query("SELECT * FROM Disque WHERE D_T BETWEEN '2014-06-01 00:00:00' And '2014-06-30 00:00:00'");
    		$rowrn = $values->fetchAll(PDO::FETCH_NUM);
    		array_unshift($rowrn, $data);
    		$objPHPExcel = new PHPExcel();
    		$objWorksheet = $objPHPExcel->getActiveSheet();
    		$objWorksheet->getColumnDimension('A')->setAutoSize(true);
    		$objWorksheet->getColumnDimension('B')->setAutoSize(true);
    		$objWorksheet->getColumnDimension('C')->setAutoSize(true);
    		$objWorksheet->getColumnDimension('D')->setAutoSize(true);
    		$objWorksheet->getColumnDimension('E')->setAutoSize(true);
    		$objWorksheet->getColumnDimension('F')->setAutoSize(true);
    		$objWorksheet->getColumnDimension('G')->setAutoSize(true);
    		$objWorksheet->getColumnDimension('H')->setAutoSize(true);
    		$objWorksheet->getColumnDimension('I')->setAutoSize(true);
     
    		 $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->applyFromArray( // Center Cell B2
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
     		$objPHPExcel->getActiveSheet()->getStyle('A1:A100')->getAlignment()->applyFromArray(
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
      		$objPHPExcel->getActiveSheet()->getStyle('B3:B100')->getAlignment()->applyFromArray(
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
    		 $objPHPExcel->getActiveSheet()->getStyle('A2:A100')->getAlignment()->applyFromArray(
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
    		 $objPHPExcel->getActiveSheet()->getStyle('C2:C100')->getAlignment()->applyFromArray(
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
    		 $objPHPExcel->getActiveSheet()->getStyle('D2:D100')->getAlignment()->applyFromArray(
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
     		$objPHPExcel->getActiveSheet()->getStyle('E2:E100')->getAlignment()->applyFromArray(
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
    		 $objPHPExcel->getActiveSheet()->getStyle('F2:F100')->getAlignment()->applyFromArray(
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
    		 $objPHPExcel->getActiveSheet()->getStyle('G2:G100')->getAlignment()->applyFromArray(
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
     		$objPHPExcel->getActiveSheet()->getStyle('H2:H100')->getAlignment()->applyFromArray(
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
     		$objPHPExcel->getActiveSheet()->getStyle('I2:I100')->getAlignment()->applyFromArray(
             array(
                 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                 'vertical'   => PHPExcel_Style_Alignment::VERTICAL_CENTER,
             )
     );
    		$objWorksheet->fromArray($rowrn);
    		$styleA1 = $objWorksheet-> getStyle('A1:I1');
    		//$cell->HorizontalAlignment = "xlCenter";
    		$styleA1-> applyFromArray(array(
            'font'=> array('bold'=> true,'type'=>PHPExcel_Style_Fill::FILL_SOLID,
                    'color'=>array('argb'=> '0131B4'),
    				'alignement'=> array(
                    'horizontal'=> PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                    'vertical'=> PHPExcel_Style_Alignment::VERTICAL_CENTER),
    				)
    ));
    	//Duplication du style
    		$objWorksheet-> duplicateStyle($styleA1, 'A1:I1');
    		$GrapheWorkSheet = new PHPExcel_Worksheet($objPHPExcel, 'Graphe');
    		$objPHPExcel->addSheet($GrapheWorkSheet, 1);
    		$values = $cnx->getDB()->query("SELECT COUNT(SN) as total FROM ".$table."");
    		$total = $values->fetch();
    		$values = $cnx->getDB()->query("SELECT COUNT(SN) as success FROM ".$table." WHERE W_F_S = 0");
    		$success = $values->fetch();
    		$values = $cnx->getDB()->query("SELECT COUNT(SN) as faild FROM ".$table." WHERE W_F_S = 1");
    		$faild = $values->fetch();
    		$f = ($faild['faild']/$total['total'])*100 ;
    		$s = ($success['success']/$total['total'])*100;
     
     
    		$GrapheWorkSheet->fromArray(array(
    		array('Total',   $total['total']),
    		array('Failed', $f),
    		array('Success', $s  ),
    	));
    	$categories = array(
    		new PHPExcel_Chart_DataSeriesValues('String', 'Graphe!$A$2:$A$3', null, 2)
    	);
    	$values = array(
    		new PHPExcel_Chart_DataSeriesValues('Number', 'Graphe!$B$2:$B$3', null, 2)
    	);
    	$series = new PHPExcel_Chart_DataSeries(
    		PHPExcel_Chart_DataSeries::TYPE_PIECHART,       // plotType
    		PHPExcel_Chart_DataSeries::GROUPING_STANDARD,  // plotGrouping
    		range(0, count($values)-1),                                    	// plotOrder
    		null,                                        // plotLabel
    		$categories,                                    // plotCategory
    		$values                                         // plotValues
    	);
    	$layout1 = new PHPExcel_Chart_Layout();
    	$layout1->setShowPercent(TRUE);
    	$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
    	$labels = array(
        new PHPExcel_Chart_DataSeriesValues('String', 'Graphe!$B$1', null, 1),
        new PHPExcel_Chart_DataSeriesValues('String', 'Graphe!$C$1', null, 1),
    		);
     
    	$title = new PHPExcel_Chart_Title('             Fail                                          Success');
    	$plotarea = new PHPExcel_Chart_PlotArea($layout1, array($series));
    	$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_LEFT, NULL, false);
    	$xTitle   = new PHPExcel_Chart_Title('Fail');
        $yTitle   = new PHPExcel_Chart_Title('Success');
    	$chart = new PHPExcel_Chart(
    		"chart1",                                       // name
    		$title, 
    		$legend,                                        // legend
    		$plotarea,                                      // plotArea
     
    		true,                                           // plotVisibleOnly
    		0,                                              // displayBlanksAs
    		$xTitle, 
    		$yTitle                                          // xAxisLabel                                          // yAxisLabel
    	);
     
    	$chart->setTopLeftPosition('A7');
    	$chart->setBottomRightPosition('H20');
    	$GrapheWorkSheet->addChart($chart);
    	$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    	$writer->setIncludeCharts(TRUE);
    	header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    	header('Content-Disposition: attachment;filename=DisquesHistory_'.date("Y-m-d_H-i",time()).'.xlsx');
    	$writer->save('php://output');

  2. #2
    Membre confirmé Avatar de 01001111
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2009
    Messages
    319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Loire (Auvergne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2009
    Messages : 319
    Points : 509
    Points
    509
    Par défaut
    Bonjour, as-tu fait un print_r sur $data pour voir si ta requête sort bien agencée dans le tableau?
    C'est un peu bourrin d'utiliser un array_unshift avec deux tableaux en arguments, me semble-t-il.
    De plus tu veux surement ajouter les éléments de data en début de $rowrn donc il faut faire autrement.

    Sinon je ne vois aucune référence à $data par la suite dans les fonctions de mise en forme du xlsx, ça ne me parait pas normal...

  3. #3
    Membre du Club
    Femme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Juin 2014
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2014
    Messages : 51
    Points : 40
    Points
    40
    Par défaut
    Bonjour ,
    Merci pour votre Réponse Sinon J'ai enfin réussi à extraire mon fichier excel , j'ai utilisé PHPEXCEl , mais les légendes n'apparaissent pas dans les graphes de type Pie chart et Encore j'ai Un probléme dés l'ouverture du fichier Excel: Il m'affiche Contenu Illisible dans le fichier .xlsx veuillez confirmer qu'il provient d'une source fiable , je clique sur oui , il m'affiche un autre message : Excel a terminé la réparation du document :Fermer ! Et puis il s'ouvre normalement ! Si Seulement Je peux eliminer ces messages!
    voilà !

  4. #4
    Membre confirmé Avatar de 01001111
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2009
    Messages
    319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Loire (Auvergne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2009
    Messages : 319
    Points : 509
    Points
    509
    Par défaut
    php excel te génère-t-il un fichier xlsx aux normes?

    si c'est bien le cas, je ne sais pas d'où ça vient, sinon vérifie le header php que tu fais, il n'est peut-être plus correct.

  5. #5
    Membre du Club
    Femme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Juin 2014
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2014
    Messages : 51
    Points : 40
    Points
    40
    Par défaut Erreur Excel
    voilà mon code est là : j'arrive ni à afficher les légendes ni à résoudre le probléme montré
    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
     
        function OutCSV($d_debut, $d_fin, $condition,$conditionBie) {
            error_reporting(E_ALL);
    		ini_set('display_errors', TRUE);
    		ini_set('display_startup_errors', TRUE);
         //   ini_set('display_errors', 0);
    //        ini_set('display_startup_errors', TRUE);
            require_once ROOT . 'lib/PHPExcel.php';
    		require_once ROOT . 'lib/PHPExcel/IOFactory.php';
            $cnx = new Connection();
            $table = 'disque';
            $result = $cnx->getDB()->query("SHOW COLUMNS FROM " . $table . "");
            $data = array('Serial Number', ' Capacity ', ' Model ', ' Wiping Final Status ', ' Wiping Duration ', ' Date Time ', ' Description ', ' Number On Hours ', ' SMART STATUS ', 'Machine ID', 'Operator ID', 'Slot Position','PlugedIn','Mouvement');
            // D�finition de la requ�te : si on a des dates, on va chercher entre elles, sinon on r�cup�re toute la DB
            if (!empty($d_debut) && !empty($d_fin)) {
                $query = "SELECT * FROM disque WHERE (DATE(D_T) BETWEEN '$d_debut' And '$d_fin')And Plugged_IN = 0 And Mvmt='Wiping' $condition";
            } else {
                $query = "SELECT * FROM Disque where Mvmt='Wiping'";
            }
            $values = $cnx->getDB()->query($query);
            $rowrn = $values->fetchAll(PDO::FETCH_NUM);
            array_unshift($rowrn, $data);
     
    //        echo '<pre>$values: ' . print_r($values, true) . '</pre>';
    //        echo '<pre>$rowrn: ' . print_r($rowrn, true) . '</pre>';
    //        die();
            //array_unshift($rowrn, $data);
            $objPHPExcel = new PHPExcel();
            $objWorksheet = $objPHPExcel->getActiveSheet();
            $objWorksheet->getColumnDimension('A')->setAutoSize(true);
            $objWorksheet->getColumnDimension('B')->setAutoSize(true);
            $objWorksheet->getColumnDimension('C')->setAutoSize(true);
            $objWorksheet->getColumnDimension('D')->setAutoSize(true);
            $objWorksheet->getColumnDimension('E')->setAutoSize(true);
            $objWorksheet->getColumnDimension('F')->setAutoSize(true);
            $objWorksheet->getColumnDimension('G')->setAutoSize(true);
            $objWorksheet->getColumnDimension('H')->setAutoSize(true);
            $objWorksheet->getColumnDimension('I')->setAutoSize(true);
            $objWorksheet->getColumnDimension('J')->setAutoSize(true);
            $objWorksheet->getColumnDimension('K')->setAutoSize(true);
            $objWorksheet->getColumnDimension('L')->setAutoSize(true);
     
     
            $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->applyFromArray(// Center Cell B2
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('A1:A100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('B3:B100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('A2:A100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('C2:C100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('D2:D100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('E2:E100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('F2:F100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('G2:G100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('H2:H100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('I2:I100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('J2:J100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('J2:A100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objPHPExcel->getActiveSheet()->getStyle('A2:A100')->getAlignment()->applyFromArray(
                    array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                    )
            );
            $objWorksheet->fromArray($rowrn);
            $styleA1 = $objWorksheet->getStyle('A1:M1');
            $styleA1->applyFromArray(array(
                'font' => array('bold' => true, 'type' => PHPExcel_Style_Fill::FILL_SOLID,
                    'color' => array('argb' => '0131B4'),
                    'alignement' => array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
                        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER),
                )
            ));
            //Duplication du style
            $objWorksheet->duplicateStyle($styleA1, 'A1:I1');
            $GrapheWorkSheet = new PHPExcel_Worksheet($objPHPExcel, 'Graphe');
            $objPHPExcel->addSheet($GrapheWorkSheet, 1);
     
     
     
    		if($conditionBie["num"] == 0){
    $values = $cnx->getDB()->query("SELECT COUNT(SN) as total FROM ".$table."");
    		$total = $values->fetch();
     
    		$values = $cnx->getDB()->query("SELECT COUNT(SN) as success FROM ".$table." WHERE W_F_S = 'Failed");
    		$success = $values->fetch();
     
    		$values = $cnx->getDB()->query("SELECT COUNT(SN) as faild FROM ".$table." WHERE W_F_S = 'Succeeded");
    		$faild = $values->fetch();
     
    		$f = ($faild['faild']/$total['total'])*100 ;
    		$s = ($success['success']/$total['total'])*100;
     
    		$GrapheWorkSheet->fromArray(array(
    		array('Total',   $total['total']),
    		array('Failed', $f),
    		array('Success', $s  ),
    	));
     
    	}
    			if($conditionBie["num"] == 1){
    $tab=array();
    					$values = $cnx->getDB()->query("SELECT Model  FROM ".$table." GROUP BY Model ");
            $models = $values->fetchAll(PDO::FETCH_NUM);
     
    		$values = $cnx->getDB()->query("SELECT COUNT(SN) as total FROM ".$table."");
    		$total = $values->fetch();
    					array_push($tab,array('Total',   $total['total'])) ;
     
    			foreach ($models as $valeur)
    			{$porcentage=0 ;
     
    			$porcentage = $cnx->getDB()->query('SELECT COUNT(SN) as porcentage FROM '.$table.' WHERE Model ="'.$valeur[0].'"');
    					$porcentage = $porcentage->fetch();
     
    $porcentage =($porcentage["porcentage"]/$total['total'])*100 ;
    			array_push($tab,array($valeur[0], $porcentage)) ;
    			}
     
    			$GrapheWorkSheet->fromArray($tab);
     
    	}
    			if($conditionBie["num"] == 2){
    $tab=array();
    					$values = $cnx->getDB()->query("SELECT Capacity  FROM ".$table." GROUP BY Capacity ");
            $models = $values->fetchAll(PDO::FETCH_NUM);
     
    		$values = $cnx->getDB()->query("SELECT COUNT(SN) as total FROM ".$table."");
    		$total = $values->fetch();
    					array_push($tab,array('Total',   $total['total'])) ;
     
    			foreach ($models as $valeur)
    			{$porcentage=0 ;
     
    			$porcentage = $cnx->getDB()->query('SELECT COUNT(SN) as porcentage FROM '.$table.' WHERE Capacity ="'.$valeur[0].'"');
    					$porcentage = $porcentage->fetch();
     
    $porcentage =($porcentage["porcentage"]/$total['total'])*100 ;
    			array_push($tab,array($valeur[0], $porcentage)) ;
    			}
     
    			$GrapheWorkSheet->fromArray($tab);
     
    	}
    			if($conditionBie["num"] == 3){
    $tab=array();
    					$values = $cnx->getDB()->query("SELECT W_D  FROM ".$table." GROUP BY W_D ");
            $models = $values->fetchAll(PDO::FETCH_NUM);
     
    		$values = $cnx->getDB()->query("SELECT COUNT(SN) as total FROM ".$table."");
    		$total = $values->fetch();
    					array_push($tab,array('Total',   $total['total'])) ;
    $j=0;$i;
    			foreach ($models as $valeur)
    			{ $j++;  for($i=$j;$i<count($models); $i++){
    			$porcentage=0 ;
     
    		$porcentage = $cnx->getDB()->query('SELECT COUNT(SN) as porcentage FROM '.$table.' WHERE W_D BETWEEN '.$valeur[0].' AND  '.$models[$i][0]);
    					//return var_dump('SELECT COUNT(SN) as porcentage FROM '.$table.' WHERE W_D BETWEEN '.$valeur[0].' AND  '.$models[$i][0]) ;
    					$porcentage = $porcentage->fetch();
     
    $porcentage =($porcentage["porcentage"]/$total['total'])*100 ;
    			array_push($tab,array($valeur[0]."-".$models[$i][0], $porcentage)) ;
    			}
    			}
     
    			$GrapheWorkSheet->fromArray($tab);
     
    	}
    			if($conditionBie["num"] == 4){
    $tab=array();
    					$values = $cnx->getDB()->query("SELECT Model  FROM ".$table." GROUP BY Model ");
            $models = $values->fetchAll(PDO::FETCH_NUM);
     
    		$values = $cnx->getDB()->query("SELECT COUNT(SN) as total FROM ".$table."");
    		$total = $values->fetch();
    					array_push($tab,array('Total',   $total['total'])) ;
     
    			foreach ($models as $valeur)
    			{$porcentage=0 ;
     
    			$porcentage = $cnx->getDB()->query('SELECT COUNT(SN) as porcentage FROM '.$table.' WHERE Model ="'.$valeur[0].'"');
    					$porcentage = $porcentage->fetch();
     
    $porcentage =($porcentage["porcentage"]/$total['total'])*100 ;
    			array_push($tab,array($valeur[0], $porcentage)) ;
    			}
     
    			$GrapheWorkSheet->fromArray($tab);
     
    	}
     
     
    	$labels = array(
    		new PHPExcel_Chart_DataSeriesValues('String', 'Graphe!$A$2', null, 2)
    	);
    	$categories = array(
    		new PHPExcel_Chart_DataSeriesValues('String', 'Graphe!$A$2:$A$'.count($tab), null, 2)
    	);
    	$values = array(
    		new PHPExcel_Chart_DataSeriesValues('Number', 'Graphe!$B$2:$B$'.count($tab), null, 2)
    	);
     
    				if($conditionBie["num"] == 3 || $conditionBie["num"] == 4 ){
     
     
    	$series = new PHPExcel_Chart_DataSeries(
    		PHPExcel_Chart_DataSeries::TYPE_BARCHART,       // plotType
    		PHPExcel_Chart_DataSeries::GROUPING_STANDARD,  // plotGrouping
    		range(0, count($values)-1),                                    	// plotOrder
    		$labels,                                        // plotLabel
    		$categories,                                    // plotCategory
    		$values                                         // plotValues
    	);
     
    	}
     
    	else {
    	$series = new PHPExcel_Chart_DataSeries(
    		PHPExcel_Chart_DataSeries::TYPE_PIECHART,       // plotType
    		PHPExcel_Chart_DataSeries::GROUPING_STANDARD,  // plotGrouping
    		range(0, count($values)-1),                                    	// plotOrder
    		$labels,                                        // plotLabel
    		$categories,                                    // plotCategory
    		$values                                         // plotValues
    	);
     
    	}
    	$layout1 = new PHPExcel_Chart_Layout();
    	$layout1->setShowPercent(TRUE);
    	$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
    	$labels = array(
        new PHPExcel_Chart_DataSeriesValues('String', 'Graphe!$B$2:$B$15', null, 2),
        new PHPExcel_Chart_DataSeriesValues('String', 'Graphe!$C$1', null, 2),
    		);
     
    	$title = new PHPExcel_Chart_Title('Monitoring HDD Graph ');
    	$plotarea = new PHPExcel_Chart_PlotArea($layout1, array($series));
    	$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_LEFT, NULL, false);
     
    	$chart = new PHPExcel_Chart(
    		"chart1",                                       // name
    		$title, 
    		$legend,                                        // legend
    		$plotarea,                                      // plotArea
    		true,                                           // plotVisibleOnly
    		0                                          // displayBlanksAs
    		                                         // xAxisLabel                                          // yAxisLabel
    	);
    	$layout1 = new PHPExcel_Chart_Layout();
    	$layout1->setShowVal(TRUE);      // Initializing the data labels with Values
    	$layout1->setShowPercent(TRUE);  // Initializing the data labels with Percentages
     
    	$chart->setTopLeftPosition('E1');
    	$chart->setBottomRightPosition('H25');
    	$GrapheWorkSheet->addChart($chart);
            $writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
            $writer->setIncludeCharts(TRUE);
            ob_get_clean();
            header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
            header('Content-Disposition: attachment;filename=DisquesHistory_' . date("Y-m-d_H-i", time()) . '.xlsx');
            $writer->save('php://output');
            $writer->save('php://output');
            $writer->save("Historique/DisquesHistory ".date("Y-m-d_H-i",time()).".xlsx");
        }
     
    }

  6. #6
    Membre confirmé Avatar de 01001111
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2009
    Messages
    319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Loire (Auvergne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2009
    Messages : 319
    Points : 509
    Points
    509
    Par défaut
    pourquoi trois fois save?
    tu bourres le tampon de php avec deux saves successifs, puis tu génères un fichier sur disque.

    comprends pas, seul un save suffit à priori...

    Avec ce code essaie de charger un xlsx depuis le disque:

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    $file = "myfile.xlsx" ;
    header('Content-Disposition: attachment; filename=' . $file );
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Length: ' . filesize($file));
    header('Content-Transfer-Encoding: binary');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    readfile('myfile.xlsx');

    si ça marche, essaie de reproduire ce code dans ton fichier php après avoir fait un save sur le disque, un petit usleep pour laisser le temps au systême de fichiers de le prendre en compte et le read de ce code fonctionnera.

Discussions similaires

  1. Réponses: 2
    Dernier message: 13/01/2015, 08h56
  2. Chercher les fichiers crées entre deux dates
    Par almofa237 dans le forum Administration système
    Réponses: 10
    Dernier message: 07/03/2011, 12h23
  3. Jointure entre un fichier Excel et deux tables SQL Server EN VB
    Par sql_bin dans le forum Général VBA
    Réponses: 1
    Dernier message: 10/11/2010, 15h57
  4. Réponses: 5
    Dernier message: 10/04/2006, 12h07
  5. Récupérer du texte d'un fichier xml entre deux balises
    Par manutudescends dans le forum Format d'échange (XML, JSON...)
    Réponses: 24
    Dernier message: 30/11/2005, 18h29

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