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 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 #vbRedIt 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
In Section
Seekers of Perl Wisdom
|
|