Hi Monks,
I have a script which produces output in a Excel sheet. I use Win32::OLE. The file has 7 work sheets and one of them is quite big - 10 columns and 8000 to 10000 rows. I use a for loop to write the data cell by cell from an array. Most columns have string data except two which has date time values. This operation takes few minutes to complete.
Is there a way to speed it up by alternate methods (e.g. creating CSV files and joining them together or such). Any comments and suggestions are welcome.
I don't have much formatting at the moment, but need to introduce it also (bold/ italics/ colors).
Following is the piece of code I use currently.
$Sheet = $Book-> Worksheets->Add;
$Sheet = $Book-> Worksheets("Sheet7");
$Sheet-> Activate();
$Sheet-> {Name} = "BU Detail";
$range = 1;
foreach my $detail_line (@bu_detail)
{
my @detail_fields = split(/,/,$detail_line);
$Sheet-> Range('A'.$range)->{Value} = $detail_fields[0];
$Sheet-> Range('B'.$range)->{Value} = $detail_fields[1];
$Sheet-> Range('C'.$range)->{Value} = $detail_fields[2];
$Sheet-> Range('D'.$range)->{Value} = $detail_fields[3];
$Sheet-> Range('E'.$range)->{Value} = $detail_fields[4];
$Sheet-> Range('F'.$range)->{Value} = $detail_fields[5];
$Sheet-> Range('G'.$range)->{Value} = $detail_fields[6];
$Sheet-> Range('H'.$range)->{Value} = $detail_fields[7];
$Sheet-> Range('I'.$range)->{Value} = $detail_fields[8];
$Sheet-> Range('J'.$range)->{Value} = $detail_fields[9];
$range++;
}
@columnheaders = qw(A:J);
foreach $range(@columnheaders)
{
$Sheet-> Columns($range)->AutoFit();
}
Regards
Joseph John
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.