Using a nested array to paste range in Excel

Discussion in 'Perl' started by moller@notvalid.se, Feb 18, 2004.

  1. Guest

    I'm new to perl but not to programming in general.

    I hav been trying to put some data into an excel
    sheet. And it works fine.... if I hardcode the data.

    And I of cource I dont want to do that.


    This code works:

    my $table = [["040101",11,12,13,14,15],
    ["040102",21,22,23,24,25],
    ["040103",31,32,33,34,35],
    ["040104",41,42,43,44,45],
    ["040105",51,52,53,54,55]];

    $Sheet->Range("A3:E7")->{Value} = $table;



    So my (probably stupid) question is:
    How do I create the $table array dynamicly?

    foreach (sort (keys %My_hash)) {
    my $A = $My_hash{$_} { data_a };
    my $B = $My_hash{$_} { data_b };
    my $C = $My_hash{$_} { data_c };
    my $D = $My_hash{$_} { data_d };
    my $E = $My_hash{$_} { data_e };

    And here I would like to create each "row" in the array
    }


    I have tried using an normal array like this but this goes wrong.
    I get nonsens data in my excel file.

    my @arr;

    foreach (sort (keys %My_hash)) {
    my $A = $My_hash{$_} { data_a };
    my $B = $My_hash{$_} { data_b };
    my $C = $My_hash{$_} { data_c };
    my $D = $My_hash{$_} { data_d };
    my $E = $My_hash{$_} { data_e };

    push @arr, [$_, $A, $B, $C, $D, $D];
    }

    $Sheet->Range("A3:E7")->{Value} = @arr;


    I'm quite sure ther is somthing basic I'm missing.

    Any suggestions apreciated.
    , Feb 18, 2004
    #1
    1. Advertising

  2. Guest

    writes:

    Ignore this post. After reading som posts here I
    have reposted my question in comp.lang.perl.misc


    > I'm new to perl but not to programming in general.
    >
    > I hav been trying to put some data into an excel
    > sheet. And it works fine.... if I hardcode the data.
    >
    > And I of cource I dont want to do that.
    >
    >
    > This code works:
    >
    > my $table = [["040101",11,12,13,14,15],
    > ["040102",21,22,23,24,25],
    > ["040103",31,32,33,34,35],
    > ["040104",41,42,43,44,45],
    > ["040105",51,52,53,54,55]];
    >
    > $Sheet->Range("A3:E7")->{Value} = $table;
    >
    >
    >
    > So my (probably stupid) question is:
    > How do I create the $table array dynamicly?
    >
    > foreach (sort (keys %My_hash)) {
    > my $A = $My_hash{$_} { data_a };
    > my $B = $My_hash{$_} { data_b };
    > my $C = $My_hash{$_} { data_c };
    > my $D = $My_hash{$_} { data_d };
    > my $E = $My_hash{$_} { data_e };
    >
    > And here I would like to create each "row" in the array
    > }
    >
    >
    > I have tried using an normal array like this but this goes wrong.
    > I get nonsens data in my excel file.
    >
    > my @arr;
    >
    > foreach (sort (keys %My_hash)) {
    > my $A = $My_hash{$_} { data_a };
    > my $B = $My_hash{$_} { data_b };
    > my $C = $My_hash{$_} { data_c };
    > my $D = $My_hash{$_} { data_d };
    > my $E = $My_hash{$_} { data_e };
    >
    > push @arr, [$_, $A, $B, $C, $D, $D];
    > }
    >
    > $Sheet->Range("A3:E7")->{Value} = @arr;
    >
    >
    > I'm quite sure ther is somthing basic I'm missing.
    >
    > Any suggestions apreciated.
    , Feb 18, 2004
    #2
    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. Humvee
    Replies:
    1
    Views:
    383
    Mr. Clean
    Jul 22, 2003
  2. zxo102
    Replies:
    3
    Views:
    3,243
    Stuart Corrie
    Aug 9, 2005
  3. KaR
    Replies:
    0
    Views:
    650
  4. sdfgsd
    Replies:
    3
    Views:
    282
    sdfgsd
    Nov 4, 2003
  5. it_says_BALLS_on_your forehead

    extract range of lines using range op bug?

    it_says_BALLS_on_your forehead, Mar 3, 2006, in forum: Perl Misc
    Replies:
    3
    Views:
    176
    it_says_BALLS_on_your forehead
    Mar 3, 2006
Loading...

Share This Page