in reply to output to excel

Spreadsheet::WriteExcel

Replies are listed 'Best First'.
Re^2: output to excel
by cjb (Friar) on Aug 04, 2011 at 13:00 UTC
    It's lunch time, I'm bored. Something like this should work .
    #!perl.exe use Modern::Perl; #or use strict;use warnings; use Spreadsheet::WriteExcel; my $input_fn = 'perlmonks.org.918502.txt'; # or the name of your file my $output_fn = 'perlmonks.org.918502.xls'; # or the name of the xls f +ile you want to produce #open the input for reading open my $input_fh, '<', $input_fn or die "Unable to open $input_fn: $1 +\n"; #open xls file for output my $workbook = Spreadsheet::WriteExcel->new($output_fn); die "Problems creating Excel file: $!\n" unless defined $workbook; #create a worksheet with the name of the input file my $worksheet = $workbook->add_worksheet($input_fn); #split the line, and write to the matching row in the spreadsheet while (my $line = <$input_fh>) { $line =~ /(\d+).{5}(\d+.\d+)\s(\d+.\d+)\s(\d+.\d+)/; my @columns = ($2, $3, $4); $worksheet->write_row($1,0,\@columns); }
Re^2: output to excel
by chrestomanci (Priest) on Aug 04, 2011 at 15:08 UTC

    Or Excel::Writer::XLSX if you have the latest version of MS Excel and you want to write in it's native XML format.

    You might want to do this go get around the limitations in the older Excel format (eg: maximum of 256 columns and 2**16 rows per sheet).

    Both modules are written by the same author and claim to have the same interface, so you could decide which to use at runtime while only having a few lines of code that depend on which file format you plan to write.