Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to use win32::OLE with multiple versions of Microsoft Office?

by davies (Prior)
on Aug 03, 2011 at 20:59 UTC ( [id://918391]=note: print w/replies, xml ) Need Help??


in reply to How to use win32::OLE with multiple versions of Microsoft Office?

In Re^2: Finding out Excel 'variables', I reproduced ActiveState's code for listing Excel's constants and values. I think it would be relatively simple to adapt this to other libraries. I would therefore start thinking along the following lines:

Which constants vary from one version to the next? My first guess would be "None", meaning that each later version is likely to be a superset of the previous one.

If any constant does in fact vary, how would I know which to use? If you have or can get (not all that difficult in Excel) the version number, you might try creating your own hash of hashes containing all the constants, so that you would have a key, say xlVisible, and a hashref giving you the constant values for each version of the library that you have available. This means a large data structure, so my next thought would be to isolate the constants that are actually used. Again, if they are all the same, just use the latest version.

Another option is not to use constants at all, but magic numbers. This isn't ideal, but sometimes it's the least work, especially if the constant isn't in the library. So, when writing Perl to control Excel, I frequently write something like:

$object->Color = 255 #vbRed

It would be simple to take this farther and write ones own constants if the magic number were to be used more than once.

Regards,

John Davies

Update: Dasgar's reply, written while I was writing mine, looks much better at first sight.

Update 2: fixed minor typo

Replies are listed 'Best First'.
Re^2: How to use win32::OLE with multiple versions of Microsoft Office?
by frida (Initiate) on Aug 04, 2011 at 15:32 UTC
    I agree with John Davies, but the situation here is that the same perl script should run on several different servers. Each server has a particular Windows OS and a particular Office version; I would like to obtain mso constants without hardcoding of any kind. I can figure out various ways to do this, but they all are "not the right (PerlMonk) way". Thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://918391]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found