thmsdrew has asked for the wisdom of the Perl Monks concerning the following question:

I've been using Win32::OLE to clean up some data in a spreadsheet. Usually involves a loop that iterates over every row, modifying certain rows in certain ways.

At one point I ran into a situation where, on one of the iterations of my loop, my code erred, and my script stopped without getting to the $book->Close; $excel->Quit; part at the end.

Is there a way that I can always Close and Quit no matter what? I could put an or die after each bit of code that might fail, but that seems kind of inelegant.

  • Comment on Win32::OLE Excel: Close and Quit no matter what happens

Replies are listed 'Best First'.
Re: Win32::OLE Excel: Close and Quit no matter what happens
by Corion (Patriarch) on Aug 06, 2014 at 15:09 UTC

    Searching the Win32::OLE documentation for ->Quit shows the following example:

    $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Qui +t;}) or die "Oops, cannot start Excel";

    It seems to me that the optional destructor argument (as documented in Win32::OLE) will do what you want.

      Perfect. Thanks!