If I may be permitted a small rant: What kind of twisted mind came up with this Office object model? It is the Rube Goldberg Device of object models. Six steps to insert a heading. REALLY? It took me forever to figure out that you make a selection in the document, but then the selection belongs to to system, not that document. Geez.
#!/usr/bin/perl -w use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $word = Win32::OLE->new('Word.Application') or die "Failure - word. + \n"; $word->{'Visible'} = 1; my $outputdoc = $word->Documents->Add; my @inputdocs = qw( foo.doc bar.doc); foreach my $f (@inputdocs) { my $ip = $outputdoc->Range({Start=>$outputdoc->Content->End -1,End +=>$outputdoc->Content->End -1}); $ip->Select(); my $selection = $word->Selection; $selection->TypeText($f); $selection->{'Style'} = "Heading 2"; $selection->TypeParagraph; my $inputdoc = $word->Documents->Open({FileName => "c:\\temp\\work +\\$f"}); my $inputparagraphs = $inputdoc->Paragraphs; my $nparagraphs = $inputdoc->Paragraphs->Count; for my $i (1..$nparagraphs) { $inputdoc->Paragraphs($i)->Range->Copy; my $outrange = $outputdoc->Range({Start=>$outputdoc->Content-> +End -1,End=>$outputdoc->Content->End -1}); $outrange->Paste; } $inputdoc->close; my $outputend = $outputdoc->Range({Start=>$outputdoc->Content->End + -1,End=>$outputdoc->Content->End -1}); $outputend->InsertBreak(); } $outputdoc->SaveAs({FileName => 'c:\\temp\\work\\combined.doc'});
In reply to Re^2: Win32 OLE Word combining docs
by cormanaz
in thread Win32 OLE Word combining docs
by cormanaz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |