Good day bros. I need to create a script to take multiple word documents and combine them into one. I've done a little Word automation for accessing text but never for writing it. I have looked at nodes here like
this one about writing stuff to Word, but what I want to do it take the text unmodified with formatting etc. from a source file and add it to the end of a destination file using code like:
#!/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";
my $outputdoc = $word->Documents->Add;
my @inputdocs = qw( foo.doc bar.doc);
foreach my $f (@inputdocs) {
my $inputdoc = $word->Documents->Open({FileName => "c:\\$f"});
my $inputparagraphs = $inputdoc->Paragraphs;
foreach my $par (@$inputparagraphs) {
#how to add to end of $outputdoc?
}
$inputdoc->close;
}
$outputdoc->SaveAs({FileName => 'c:\\combined.doc'});
So I guess my question is, is there a way to take a paragraph from the source doc and push it (with original formatting) onto the end of the paragraphs of the destination doc? The VBA reference for Word shows that there is a Paragraphs.Add method, but it seems that just adds a paragraph without putting anything in it. Any pointers appreciated.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.