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

Hi,

I'm using the Win32::OLE module to create a new workbook. I'm importing a csv file, creating a new workbook, copying the relevant data from the csv file to the new workbook, adding a chart to the new workbook, saving the new workbook, and then attempting to close the workbooks and Quit the Excel Application instance. If I run it from DOS everything looks fine but running it from a CGI application the Excel.exe process sticks around. After creating a bunch of charts (i.e. multiple calls to this Excel creation module I have) I have to start clearing the Excel.exe processes from the host machine. Can anyone tell me how to terminate Excel after finished with it within the module I have? I try and use the object holding the reference to the Excel Application (I use GetActiveObject by the way) and then try calling the Quit() method but it doesn't seem to be working in the CGI app as opposed to executing from DOS. Any help would be greatly appreciated. Thanks.

RP

Replies are listed 'Best First'.
Re: Excel exe still hanging 'round
by TedYoung (Deacon) on Jan 09, 2006 at 20:32 UTC

    I had a problem with this once, though it was in a comand line env. I know you specifically mention your current solution works fine on the comand line, but try it anyway... it can't hurt. What I had to do was call:

    Win32::OLE->Uninitialize

    at the very end. Depending on how your CGI is set up, it may be easiest for you to do this:

    END { Win32::OLE->Uninitialize }

    Good luck!

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
      Thanks Ted. Seems like it done the trick. Quick question though: By calling the Win32::OLE->Uninitialize does that or will it affect other simultaneous Excel processes running by other users on that machine? I'll see what I can find but what does the Uninitialize do (i.e. deletions, clears, etc..,)? Thanks so much for the reply. I had noticed some methods listed (including this one) but it wasn't near the top of methods I was going to try so thanks for saving me the trouble.

      Rob

        I strongly suspect it is mearly a call to the function CoUninitialize(); which uninits COM for the current thread. So, it should not effect other CGI processes.

        Ted Young

        ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
Re: Excel exe still hanging 'round
by marto (Cardinal) on Jan 09, 2006 at 20:22 UTC
    Hi Anonymous Monk,

    Perhaps if you posted the code you were using we would be in a better position to offer advice.

    Martin