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

I am using Excel 2007 on a windows XP PC. Typically I just use the following at the beginning of Perl where I am reading and/or writing Excel spreadsheets.
use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel';
In the O’Reilly Excel Macros by Steven Roman there are given a number of lists of constants which all start with
Enum property name
with the constant name and values underneath
For example, the first three for XLFileFormat are given as
xlAddIn = 18
xlCSV = 6
xlCSVMac = 22
It would be very helpful to be able to write out these lists.

‘John’ replied to an earlier request of mine with the Perl code of
use strict; use Win32::OLE; use Win32::OLE::Const; my $xl = Win32::OLE::Const->Load("Microsoft Excel"); printf "Excel type library contains %d constants:\n", scalar keys %$xl +; foreach my $Key (sort keys %$xl) { print "$Key = $xl->{$Key}\n"; }
This does seem to give all the values of the constants that I am looking for. However, it does not associate these with any property
Is there any way that Perl can be used to write out these lists so that I can tell with which property they can be used with?
For me it would be perfectly acceptable to have a whole of statements like
Enum(‘XLFileFormat');

Replies are listed 'Best First'.
Re: Excel enum lists
by dasgar (Priest) on Mar 07, 2011 at 19:00 UTC

    Since you're on a Windows box and are already using Win32::OLE, you already have a tool that will give tons of information about Excel and Office data types and constants. The Win32::OLE includes an OLE "browser". It shows all kinds of information, but it's based in VB. If you got the process down of converting macros (recorded in VB) to Perl, you should be able to "convert" the information you find from the OLE browser into Perl code for whatever your developing.

    An alternative approach is to not even worry about what are the values of the constants are. I usually add use Win32::OLE::Const "Microsoft Excel .* Object Library"; and use Win32::OLE::Const "Microsoft Word .* Object Library"; to my code, which allows me to directly use the Excel and Office constants without having to decode what their value is.

Re: Excel enum lists
by ww (Archbishop) on Mar 07, 2011 at 18:38 UTC
Re: Excel enum lists
by planetscape (Chancellor) on Mar 09, 2011 at 01:01 UTC