in reply to Re^3: Using variable files to add data into excel spreadsheet
in thread Using variable files to add data into excel spreadsheet

#!perl use strict; use Excel::Writer::XLSX; # Create a new Excel workbook and worksheet my $workbook = Excel::Writer::XLSX->new( 'fruits.xlsx' ); my $worksheet = $workbook->add_worksheet(); # get fruit types open FRUITS,'fruit_types.txt' or die "$!"; my @fruits = split '\s',<FRUITS>; # write column for each fruit for my $col (0..$#fruits){ my $fruit = $fruits[$col]; my $filename = $fruit.'.txt'; open IN, $filename or die "Could not open $filename : $!"; my @col = ($fruit); while (<IN>){ chomp; push @col, $_; } print "Writing column $col @col\n"; $worksheet->write_col(0,$col,\@col); } $workbook->close() or die "Error closing file: $!";
poj

Replies are listed 'Best First'.
Re^5: Using variable files to add data into excel spreadsheet
by rickyboy (Novice) on May 23, 2014 at 13:36 UTC

    Oh dear Lord, this is incredible!

    Thanks so much poj, for taking the time to write this. This is exactly what I'm looking for!

    With the risk of extracting the Michael...

    ...Any way of making the output to the spread sheet start at column 2 as the first columns in the spread sheet will already be accounted for? i.e

    column 0 column 1 column 2 column 3 column 4 shop area apple banana orange Aldi Glasgow 1 2 5 Tesco Edinburgh 5 6 3 Asda London 3 1 7
      # write column for each fruit for my $i (0..$#fruits){ my $col = $i+2; my $fruit = $fruits[$i]; .. etc
      poj