Convert file to excel

Discussion in 'Perl Misc' started by Deepu, Sep 22, 2006.

  1. Deepu

    Deepu Guest

    Hi All,

    I am trying to create a table with some data and store it in a file and
    then it should be used in excel to create 3D bar chart. Can some one
    provide me with some ideas on how it can be done.

    Thanks for your time.

    Code:

    I have file which contains so many other details and have a line in the

    file which start with:

    #RESULT: 30 => YES: 10 NO: 10 UNKNOWN: 10

    I have several files with each file have a line with RESULT.

    ##### Code starts here ####

    #!/usr/bin/perl

    @dirList= qw(FILE1 FILE2 FILE3 FILE4 FILE5);

    foreach $dir (@dirList) {
    open (PH, "$dir") || die "Can not open:$dir";

    while (<PH>) {
    if (/#RESULT: (\d+) => YES: (\d+) NO: (\d+) UNKNOWN: (\d+)/) {
    push (@yesArray, $2);
    push (@noArray, $3);
    push (@unknownArray, $4);
    }
    }

    close (PH);

    }

    ## -- help from Mumia W ---
    my $fmt = "-%10s %5s %5s %5s\n";
    printf ($fmt, '', qw(YES NO UNKNOWN));

    foreach $dir(@dirList) {
    printf $fmt, $dir, $yesArray[$_], $noArray[$_], $unknownArray[$_];
    $_++;
    }

    The output generated is:

    YES NO UNKNOWN
    FILE1 10 8 14
    FILE2 6 7 20
    FILE3 18 10 10
    FILE4 20 12 10
    FILE5 10 10 10

    Now i am trying to save this table in a file so that it can be read by
    Excel and create bar chart. Is there any way possible to automate this
    flow.

    Thanks for the help.
    Deepu, Sep 22, 2006
    #1
    1. Advertising

  2. Deepu wrote:

    > The output generated is:
    >
    > YES NO UNKNOWN
    > FILE1 10 8 14
    > FILE2 6 7 20
    > FILE3 18 10 10
    > FILE4 20 12 10
    > FILE5 10 10 10
    >
    > Now i am trying to save this table in a file so that it can be read by
    > Excel and create bar chart.


    Excel can read CSV files.

    There's also a module on CPAN to write Excel files but it can't do
    fancy stuff like include macros.

    > Is there any way possible to automate this flow.


    You can drive Excel via OLE. (f you know the OLE commands you want
    then Win32::OLE will let you do them).

    Alternatively you could write an Excel macro that runs your Perl script.
    Brian McCauley, Sep 22, 2006
    #2
    1. Advertising

  3. Deepu <> wrote:

    > #!/usr/bin/perl


    use warnings;
    use strict;


    > @dirList= qw(FILE1 FILE2 FILE3 FILE4 FILE5);
    > foreach $dir (@dirList) {



    Calling something that is not a directory "dir" is likely to lead
    to easily avoided confusion.


    > open (PH, "$dir") || die "Can not open:$dir";



    perldoc -q vars

    What's wrong with always quoting "$vars"?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Sep 22, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rama
    Replies:
    1
    Views:
    2,534
    Steve C. Orr [MVP, MCSD]
    Nov 12, 2003
  2. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,380
    Carl Prothman [MVP]
    Jan 12, 2005
  3. Replies:
    1
    Views:
    1,794
    extentechjohn
    Nov 21, 2006
  4. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,498
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  5. Santana
    Replies:
    1
    Views:
    127
    Serman D.
    Aug 7, 2007
Loading...

Share This Page