I have a comma delimited file which upper management imports into an Excel file. I figured I'd show some initiative and write a script to create the Excel file for them.

I'd never used Spreadsheet::WriteExcel before, but it was a breeze. The spreadsheet is exactly the way management uses it. The only difference is the size of the file. The file created by my perl script is much larger than the file created by importing the comma delimited file. Here's the breakdown:

Following is the script I'm using to create the file. I'd like to hear any suggestions regarding reducing the size of the Excel file. Like I said, I've never played with the module before, so I may be missing some obvious efficiency issues.

#!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel::Big; open (IN, "temp.txt") || die "Cannot open temp.txt\n"; # set up Excel spreadsheet my $workbook = Spreadsheet::WriteExcel::Big->new("temp.xls"); my $worksheet = $workbook->addworksheet(); my $inLine; my $row = 0; while ($inLine = <IN>) { my ($date, $log, $protocol, $firstIP, $secondIP, $packets) = split(/,/, $inLine); # strip port number if it exists if ($firstIP =~ /([\d.]+)\((\d+)\)/) { my $ip1 = $1; my $port1 = $2; } else { my $ip1 = $firstIP; my $port1 = " "; } if ($secondIP =~ /([\d.]+)\((\d+)\)/) { my $ip2 = $1; my $port2 = $2; } else { my $ip2 = $secondIP; my $port2 = " "; } push my @XLSarray, ($date, $log, $protocol, $ip1, $port1, $ip2, $port2, $pac +kets); # print information to Excel spreadsheet my $col = 0; foreach my $XLSelement (@XLSarray) { $worksheet->write($row, $col, $XLSelement); $col++; } $row++; } $workbook->close();

If things get any worse, I'll have to ask you to stop helping me.


In reply to Spreadsheet::WriteExcel::Big is Bigger by shockme

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.