Here is a short example that displays the problem on the new computer
#!perl
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const;
use Cwd;
print "Load Const\n";
my $wdc = Win32::OLE::Const->Load("Microsoft Word") ||
die "Unable to load constants ", Win32::OLE->LastError();
print "Load Word Engine\n";
my $Word = Win32::OLE->new('Word.Application', 'Quit') ||
die "Unable to start Word Engine ", Win32::OLE->LastError();
$Word->{'Visible'} = 0 ;
$Word->{'DisplayAlerts'} = 0;
## Open template
print "Add new doc\n";
my $doc = $Word->Documents->Add() ||
die"Unable to open new doc ", Win32::OLE->LastError();
# Turnoff background operations
$Word->Options->{'Pagination'} = 0;
$Word->Options->{'PrintBackground'} = 1;
$Word->Options->{'BackgroundSave'} = 0;
my $range = $doc->Content;
$range->Collapse( {Direction => $wdc->{wdCollapseEnd} } );
my $max_row = 25;
my $max_col = 7;
print "Creating table $max_row x $max_col\n";
my $t1 = $doc->Tables->Add($range, $max_row, $max_col);
my $start = time;
print "Start Data Entry\n";
foreach my $row (1 .. $max_row) {
foreach my $col (1 .. $max_col) {
$t1->Cell($row, $col)->Range->{Text} = "$row-$col";
}
}
print "Finished Data Entry ", time - $start, " secs\n";
$start = time;
print "Start Center\n";
foreach my $row (2 .. $max_row) {
foreach my $col (1,3,5.. $max_col) {
$t1->Cell( $row, $col )->Range->ParagraphFormat->{'Alignment'}
+ =
$wdc->{'wdAlignParagraphCenter'};
}
}
print "Finished Center ", time - $start , " secs\n";
my $path = cwd;
my $out_file = "$path/word_ole.doc";
$out_file =~ s{\/}{\\}g;
$doc->SaveAs($out_file);
$doc->Close( { SaveChanges => $wdc->{wdDoNotSaveChanges} } );
I have timed this on three different computers. On the new one it takes around 50 secs to enter data and 70 secs to center data. Whereas on the others enter and center takes around one second each, which is what I was used to.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.