Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Win32::OLE Examples?

by Flame (Deacon)
on Mar 20, 2002 at 20:12 UTC ( #153111=perlquestion: print w/ replies, xml ) Need Help??
Flame has asked for the wisdom of the Perl Monks concerning the following question:

Wow, I'm amazed, I entered 'OLE' into the search box and there is NOTHING out there?

First, can anyone explain in detail what OLE does? Someone mentioned it to me while I was working on a Win32::GUI application, and it caught my attention. Unfortunately, the description in the docs isn't all that helpful.

Second, does anyone know of any Win32::OLE examples that don't involve Excel? I'm hopeing I might get a better understanding of it if I can actually run the program...

Thanks



"Weird things happen, get used to it."

Flame ~ Lead Programmer: GMS

Comment on Win32::OLE Examples?
Re: Win32::OLE Examples?
by cacharbe (Curate) on Mar 20, 2002 at 20:30 UTC
    Definitions: Sure, I have plenty of OLE examples, what were you hoping to see?

    Word

    use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them my $Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit'); $Word->{'Visible'} = 1; $Word->Documents->Add || die("Unable to create document ", Win32::OLE- +>LastError()); my $MyRange = $Word->ActiveDocument->Content; my $mytxt = "Some Random Text"; # I'll fill this in later # add a table that is the header portion, 1 column by 1 row $Word->ActiveDocument->Tables->Add({ Range => $MyRange, NumRows => 1, NumColumns => 1, }); $Word->Selection->TypeText ({ Text => $mytxt}); $Word->Selection->MoveRight({Count => 1}); $Word->Selection->TypeText ({ Text => "A little more text"});

    PowerPoint

    use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft PowerPoint'; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them my $PptApp = Win32::OLE->GetActiveObject('PowerPoint.Application')|| +Win32::OLE->new('PowerPoint.Application', 'Quit'); $PptApp->{Visible} = 1; my $Presentation = $PptApp->Presentations->Add(); #my $Presentation = $PptApp->Presentations->Open({FileName=>'<SOMEFILE +NAME>',ReadOnly=>1}); my $Slide = $Presentation->Slides->Add({Index=>1 , Layout=>ppLayoutTex +t}); $Slide->{Name} = "Slide1"; my $TextBox=$Slide->Shapes->AddTextbox({Orientation=>1, Left=>5, Top=>5, Width=>250, Height=>250,}); $TextBox->TextFrame->TextRange->{Text} ="Big Ole Test"; my $Title=$Slide->Shapes->{Title}; $Title->TextFrame->TextRange->{Text} ="Title Test"; my $NewSlide = $Slide->Duplicate(); $NewSlide->{Name} = "Slide2";

    OutLook

    use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Outlook'; $|++; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them my $OL = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application', 'Quit'); my $NameSpace = $OL->GetNameSpace("MAPI"); my $Folder = $NameSpace->GetDefaultFolder(olFolderInbox); # map {print "Attachment Name: ". $_->Attachment(1)->{Name} ."\n";} +(in ($Folder->{Items})); foreach my $msg (in $Folder->{Items}){ foreach my $atch (in $msg->{Attachments}){ my $filename = "C:\\atchs\\" . $atch->{FileName}; #print $atch->{FileName} ." in message ". $msg->{Subject} . +"\n"; print $filename ."\n";#." in message ". $msg->{Subject} ."\ +n"; $atch->SaveAsFile($filename); } }
    I mean, really, what are you hoping to accomplish? Did you have a task in mind?

    You'll need to use an object browser, something like Active States html based one, or MS various tools.

    C-.

    Update: Added defn links

      Ok, I take it only microsoft products work with OLE?

      Do you have an example with WordPad or something free like that?

      Thanks



      "Weird things happen, get used to it."

      Flame ~ Lead Programmer: GMS

        The point is, OLE is a Microsoft "technology", so it's really the other way around. OLE only works on Micrsoft and Microsoft compliant software products. Technically, it works with certain applications and codebases that implement an interface named IDispatch.

        Unfortunately, from what I can see, Wordpad really has no interfaces derived from IDispatch, which means no OLE (someone please correct me if I'm wrong).

        I ask again, though, what are you thinking of doing? Perhaps there is another way around it that a few here could suggest.

        C-.

      Any one know how to link some text to a different slide?
Re: Win32::OLE Examples?
by traveler (Parson) on Mar 20, 2002 at 20:38 UTC
    OLE does lots of things. To grossly oversimplify, it allows applications to "talk to" each other. That is why you see Perl programs controlling Excel. In my Windows 2000, I typed OLE into help's window and got a good explanation.

    This is a discussion of OLE to control PowerPoint. I have used it to control MS Word, too. The key, as the aformentioned thread points out is to understand the Object Model for the object you wish to manipulate (e.g. Word Doc, PPT presentation, etc.). This is often easier said than done. There are documents supplied with Active State perl to help. Some third-parties (e.g. this or this) also provide tools to help you browse objects. You can also check your local tech bookstore for books on the object models.

    HTH, --traveler

Re: Win32::OLE Examples?
by buckaduck (Chaplain) on Mar 21, 2002 at 13:16 UTC
    Here is an example program I wrote using OLE to control Lotus Notes under Windows.

    buckaduck

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://153111]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-07-31 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (253 votes), past polls