Looking for some help with the reason as to why my run time is taking about a minute when using Win32::OLE SaveAs. Does it have to do with the fact that the Fileformat is = xlTextPrinter?
# This script is used to run like a Excel Macro
#!/usr/bin/perl -w
use strict;
use Win32::OLE;
use Win32::OLE qw(in with);
use Win32::OLE::Variant;
use Win32::OLE::Const 'Microsoft Excel';
#### File location
my $Filename = ('C:\xxxx\xxxx\xxx.xls');
#### Open Excel
my $Excel = Win32::OLE->new('Excel.Application', 'Quit');
$Excel->{SheetsInNewWorkbook} = 0;
my $Book1 = $Excel->Workbooks->Open($Filename) || die("Could not open file!");
my $Sheet1 = $Book1->Worksheets(1);
#### Column A
$Sheet1->Columns("A:A")->{ColumnWidth} = "25";
$Sheet1->Columns("A:A")->{HorizontalAlignment} = xlLeft;
$Sheet1->Columns("A:A")->{VerticalAlignment} = xlBottom;
#### Column B
$Sheet1->Columns("B:B")->{ColumnWidth} = "5";
$Sheet1->Columns("B:B")->{HorizontalAlignment} = xlLeft;
$Sheet1->Columns("B:B")->{VerticalAlignment} = xlBottom;
#### Column C
$Sheet1->Columns("C:C")->{ColumnWidth} = "25";
$Sheet1->Columns("C:C")->{HorizontalAlignment} = xlLeft;
$Sheet1->Columns("C:C")->{VerticalAlignment} = xlBottom;
#### Column D
$Sheet1->Columns("D:D")->{NumberFormat} = "0000000.00";
$Sheet1->Columns("D:D")->{ColumnWidth} = "10";
$Sheet1->Columns("D:D")->{HorizontalAlignment} = xlRight;
$Sheet1->Columns("D:D")->{VerticalAlignment} = xlBottom;
#### Column E
$Sheet1->Columns("E:E")->{ColumnWidth} = "1";
$Sheet1->Columns("E:E")->{HorizontalAlignment} = xlLeft;
$Sheet1->Columns("E:E")->{VerticalAlignment} = xlBottom;
#### Column F
$Sheet1->Columns("F:F")->{ColumnWidth} = "5";
$Sheet1->Columns("F:F")->{HorizontalAlignment} = xlLeft;
$Sheet1->Columns("F:F")->{VerticalAlignment} = xlBottom;
#### Column G
$Sheet1->Columns("G:G")->{ColumnWidth} = "40";
$Sheet1->Columns("G:G")->{HorizontalAlignment} = xlLeft;
$Sheet1->Columns("G:G")->{VerticalAlignment} = xlBottom;
#### Add X to Last Column
my $LastRow = $Sheet1->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByRows})->{Row};
my $LastCol = $Sheet1->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByColumns})->{Column};
$mylastcol2 = 'a';
for (my $m=1; $m < $LastCol + 1; $m++) {$mylastcol2++;}
my $Range1 = ("$mylastcol2"."1");
my $Range2 = ("$mylastcol2"."$LastRow");
my $Range = ("$Range1".":"."$Range2");
$Book1 -> ActiveSheet -> Range($Range)->{'Value'} = "X";
#### Save As .prn file
$Book1->SaveAs({Filename =>'C:\xxxx\xxxx\xxx.prn',
FileFormat => xlTextPrinter});
#### Close
$Book1->Close;
$Excel->Quit;
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.