Dear great ones, I have turned to the almighty Perl to make a spread sheet. It's made life incredibly easy for me up until now. I need to add data from files into columns. The problem is, I don't know how many columns there will be or how many files as the data I'm using for the files is variable. For example,

my $intStartRow = 0; my $altRow = $intStartRow; my $intStartCol = 2; my $altCol = $intStartCol; open (FRUITS, '/home/fruit_types.txt') or die ("Problem opening file: +$!"); # Fruit Header Insertion my $row = 1; while (<FRUIT>) { chomp; # Split on single tab my @Fld = split ('\t', $_); my $col = 3; foreach my $token (@Fld) { $worksheet->write($altRow, $altCol++, $token, $format); $col++; } $row++; }

So I have a file called fruit_types which contains the strings (apple, banana, orange, etc). The perl script will automatically put those strings into their own columns at the head of the spread sheet. The types of fruit will be variable so I will not know how many strings will be in the file, hence why it is added using the script above. I then have a directory with a separate file for each fruit i.e (apple.txt, banana.txt, orange.txt, etc). Inside each file contains spread sheet data (1,2,5, etc) to represent the amounts of each fruit I have. I now want to tie that data into the relevant column (apple, banana, orange, etc). The spread sheet would look like this...

apple banana orange 1 2 5 2 3 8 3 1 3
Can someone enlighten me how I would go about doing this? Thanks, Richard.

In reply to Using variable files to add data into excel spreadsheet by rickyboy

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.