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(wdPageBreak);
}
Thanks for your helpful advice in advance
2006-05-05 Retitled by [GrandFather], as per Monastery [id://341118|guidelines]
Original title: 'OLE Problem'
Reread better on what I wrote to you at Re: MS word insert picture, or wait for my English to improve and then ask again...
$picture = insert_picture($document, 'C:\dee-dwive\pic2.jpg', 0, 1, 0, 500);
Hi - Sorry vkon I don't have enough knowedge to understand what you are
showing me which could fustrate you ;-( Martin - the pictures insert them selves
ontop of each other instead of the second picture landing on the second page at
the same position as the 1st picture on page 1 - no matter what I set the value
to it does not move beyond the 1st page.
Thanks for your comments
perlmonks.org content © perlmonks.org and marto, Secode, vkon
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03