OLE & Excel - Opening causes Excel.exe to hang around

Discussion in 'Perl Misc' started by TimmyD, Apr 21, 2005.

  1. TimmyD

    TimmyD Guest

    This is a very simple script (proof of concept) that simply either
    opens an Excel workbook or creates a new one. When I run this script
    (with -w of course:) with the Add line uncommented, EXCEL.EXE starts
    when the application object is created and closes when the script is
    done. However, when I run it with the Open line uncommented, EXCEL.EXE
    stays running (in process list) once the script is done. The only way
    to get rid of it is to kill it in the Task Manager. Has anyone out
    there had this same problem and knows what I'm doing wrong? BTW: I'm
    using ActiveState perl v5.8.4

    <START CODE>
    use Win32::Ole qw(in with);
    use strict;
    use Cwd;

    do_it();

    sub do_it() {
    my $Excel = "";
    my $Book = "";
    my $key = "";
    my $Sheet = "";
    my $current_path = "";
    my $full_path_and_filename = "";
    my $filename = "";
    my @UserStatArray = ();

    print "Doing it...\n";
    $Excel = Win32::OLE->new( 'Excel.Application',sub { $_[0]->Quit; } )
    or die_nice("Couldn't start Excel to read DTC Spreadsheet!");
    $current_path = getcwd;
    $filename = "blah.xls";
    $full_path_and_filename = $current_path.'/'.$filename;

    #If the line below (Open) is used, EXCEL.EXE
    #stays running (in process list) after the script exits.
    #$Book = $Excel->Workbooks->Open($full_path_and_filename,0,1);
    #If the line below (Add) is used, EXCEL.EXE
    #terminates when the script exits.
    $Book = $Excel->Workbooks->Add;

    $Sheet = $Book->Worksheets(1);
    sleep(1);
    $Excel->ActiveWorkbook->Close(0);
    $Excel->Quit;
    undef $Sheet;
    undef $Book;
    undef $Excel;
    }
    <END CODE>
    TimmyD, Apr 21, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jesse Cates via DotNetMonster.com

    Process.Start is causes application to hang

    Jesse Cates via DotNetMonster.com, Jan 28, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    3,543
    Steve C. Orr [MVP, MCSD]
    Jan 31, 2005
  2. Nishi Bhonsle
    Replies:
    2
    Views:
    23,565
    pahujadeepanshu
    Nov 30, 2009
  3. Earl Eiland
    Replies:
    1
    Views:
    465
    Dennis Lee Bieber
    Mar 19, 2005
  4. Jeff Epler
    Replies:
    0
    Views:
    364
    Jeff Epler
    Mar 19, 2005
  5. fniles
    Replies:
    0
    Views:
    268
    fniles
    Apr 26, 2009
Loading...

Share This Page