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
   | #!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Cwd;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::Variant;
$Win32::OLE::Warn = 1;
require Tk::BrowseEntry;
 
my $mw = MainWindow->new(
  -title      => "bm",
  -background => 'white',
);
$mw->minsize( 500, 500 );
 
my $frame = $mw->Frame()->pack(qw/ -pady 10 -padx 10 /);
 
my ( $argument1, $argument2 );
 
my $BrowseEntry1 = $frame->BrowseEntry(
  -label    => "name : ",
  -variable => \$argument1,
  -choices  => [ "$argument1" ],
)->pack(qw/ -side left -padx 10 /);
 
my $BrowseEntry2 = $frame->BrowseEntry(
  -label    => "n : ",
  -variable => \$argument2,
  -choices  => [ "1", "2" ],
)->pack(qw/ -side right -padx 10 /);
 
$mw->Button(
  -text    => "lancer prog",
  -command => [ \&voiture, \$argument1, \$argument2 ],
)->pack();
 
$mw->Button(
  -text    => "List",
  -command => [ \&liste, ],
)->pack();
 
MainLoop;
 
sub voiture {
  my ( $Refargument1, $Refargument2 ) = @_;
  my ( $argument1, $argument2 ) = ( ${$Refargument1}, ${$Refargument2} );
  print "Argument 1 :  : $argument1\n" if ( defined $argument1 );
  print "Argument 2 :  : $argument2\n" if ( defined $argument2 );
  if ( defined $argument1 and defined $argument2 ) {
    system("voiture_v8.exe $argument1 $argument2");
  }
  else {
    warn "Les 2 arguments ne sont pas ok\n";
  }
  return;
}
sub liste {
 
     my $choix1="list.xls";
     my $argument1;
     my $cmd = getcwd;
        $cmd =~ s/\//\\/g;
     my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application');
        $Excel->{Visible} = 1;
     my $book = $Excel->Workbooks->Open("$cmd/$choix1") or die Win32::OLE->LastError;
 
     my $sheet    = $book -> Worksheets(1) -> {Name};
        $sheet    = $book -> Worksheets($sheet);
        $sheet                -> Activate;
        $sheet -> Range("A") -> {Value} = "$argument1";
 
   $book->Save();
   $Excel->Quit();
}; | 
Partager