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
| 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();
$i = 0;
if ($result->rowCount() > 0){
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
array_push($data, $row['Field']);
$i++;
}
}
$values = $cnx->getDB()->query("SELECT * FROM ".$table."");
$rowrn = $values->fetchAll(PDO::FETCH_NUM);
array_unshift($rowrn, $data);
$style['red_text']=new PHPExcelstyle()
$objPHPExcel = new PHPExcel();
$objWorksheet = $objPHPExcel->getActiveSheet();
$objWorksheet->fromArray($rowrn);
$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
array(0), // plotOrder
null, // plotLabel
$categories, // plotCategory
$values // plotValues
);
$layout1 = new PHPExcel_Chart_Layout();
$layout1->setShowPercent(TRUE);
$title = new PHPExcel_Chart_Title('HDD SUCCESS FAILD');
$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, // title
$legend, // legend
$plotarea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
null, // xAxisLabel
null // yAxisLabel
);
$chart->setTopLeftPosition('A7');
$chart->setBottomRightPosition('H20');
$GrapheWorkSheet->addChart($chart);
$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$writer->setIncludeCharts(TRUE);
$writer->save("Historique/DisquesHistory ".date("Y-m-d_H-i",time()).".xlsx");
} |
Partager