Hi Monks
I am having trouble with OLE and inserting pictures into a word document. The problem lies in getting a picture into the document after a page break. The pictures insert easily onto the first page but I cannot get them onto the second page - probably due to my lack of knowledge in Object programming. I have also used code I have found on the web and do not claim to be the author of most of it ;-)
here is my code:
use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Win32::OLE::Variant; my $cur_style = 'a'; my $cur_bookmark = 'a'; my $word = CreateObject Win32::OLE 'Word.Application' or die $!; $word->{'Visible'} = 1; my $document = $word->Documents->Add; my $selection = $word->Selection; text ($document, "Page 1"); enter ($document); my $picture = insert_picture($document, 'C:\dee-dwive\pic1.jpg', 0, 1, + 0, 250); enter ($document); $selection ->InsertBreak(wdPageBreak); enter ($document); text ($document, "Page 2"); enter ($document); $picture = insert_picture($document, 'C:\dee-dwive\pic2.jpg', 0, 1, 0, + 250); enter ($document); save_doc_as($document, 'C:\dee-dwive\picture.doc'); #close_doc($document); #$word->Quit; sub text { my $document = shift; my $text = shift; $document->ActiveWindow->Selection -> TypeText($text); } sub enter { my $document = shift; $document->ActiveWindow->Selection -> TypeParagraph; } sub insert_picture { my $document = shift; my $file = shift; my $left = shift; my $top = shift; my $width = shift; my $height = shift; my $picture = $document-> Shapes -> AddPicture ( $file, $left, $top, $width, $height, ); return $picture; } sub insert_page_break { my $document = shift; $document->ActiveWindow->Selection->{Range} -> InsertBreak(wdPageBre +ak); }
Thanks for your helpful advice in advance
2006-05-05 Retitled by GrandFather, as per Monastery guidelines
Original title: 'OLE Problem'
In reply to MS word insert picture again by Secode
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |