XP is just a number | |
PerlMonks |
Re^3: How to run an Excel Macro in Perl?by WoodyWeaver (Monk) |
on Jan 14, 2008 at 23:08 UTC ( [id://662399]=note: print w/replies, xml ) | Need Help?? |
Its not that bad, whakka. I think he is trying, and I'll help him get started. The way to convert your macro into perl is to use the perl excel instance you've created, and convert the VBScript references to object oriented function calls. Staring at the object browser (I'm not on a box that has excel on it right now, but its something like Tools/Macro/VBEditor then View/ObjectBrowser) to understand what the calls are doing and what they mean is very helpful. Adding perl print statements mixed between the Excel statements is also helpful. You've set up my $Sheet = $Book->Worksheets(1); -- this is the first worksheet. You can now start manipulating it. For example, the first thing you do is to select a range of rows. If you look in the object browser, you will find that class "Worksheet" has property "Rows" as a range object. So, you can pick up that range as a perlish object as my $range = $Sheet->Rows("1:13"); The macro then selects that range $range->Select; -- but that might not be what you want. If you look in the browser, class Range has a lot of properties you can invoke -- and since you are selecting only to insert, you can do that directly. The object browser describes Okay, not the greatest of doc, but given that xlDown is -4121 and that xlFormatFromLeftOrAbove is 0 (look them up in the object browser) your code becomes $range->Insert(-4121,0); or, since you didn't really need that range for anything else, And so on. Now you can put in a print statement that says you did that line successfully. Even better, you can introduce a $Book->Save; so that after the train jumps the tracks, you can at least see if the spreadsheet looked like you expected up to that point. By breaking out of the "load file, execute canned macro" you can gain a lot of leverage from perl. Sure, you can still have lines like which is nice, because it saves some tedium, but you can also do things like But ultimately, yeah, its hit the documentation to see how others have done it and what patterns to follow. --woody
In Section
Seekers of Perl Wisdom
|
|