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

I'm using Win32::OLE in perl : $xl = Win32::OLE::Const->Load('Microsoft Excel'); then I test if scalar(keys %{$xl}) is zero :
if (scalar(keys %{$xl})==0) { return False; } else { return True; }
I tested this code in machine which supports Microsoft Excel 2003 it gives True, but when I tested the same code in machine where there is Microsoft Excel 2013 it gives me False! I also printed the scalar(keys %{$xl} in the first machine it gives 2023, in the second machine it is 0! Best Regards

Replies are listed 'Best First'.
Re: Does Win32::OLE::Const->Load('Microsoft Excel'); depends upon Excel version
by poj (Abbot) on Mar 20, 2020 at 15:59 UTC
    If you run this code
    use strict; use Win32::OLE::Const; Win32::OLE::Const->EnumTypeLibs(\&mylib);; sub mylib { return unless $_[1] =~ /Excel/; print join " ",$_[1],$_[4],"\n"; }

    you should get a result like this (14.0 is 2010 , it would probably be 15.0 for 2013)

    Microsoft Excel 14.0 Object Library C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE
    
    try using the full version name you have in the load eg ->Load('Microsoft Excel 14.0 Object Library');
    poj
Re: Does Win32::OLE::Const->Load('Microsoft Excel'); depends upon Excel version
by syphilis (Archbishop) on Mar 19, 2020 at 23:39 UTC
    Hi agnes00,

    The example in the Win32::OLE documentation seems to be trying to load Excel as:
    $xl = Win32::OLE->new('Excel.Application') or die "oops\n";
    You could try that and see if it makes a difference.

    Did the test suite pass when you installed Win32::OLE ?
    If you installed it via ppm, then you won't have run the test suite.
    In that case grab the Win32::OLE source, unpack it to some location, cd to that location, and run:
    perl t/2_variant.t perl t/3_ole.t
    Let us know if they both pass. Please provide a copy'n'paste of the results if there are failures.
    (Those 2 test files seem to rely on the loadability of Excel, and are therefore relevant to your issue.)

    Other than that, try looking through the Win32:OLE bug reports and see if there's anything there that helps.
    Nothing there stands out to me, though 67609 might perhaps be relevant.

    I don't know much about Win32::OLE - I don't have it, nor do I have Excel. And I doubt that Win32::OLE is being actively maintained. (The current version on CPAN is 6 years old.)

    There's also a number of modules that have been written for Excel. Perhaps one of them might better suit your purposes - I don't know.
    You can see a list of those modules at https://metacpan.org/search?q=Excel.

    Cheers,
    Rob
Re: Does Win32::OLE::Const->Load('Microsoft Excel'); depends upon Excel version
by Anonymous Monk on Mar 20, 2020 at 23:14 UTC