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
| #!D:\Perl\bin
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
use Math::Round qw(:all);
my %recept=();
my $count_80=0;
my $count_20=0;
my $nb_all=0;
my @alpha=('A','B','C','D','E','F','G','H','I','J','K','L','M','N','M','O','P','Q','R','S','T');
#my $file="C:/PL/VN.xls";
&full_recept_table(\%recept);
sub full_recept_table
{
my $recept=@_;
my $i=1;
my $j=1;
##my $file=@_;
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $Workbook = $Excel->Workbooks->Open("C:/PL/APV.xls");
my $Sheet = $Workbook->Worksheets(1);
my $numRows = $Sheet->UsedRange->Find({What=>"*",SearchDirection=>xlPrevious,SearchOrder=>xlByRows})->{Row};
# #my $numCols=$Sheet->UsedRange->Find({What=>"*",SearchDirection=>xlPrevious,SearchOrder=>xlByCols})->{Col};
# #print $numRows ." ".$numCols;
################################## add new
##création d'un nouveau classeur pour les 80 pourcent
my $xl80 = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
## nouveau workbook
my $w80=$xl80->Workbooks->Open("C:/80.xls");
my $Sheet80=$w80->Worksheets(1);
##un nouveau classeur pour les 20 pourcent
my $xl20 = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
# #nouveau workbook
my $w20=$xl20->Workbooks->Open("C:/20.xls");
my $Sheet20=$w20->Worksheets(1);
###########################
for (my $row=2;$row<=$numRows;$row++)
{
my $nom_recep= $Sheet->Range("O".$row)->{'Value'};
$recept->{$nom_recep}{'all'}++;
}
# #pour ajouter des clés
foreach my $f(keys %{$recept})
{
$recept->{$f}{'80'} = round ($recept->{$f}{'all'} * 80/100);
$recept->{$f}{'20'} = round ($recept->{$f}{'all'} * 20/100);
}
## vérifier les résultats
#foreach my $f(keys %{$recept})
# {
# $nb_all+=$recept->{$f}{'r'} ;
#print "\t".$f ."\tNBFiches = ".$recept->{$f}{'all'}."\t 80 = ".$recept->{$f}{'80'}."\n";
# }
## print "tous = ".$nb_all."\n";
for (my $row=2;$row<=$numRows; $row++)
{
my $recept_name = $Sheet->Range("O".$row)->{'Value'};
if ($recept->{$recept_name}{'80'} > 0 )
{
for (my $col=0 ; $col<=15 ; $col++)
{
## ajouter la cellule à la colonne qui convient les 80 pourcent
##print $Sheet->Range($alpha[$col].$row)->{'Value'}."\n";
$Sheet80->Range($alpha[$col].$i)->{'Value'}= $Sheet->Range($alpha[$col].$row)->{'Value'};
}
$i++;
$recept->{$recept_name}{'80'}-=1;
}
# #print $line;
##$count_80++; # combien y a t il des 80 pourcent
##print$recept->{$Sheet->Range("O".$row)->{'Value'}}{'80'}."\n";
##ajout des données
elsif ($recept->{$Sheet->Range("O".$row)->{'Value'}}{'20'}>0)
{
## ajouter dans le deuxième fichier excel les 20 pourcent
for (my $col=0 ; $col<=15 ; $col++)
{
##$count_20++; # combien y a des 20 pourcent
$Sheet20->Range($alpha[$col].$j)->{'Value'}= $Sheet->Range($alpha[$col].$row)->{'Value'};
}
$recept->{$recept_name}{'20'}-=1;
$j++;
}
}
## Clean up
$Sheet80->Saved;
$Sheet20->Saved;
$w80->Close;
$w20->Close;
##$Sheet80 = 0;
##$w80 = 0;
}
##print "nb fiches80 = ".$count_80."\t nbfiches20 = ".$count_20."\n"; |
Partager