Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Win32:OLE errors when running same code on Windows XP

by HelenCr (Monk)
on Aug 09, 2012 at 18:34 UTC ( [id://986581]=perlquestion: print w/replies, xml ) Need Help??

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

Dear wise PerlMonks

I need your help on the following Perl + Win32::OLE + Excel problem:

I have been working on a project on a Windows 7 system, using StrawberryPerl v 5.014 and Win32::OLE. (Running under Eclipse and EPIC). There, the program runs with no errors.

I am trying to use a second PC running Windows XP SP3, to have the same project developed in parallel. On the new system, I have installed Strawberry Perl v 5.016, and used cpanp to install Win32::OLE. I am using the same script sources in the new system.

It turns out that in the new system, I get Win32::OLE errors once I call Microsoft Excel API's. It pops up once I call:

$xlApp = Win32::OLE->new('Excel.Application');

It emits an entire cascade of Win32::OLE errors, just for that one statement. (see below).

Here are exceprts from my Perl code:

package StatementExcel; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(LoadExcel ProcessPreparedSheet); use strict; use warnings; use Encode; use 5.014; use utf8; use Win32::Console; use autodie; use warnings qw< FATAL utf8 >; use Carp; use Win32::OLE qw(CP_UTF8); use Win32::OLE::Const 'Microsoft Excel'; use Cwd; use Text::CSV::Unicode; use File::BOM qw( :all ); use List::MoreUtils 'first_index'; sub LoadExcel { Win32::OLE->Option(CP => CP_UTF8); # set utf8 encoding binmode(STDOUT, ':unix:utf8'); binmode $DB::OUT, ':unix:utf8' if $DB::OUT; # for the debugger Win32::Console::OutputCP(65001); # Set the console code pa +ge to UTF8 my ($i,$j,$StatementRef); my ($xlApp, $xlBook, $Sheet, $rng, $tbl, $xlFile, $RowRecStart, # line where statement records will start $ColRecStart, # column where statement records will sta +rt $StatementRows, # number of statement rows $HeadingRange, $RecordsRange); my (@Statement, @Heading); my @columns = ('a'..'z'); $Win32::OLE::Warn = 2; my %parms = @_; # ... more code $xlApp = Win32::OLE->new('Excel.Application'); # Start Excel an +d make it visible # ... more code

and here are excerpts from the error dump. Like I said, this entire dump was output just for that single OLE statement:

Win32::OLE(0.1709) error 0x80020009: "Exception occurred" in METHOD/PROPERTYGET "ActiveChart" at D:/MyPrograms/System/Strawb +erryPerl/perl/vendor/lib/Win32/OLE/Lite.pm line 216. ... called at D:/My Documents/Technical/Perl/Eclipse workspace/.metada +ta/.plugins/org.epic.debug/perl5db.pl line 646 DB::eval called at D:/My Documents/Technical/Perl/Eclipse workspac +e/.metadata/.plugins/org.epic.debug/perl5db.pl line 3244 DB::DB called at D:/My Documents/Technical/Perl/Eclipse workspace/ +StatementExcel.pm line 87 StatementExcel::LoadExcel('StatementRef', 'ARRAY(0x1c72e0c)', 'Fil +esRef', 'HASH(0x1c7d80c)', 'Debug', 1, 'XLFileName', 'D:\My Documents +\Technical\Perl\Eclipse workspace\FIBI\Work\FI...', 'OutpStructRef', +...) called at D:/MyPrograms/System/StrawberryPerl/perl/vendor/lib/Wi +n32/OLE/Lite.pm line 216. ... Win32::OLE(0.1709) error 0x80020009: "Exception occurred" in METHOD/PROPERTYGET "Charts" at D:/MyPrograms/System/StrawberryP +erl/perl/vendor/lib/Win32/OLE/Lite.pm line 216. ... DB::eval called at D:/My Documents/Technical/Perl/Eclipse workspac +e/.metadata/.plugins/org.epic.debug/perl5db.pl line 3244 DB::DB called at D:/My Documents/Technical/Perl/Eclipse workspace/ +FIBI/StatementExcel.pm line 87 StatementExcel::LoadExcel('StatementRef', 'ARRAY(0x1c72e0c)', 'Fil +esRef', 'HASH(0x1c7d80c)', 'Debug', 1, 'XLFileName', 'D:\My Documents +\Technical\Perl\Eclipse workspace\FIBI\Work\FI...', 'OutpStructRef', +...) called at D:/My Documents/Technical/Perl/Eclipse workspace/FIBI/ +FIBI Conv.pl line 121 ... Win32::OLE(0.1709) error 0x80020009: "Exception occurred" in METHOD/PROPERTYGET "Excel4IntlMacroSheets" at D:/MyPrograms/Sys +tem/StrawberryPerl/perl/vendor/lib/Win32/OLE/Lite.pm line 216. ... Win32::OLE(0.1709) error 0x80020009: "Exception occurred" in METHOD/PROPERTYGET "Excel4MacroSheets" at D:/MyPrograms/System/ +StrawberryPerl/perl/vendor/lib/Win32/OLE/Lite.pm line 216. eval {...} called at D:/MyPrograms/System/StrawberryPerl/perl/vend +or/lib/Win32/OLE/Lite.pm line 216 Win32::OLE::Tie::FETCH('Win32::OLE::Tie=HASH(0x25ee6ec)', 'Excel4M +acroSheets') called at D:/My Documents/Technical/Perl/Eclipse workspa +ce/.metadata/.plugins/org.epic.debug/dumpvar_epic.pm line 162 ... Win32::OLE(0.1709) error 0x80020009: "Exception occurred" in METHOD/PROPERTYGET "FileFind" at D:/MyPrograms/System/Strawberr +yPerl/perl/vendor/lib/Win32/OLE/Lite.pm line 216. ...

What to do?

Many TIA

Helen

Replies are listed 'Best First'.
Re: Win32:OLE errors when running same code on Windows XP
by bulk88 (Priest) on Aug 10, 2012 at 05:30 UTC
    I have had bad experiences with tied/magic scalar and using a Perl debugger. The watch window in the debugger will cause every tied variable to have its value regenerated on every step. According to your error messages, the debugger tried to read a tied variable and the method behind the fetch failed because the Win32::OLE call failed.

    Tied magic being called on every debugger step became so painful I coded in caller checks into the tied implementation methods to return undef if the caller didn't start with "main::". Try running your script without a debugger.

      bulk88: sounds quite right. I will try it and report.

      Meanwhile, can you explain a couple of questions:

      1. What is a tied/magic scalar, and how is it involved here?

      2. Why don't I get this "deluge" of OLE exceptions at the original installation on the Windows 7 system?

      Many TIA

      Helen

        Some tiny settings difference in Eclipse I bet. Maybe a "+" is open on 1 machine and not the other.
        * - Package Win32::OLE::Tie Implements properties as tied hash
        From Win32::OLE.
        Object methods and properties The object returned by the new() method can be used to invoke methods +or retrieve properties in the same fashion as described in the docume +ntation for the particular OLE class (eg. Microsoft Excel documentati +on describes the object hierarchy along with the properties and metho +ds exposed for OLE access). Optional parameters on method calls can be omitted by using undef as a + placeholder. A better way is to use named arguments, as the order of + optional parameters may change in later versions of the OLE server a +pplication. Named parameters can be specified in a reference to a has +h as the last parameter to a method call. Properties can be retrieved or set using hash syntax, while methods ca +n be invoked with the usual perl method call syntax. The keys and eac +h functions can be used to enumerate an object's properties. Beware t +hat a property is not always writable or even readable (sometimes rai +sing exceptions when read while being undefined). If a method or property returns an embedded OLE object, method and pro +perty access can be chained as shown in the examples below.
        Your answer is in the quote above. More specifically, a little bit of googling leads to this http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._application.activechart. I dont know what "Nothing" translates to in Win32::OLE.
Re: Win32:OLE errors when running same code on Windows XP
by davies (Prior) on Aug 09, 2012 at 19:49 UTC

    Your code doesn't run. I made it run by removing the subroutine declaration and it ran with no errors. I'm on Perl 5.12, so I had to change that line, and SP2. I suspect the problem is in the code you haven't quoted. I see references in your errors to "Lite.pm line 216", which may or may not be among the lines you have given us, but it doesn't matter as the actual call may involve some parameters which aren't mentioned in the code you give us.

    Please try to cut your code down to the absolute minimum that demonstrates the problem (is "use 5.014" really necessary, for example? Strict & Warnings certainly are, but you have a lot of modules that I can't see being used in the given code) and check that it gives an error message on your machine. Then we will have a better chance of helping you.

    Regards,

    John Davies

Re: Win32:OLE errors when running same code on Windows XP
by Anonymous Monk on Aug 10, 2012 at 00:12 UTC

    Hi,

    If the directoy trees of the old and new boxes match, and if the programs in the direcotries are all the same, I would assume there is a problem with the setup of the new Perl.

    I would try re-installing the Win32::ole stuff looking for any error. If that doesn't help, try installing Perl 5.14 to try and match your old setup exactly.

    If it still doesn't work, do it all again until it does.

    J.C.

      Indeed when I've installed Win32::OLE I noticed some complaints that a few modules couldn't be installed, since Win32::OLE needs Visual C compiler, and StrawberryPerl has gcc.

      But I noticed the same warnings when I had installed the original system on the Windows 7 system, and there there are no problems. Those modules are not mainstream anyway.

        I just double-checked Strawberry Perl's web site. According the release notes, versions 5.14.2.1 and 5.16.0.1 (in both 32-bit and 64-bit) already include Win32::OLE. As a further check, I downloaded the portable versions and they all have Win32::OLE.

        Also, the latest version of Win32::OLE was released in 2008. That means versions 5.14.2.1 and 5.16.0.1 of Strawberry Perl would have the latest version of the module.

        Based on that information, is there a reason that you're trying to reinstall Win32::OLE in your Strawberry Perl installations?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-03-19 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found