Selection.Style = ActiveDocument.Styles "Heading 1"
Selection.TypeText Text:="The Title"
####
$Word->Selection->TypeText ({ Text => "The Title",
Style => 'Heading 1',
});
####
#!/usr/bin/perl -w
#Check that the path to the picture is correct on line 53
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const;
$Win32::OLE::Warn = 2; # Throw Errors, I'll catch them
my $Word = Win32::OLE->new('Word.Application', 'Quit');
$Word->{'Visible'} = 1; # if you want to see what's going on
$Word->Documents->Add || die("Unable to create document ",
Win32::OLE->LastError());
#
$Word->Selection->TypeText ({ Text => "The Title"});
#Generate and sort tabel information
my %mass_info_hash= ("5", "25","10", "100","15", "225","20", "400","25", "625",
"35", "1225","40", "1600","45", "2025","50", "2500","55", "3025","60",
"3600","65", "4225","70", "4900","75", "5625","80", "6400","85", "7225",
"90", "8100","95", "9025");
my @mass_list = keys %mass_info_hash;
#copy mass list over to new variabel before sorting
my @mass_list_sorted = @mass_list;
@mass_list_sorted = sort{$a<=>$b}@mass_list_sorted;
my $rows = ($#mass_list) +2;
# create table...
$Word->ActiveDocument->Tables->Add({
Range => $Word->Selection->Range,
NumRows => $rows,
NumColumns => 2,
});
# crude way of inserting text into table...
#print tabel headers
$Word->Selection->TypeText ({ Text => "Mass"}); #zero
$Word->Selection->MoveRight({Count => 1});
$Word->Selection->TypeText ({ Text => "Intensity" });
#print hash info
foreach my $mass( @mass_list){
$Word->Selection->MoveRight({Count => 1});
$Word->Selection->TypeText ({ Text => $mass });
$Word->Selection->MoveRight({Count => 1});
$Word->Selection->TypeText ({ Text => $mass_info_hash{$mass} });
}
$Word->Selection->MoveRight({Count => 1});
# Next space is outside table
#insert picture
$Word->Selection->TypeText ({ Text => "\nPicture\n" });
#change the path to point to your user folder.
$Word->Selection->InlineShapes->AddPicture ({
FileName => 'C:\Documents and Settings\Richard\My Documents\My Pictures\sample.jpg',
LinkToFile=>'False',
SaveWithDocument=>'True',
});
#Make second tabel with sorted mass list
$Word->Selection->TypeText ({ Text => "\n\n" });
# create table...
$Word->ActiveDocument->Tables->Add({
Range => $Word->Selection->Range,
NumRows => $rows,
NumColumns => 2,
});
$Word->Selection->TypeText ({ Text => "Mass"}); #zero
$Word->Selection->MoveRight({Count => 1});
$Word->Selection->TypeText ({ Text => "Intensity" });
foreach my $mass( @mass_list_sorted){
$Word->Selection->MoveRight({Count => 1});
$Word->Selection->TypeText ({ Text => $mass });
$Word->Selection->MoveRight({Count => 1});
$Word->Selection->TypeText ({ Text => $mass_info_hash{$mass} });
}
$Word->Selection->MoveRight({Count => 1});