in reply to Re^2: Copying data sets of varying size into excel using OLE
in thread Copying data sets of varying size into excel using OLE

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.

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

    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

      And now that you have the method for formatting properly, you may want to register - join the Monastery -- and read more of the docs suggested above: both those about PM and those that document various functions and modules.

        The answer to my question involved me learning how to get Perl to assess the size of the data set to be pasted, making it easy to pass this to the Range() in excel. It's a messy method to my mind, but it works well enough for the project i'm working on. Here it is in case another beginner needs to find it.

        # Define data range my $sum = 0; foreach my $line (@$array) { $sum += scalar(@$line); } my $rows = scalar(@$array); my $cols = $sum/scalar(@$array); my $rng1 = "A1"; ### hard-coded starting position my @num = ("A" .. "Z"); my $num2 = $num[$cols-1]; my $rng2 = "$num2"."$rows"; # Copy data to excel range $sheet -> Range("$rng1:$rng2") -> { 'Value' } = $array;

        Thank you all for your helpful comments on formatting ;)