Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

win32::ole and MS Office 2010 over cgi

by wal77 (Novice)
on Feb 04, 2012 at 15:57 UTC ( #951817=perlquestion: print w/ replies, xml ) Need Help??
wal77 has asked for the wisdom of the Perl Monks concerning the following question:

We have a web application runnung on Windows Server 2003, Apache and MS Office 2003. Win32::Ole generates word documents initiated over a CGI form. All works pretty. Now I have to install a new server based on Windows Server 2008 R2 Standard with Office 2010.

Apache runs as priveleged user, but the script hangs on $word = Win32::OLE->new('Word.Application', sub {$_[0]->Quit;} till browser timeout message coming, no errors in perl($Win32::OLE::Warn = 3;), Apache or Windows. Seems to be Word waiting for a confirmation, but I can't see it ({visible} = 1).

use Win32::OLE; $Win32::OLE::Warn = 3; eval {$word = Win32::OLE->GetActiveObject('Word.Application')}; die "Word not installed" if $@; unless (defined $word) { $word = Win32::OLE->new('Word.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Word"; } $word->Activate; $word->{visible} = 1; my $doc = $word->Documents->Open("$oldfile"); ....... $word->ActiveDocument->SaveAs($newfile); $doc->Close(); $word -> Quit;

Can you halp me? Regards, wal77

Comment on win32::ole and MS Office 2010 over cgi
Download Code
Re: win32::ole and MS Office 2010 over cgi
by Anonymous Monk on Feb 04, 2012 at 16:00 UTC
    Use absolute paths?
      Yes, but I don't get so far. If I comment out the rest, the Method "new" hangs as well
Re: win32::ole and MS Office 2010 over cgi
by afoken (Parson) on Feb 04, 2012 at 19:10 UTC

    Usually, Apache runs as service, and services are not allowed to interact with any desktop, neither console nor remote. So, the Word executable may start, but it won't be able to open a window, Windows actively prevents this. No window, no communication, no OLE. That are Windows' rules.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      But it works with Windows Server 2003 and Office 2003

        But it works with Windows Server 2003 and Office 2003

        Microsoft actively improves windows and office, check the changes files on msdn

        I'm not familiar with Server 2008 OR Office 2010...buuut...you might check a couple of things. First, if you installed Office with VBA, check the docs for changes. Running Office from VBA should be almost identical from running it via Perl and OLE, but for some syntax changes. You probably know that a quickstart to automating a task in Office is creating a VBA macro, and then translating it to Perl. Anyway, another possibility is that it's not Word.Application anymore. It's only a shot in the dark, but I hope it helps.

        --marmot

Re: win32::ole and MS Office 2010 over cgi
by kenearle (Novice) on Mar 18, 2012 at 15:15 UTC

    This might be too late and not address your problem, but I have had similar troubles moving from Word 2003 to 2010, in particular your code example flunks for me too. After some anguish I recorded a macro to open a file with Word 2010 - and there was one big difference from 2003. Seems Word 2010 wants to see just a file name proper in the Open(), with a change of working directory beforehand. Doing that works for me. Here's a crude example you might try, note I've assumed a full path for $oldfile with forward slashes only:

    use Win32::OLE; $Win32::OLE::Warn = 3; eval {$word = Win32::OLE->GetActiveObject('Word.Application')}; die "Word not installed" if $@; unless (defined $word) { $word = Win32::OLE->new('Word.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Word"; } $word->Activate; $word->{visible} = 1; $oldfile =~ m!^(.+?)/([^/]+)$!; my $dir = $1 . '/'; my $name = $2; $word->ChangeFileOpenDirectory($dir); my $doc = $word->Documents->Open("$name"); ...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://951817]
Approved by davies
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (14)
As of 2014-09-23 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (231 votes), past polls