I apologize - I seem pretty brain dead this weekend - I didn't get all that
script pasted into that e-mail, here is the full script:

#! Perl

use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Word';
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;

my $wd = Win32::OLE->GetActiveObject('Word.Application')
    || Win32::OLE->new('Word.Application', 'Quit');  # get already active
Word
$wd->{Visible} = 1;
my $xl = Win32::OLE->GetActiveObject('Excel.Application')
    || Win32::OLE->new('Excel.Application', 'Quit');  # get already active
Word
$xl->{Visible} = 1;
# create a new word document in the object:
my $doc = $wd->Documents->Add();

# create a new workbook in the excel object:

my $book = $xl->Workbooks->Add();
my $sheet = $book->Worksheets(1);

foreach (1..10) {
                $sheet->Range("B$_")->{Value} = 12 * $_;
}
$sheet->Columns('A')->{Columnwidth} = 12;
$sheet->Columns('B')->{Columnwidth} = 8;
$sheet->Range('A11')->{Value} = 'Total';
$sheet->Range('B11')->{Formula} = '=sum(B1:B10)';

# Put the current position on the last word:

$doc->Words->Last->Select();

#insert text at the end of the doc:

$wd->Selection->InsertAfter("Our inserted table:\n");

# copy the selection from excel:

$sheet->Range("A1:B11")->Select();
$sheet->Range("A1:B11")->Copy();

#paste into the word doc:

$doc->Words->Last->Select();
$wd->Selection->Paste();
$doc->Words->Last->Select();
$wd->Selection->InsertAfter("End of our document\n");

# create another page:
$doc->Words->Last->Select();
$wd->Selection->InsertAfter("\f");



-----Original Message-----
From: Steve Howard [mailto:[EMAIL PROTECTED]]
Sent: Sunday, February 03, 2002 3:48 PM
To: Guru^garzaH
Subject: RE: Word documents


To put info into word (your ultimate goal), you need Win32::OLE. You can do
anything in Word using Win32::OLE that you can using VB in word. Doing that
is a pretty broad topic, and there is not much documentation on doing that
with Perl - you need to learn from the VB stuff, and learn how it translates
to Perl - the methods and objects are all the same, but you need different
notation to access them. The "Learning Perl on Win32" book from O'reilly has
a chapter devoted to using the Win32::OLE module. For a reference on
classes, methods, properties, and constant values, open Word, click the
Tools menu, then Macro>Visual Basic Editor. On the VB editor bar, there is
an "Object Browser" icon - it is the best reference on what is actually
there.

A very quick example of opening a word doc, and an excel doc, putting a few
lines in the word doc, and then creating a quick table in the excel doc and
pasting it into the word doc is here - this is just something I was playing
with when I was first learning to use OLE with Perl. It should serve as a
starting point for putting info into Word since it has some basic methods
that are not well documented - but don't think this is anywhere near all
there is that can be done, however if this is the direction you are going,
learn to read the VB docs, and translate to Perl, that is explained in the
"Learning Perl on Win32" book, chapter 19. Anyway, here is the promised
exmple:


#! Perl

use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Word';
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;

my $wd = Win32::OLE->GetActiveObject('Word.Application')
    || Win32::OLE->new('Word.Application', 'Quit');  # get already active
Word
$wd->{Visible} = 1;
my $xl = Win32::OLE->GetActiveObject('Excel.Application')
    || Win32::OLE->new('Excel.Application', 'Quit');  # get already active
Word
$xl->{Visible} = 1;
# create a new word document in the object:
my $doc = $wd->Documents->Add();

# create a new workbook in the excel object:

my $book = $xl->Workbooks->Add();
my $sheet = $book->Worksheets(1);

foreach (1..10) {
                $sheet->Range("B$_")->{Value} = 12 * $_;
}
$sheet->Columns('A')->{Columnwidth} = 12;
$sheet->Columns('B')->{Columnwidth} = 8;
$sheet->Range('A11')->{Value} = 'Total';
$sheet->Range('B11')->{Formula} = '=sum(B1:B10)';

# Put the current position on the last word:

$doc->Words->Last->Select();

#insert text at the end of the doc:

$wd->Selection->InsertAfter("Our inserted table:\n");

# copy the selection from excel:


-----Original Message-----
From: Guru^garzaH [mailto:[EMAIL PROTECTED]]
Sent: Sunday, February 03, 2002 2:16 PM
To: [EMAIL PROTECTED]
Subject: Word documents


I would be in much apreciation to whomever could point me to a good learning
on formating output, but using standard fonts.
 even PCL would be ok. My ultimate goal is a word doc converter if some one
knows of a good pm. Please let me know thanks.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to