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

Hello Monks,

Namaste(greetings) to All. I have a small problem. I have a code snippet that works in Perl, but don't when i call through UI cgi script.

pasting my code

my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application'); $Excel->{'Visible'} = 0; $Excel->{DisplayAlerts}=0; print " till this all fine"; my $Book = $Excel->Workbooks->Open("C:\\devtools\\one.xlsx"); print " control does not reach here";

Please help me to resolve the issue

Replies are listed 'Best First'.
Re: Help in OLE perl
by BrowserUk (Patriarch) on Apr 24, 2012 at 15:17 UTC

    Does the userid that your webserver runs under have permissions to access the file in devtools?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re: Help in OLE perl
by davies (Monsignor) on Apr 24, 2012 at 15:34 UTC

    While debugging, set the "Visible" and "DisplayAlerts" properties to 1 (true). This may give you information that will help you find the issue. But do remember to put them back afterwards. I would strongly advise against trying to take control of an existing instance of Excel, and have given some reasons in Re: Manipulating open excel sheet. What would happen if someone was using Excel and an external user accessed your web service? They would suddenly see their instance of Excel disappear as you make it invisible. Then they would be unable to open their files for writing in a new instance as they were already open in the (now invisible) instance your code has taken over.

    Regards,

    John Davies

Re: Help in OLE perl
by afoken (Chancellor) on Apr 24, 2012 at 17:48 UTC

    On Windows, the webserver service, like almost all other services, is usually not allowed to interact with the desktop (or, in case of Remote Desktop / Terminal Server, any of the remote desktops), and for good reasons. So any program you start from the webserver will hang as soon as it attempts to draw a window. Most likely, you won't be able to use OLE. Try one of the Excel parser modules at CPAN, or even better, put your data into a database.

    (Update: See also win32::ole and MS Office 2010 over cgi)

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)