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

Got to love those Fruit loops™ !

        What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
              -Larry Wall, 1992

  • Comment on Re^2: Using variable files to add data into excel spreadsheet

Replies are listed 'Best First'.
Re^3: Using variable files to add data into excel spreadsheet
by Anonymous Monk on May 22, 2014 at 10:26 UTC

    Thanks for all the replies! Yes, can't beat fruity loops, ha, ha! Ron, I think that's what I'm trying to achieve. Essentially all I'm trying to do is repeat the while loop script for as many times as I have fruit_types. As you've probably guessed from my "fruity loops", primary school example, :) I just don't have the scripting knowledge of Perl to execute this. I've been modifying the script with a bash loop, with something along the lines of...

    occurrence=( $(wc -l fruit_types) ) for i in `seq 1 $occurrence` blah, blah, blah.

    I know there must be an easier and less primitive way of doing this like you've suggested but could someone throw an example my way. As said I need some help with the scripting.

      #!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

        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
Re^3: Using variable files to add data into excel spreadsheet
by RonW (Parson) on May 22, 2014 at 18:00 UTC

      Ha, ha, yes quite, indeed. Forgive me mien Fuhrer, I am but a mere foot soldier in the ranks of the grammar Nazi's, I still slip from time to time! ;)

      On a serious note, thanks for your help.