in reply to Copying data sets of varying size into excel using OLE

Your data structure is not what you think it is. Use Data::Dumper to get some insight into how your datastructure looks and what is contained in what variable. $sheet has the value Delivered, and is not a Win32::OLE object, as you might expect.

Also see Querylet.

Replies are listed 'Best First'.
Re^2: Copying data sets of varying size into excel using OLE
by Anonymous Monk on Sep 08, 2010 at 17:56 UTC

    Thanks Corion.

    My data looks like this (an example from the web), is there a way to process the array data in the manner described (by matching cells with array elements)?

    Thanks for the help.

    my $range = $sheet -> Range("A2:C7");</p><p> $range -> { Value } = [['Delivered', 'En route', 'To be shipped'], [504, 102, 86], [670, 150, 174], [891, 261, 201], [1274, 471, 321], [1563, 536, 241]];

    Code tags added by GrandFather

      The two tasks needed for this are "Programming" and "Debugging". You will need to do both or hire somebody who will do both for you.

      If you actually want to do both yourself instead of spending money on hiring somebody, you might want to preview your post and inspect whether it renders well or not, and then read the Writeup Formatting Tips, especially the part where it says to "Put your code and data between <code>...</code> tags".

      Most likely, what you want to do can be done by using a loop. See perlsyn about loop structures.

      If I'm correct, I believe that $range->{Value} is expecting a scalar (think a single integer, a single string, etc.) and you're trying to feed it an array. Personally, I've never tried to dump an array of data into a range of more than one cell. I've always done a single value into a single cell. You'll probably have more success doing the same. In your case, you'll probably want to do a loop as Corion suggested.

        The example i'm asking about does contains loop structures, and i'm trying to parse out the array element by element into excel, 1 element per cell.

        Here's the code formatted correctly:

        foreach my $line (@$array) { for (my $row = 0; $row < (scalar(@$array)+1); $row++) { foreach my $element (@$line) { for (my $col = 0; $col < scalar(@$line); $col++) { $sheet -> Cells(($row+10),($col+1)) -> {Value} = @$element[$co +l]; } } } }

        The array to be passed contains 6 lines (arrays) of 3 elements each. I want to loop through the lines, parsing out each array into excel in turn. I *am* a beginner (I looked at Perl for the first time last week) so I apologize if this is a simplistic question, but would appreciate any useful insights into this as i've been unable to make this script work so far.

        Thanks, Joe