From 7afc4a58a8e94a0299f961a6312a211c350e3197 Mon Sep 17 00:00:00 2001 From: mrdjez Date: Tue, 28 Mar 2017 20:22:07 +0200 Subject: [PATCH] Verif... --- SQL2XLS.pl | 33 +++++++++++++-------------------- SQL2XLS.pm | 24 ++++++++++++------------ 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/SQL2XLS.pl b/SQL2XLS.pl index b0e4a9b..ed7fe4a 100644 --- a/SQL2XLS.pl +++ b/SQL2XLS.pl @@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!/usr/bin/env perl #=============================================================================== # # FILE: SQL2XLS.pl @@ -10,10 +10,10 @@ # BUGS: --- # NOTES: --- # AUTHOR: grouch' -# ORGANIZATION: +# ORGANIZATION: # VERSION: 1.0 # CREATED: 27/03/17 -# CHANGE_LOG: +# CHANGE_LOG: # #=============================================================================== @@ -37,15 +37,15 @@ my $db = { }; #------------------------------------------------------------------------------- -# Requête SQL -#------------------------------------------------------------------------------- +# Requête SQL +#------------------------------------------------------------------------------- my $prog = 'ATO045'; my $datedebut = '20000101000000'; #my $datedebut = '20170201000000'; my $datefin = '20191231235959'; # une première requête -my $sql1 = qq{SELECT +my $sql1 = qq{SELECT MPOS ,NOM ,MINI @@ -55,35 +55,28 @@ my $sql1 = qq{SELECT ,Ppk ,NbPieces ,nb_total_occurences - + ,CRITICAL ,MAJOR ,ICD ,COMMENTAIRE_DCM - - + + FROM calcul_capa($datedebut, $datefin, '$prog') WHERE MINI notNULL AND MAXI notNULL --AND Pp > 1.33 AND Ppk > 1 }; - + #une deuxième requête my $sql2 = qq{SELECT * FROM DATA WHERE PROG = '$prog'}; - + #la sub prend une ref de hash en argument # nom_de_l'onglet => requete_sql my $requete = {"capa" => $sql1, "data" => $sql2}; - + #------------------------------------------------------------------------------- # APPEL SUB -#------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- SQL2XLS::SQL2XLS($db, $requete, 'toto.xlsx'); - - - - - - - diff --git a/SQL2XLS.pm b/SQL2XLS.pm index 42bc1b6..4c0c41c 100644 --- a/SQL2XLS.pm +++ b/SQL2XLS.pm @@ -13,7 +13,7 @@ package SQL2XLS; # ORGANIZATION: non # VERSION: 1.0 # CREATED: 28/03/17 -# CHANGE_LOG: +# CHANGE_LOG: # #=============================================================================== use Carp; @@ -32,13 +32,13 @@ use subs qw(SQL2XLS); #------------------------------------------------------------------------------- # SUB SQL2XLS # arguments : \%db \%requete, $filename -#------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- sub SQL2XLS{ my $ref_db = shift; my $ref_requete = shift; my $filename = shift; - + # connexion base say "dbi:Pg:dbname=${$ref_db}{dbname};host=${$ref_db}{host};port=${$ref_db}{port}"; my $dbh = DBI->connect("dbi:Pg:dbname=$ref_db->{dbname};host=$ref_db->{host};port=$ref_db->{port}", @@ -46,24 +46,24 @@ sub SQL2XLS{ $ref_db->{password}, {AutoCommit => 1, RaiseError => 1, PrintError => 0} ); - + #création du fichier Excel my $wb = Excel::Writer::XLSX->new($filename); $wb->set_properties( title => 'SQL2XLS', author => 'C.GRUSZKA', ); - + #on boucle pour créer tous les onglets du workbook - foreach my $tab (keys %{$ref_requete}){ + foreach my $tab (keys %{$ref_requete}){ #création de l'onglet say "\n\nOnglet $tab"; my $ws = $wb->add_worksheet($tab); $ws->set_zoom(85); - + #récupèration de la requête SQL associée à l'onglet - my $sql = $ref_requete->{$tab}; - + my $sql = $ref_requete->{$tab}; + #requêtage ! my $sth = $dbh->prepare($sql); $sth->execute; @@ -73,15 +73,15 @@ sub SQL2XLS{ say "Nombre de colonnes : $nb_col"; my $nb_items = scalar @$list; say "Nombre de lignes : $nb_items"; - + #construction de l'array de hash des entêtes de colonnes (à tes souhaits) my @arraycol; foreach my $col (@{$colonnes}){ push @arraycol, { header => "$col" }; } - + #table EXCEL $ws->add_table(0,0,$nb_items,$nb_col-1, { data => $list, header_row => 1, autofilter => 1,style => 'Table Style Medium 5', columns => \@arraycol }); } } -1; \ No newline at end of file +1;