For others who may want to see how module works...

Here is a snippet of code I used with the Write:Excel module...  Was
written and run on WinNT without Excel installed on the box.  It reads
in csv files into Excel file and then sets some limited formatting
(freeze panes and set column widths).  Thanks to Japhy for help with the
sequence on this script!

....Preliminary stuff here...

($first) = @ARGV = grep !-d, glob "C:/SMTPBeam/Stats/sm*.csv";  #Make a
list of the files to process

$FILE2 = "C:/SMTPBeam/Stats/Stats for $mth-$yr.xls";  #Name output
file
    my $workbook  = Spreadsheet::WriteExcel->new("$FILE2");
    my $worksheet = $workbook->addworksheet("Stats for $mth-$yr");
    my $row = 0;

while (<>) {            #Read in the data to Spreadsheet
            s/"//g;             #Kill " appearing in source
            s/^0/200/g;        # Change year (ie: 05 to 2005) Had to do
some date trickery here so Excel wouldn't freak out  Original date
format was YYMMDD

if ($ARGV eq $first or $. !=1) # If first file, read all rows else skip
header on others
{        chomp;
        my @Fld = split(',', $_);

        my $col = 0;
        foreach my $token (@Fld) {
            $worksheet->write($row, $col, $token);
            $col++;
        }
        $row++;}
close ARGV if eof;

#Formatting Section
$worksheet->freeze_panes('B2'); # Using A1 notation, Column 1 and Row A
are frozen
$worksheet->set_column('A:B',  10); # Column  A-B   width set to 10
$worksheet->set_column('C:C',  05); # Columns C width set to 5
$worksheet->set_column('D:D',  07); # Columns D width set to 7
$worksheet->set_column('E:F',  35); # Columns E-F width set to 35
$worksheet->set_column('G:G',  10); # Columns G width set to 10
}

....Do whatever you want with file here like mail it or FTP...

>>> John Edwards <[EMAIL PROTECTED]> 01/31/02 10:49AM >>>


What OS are you running? I've included a script that uses Win32::OLE
to
interface with Excel. You'll need to be on a Win32 machine, with Excel
installed.

There is also a module called Spreadsheet::WriteExcel which is
platform
independant, but I have not had any experience using this.

HTH

John

-----Original Message-----
From: Lance Prais [mailto:[EMAIL PROTECTED]] 
Sent: 31 January 2002 17:46
To: PERL
Subject: Writing to a file


I have a question regarding writing to a file.

I have written a script and my experiences in perl thus far has been
limited
to outputting data to a JSP page but in this case I need to send it to
a
excel file.  Does anyone know if there are examples out there that can
show
me how to do this?

Thank you in advance

Lance


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 


--------------------------Confidentiality--------------------------.
This E-mail is confidential.  It should not be read, copied, disclosed
or
used by any person other than the intended recipient.  Unauthorised
use,
disclosure or copying by whatever medium is strictly prohibited and may
be
unlawful.  If you have received this E-mail in error please contact
the
sender immediately and delete the E-mail from your system.


 <<eventlog.zip>>  

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to