in reply to Can't Use an undefined value as a HASH reference when passing HASH key into Excel OLE call.
I can't reproduce your problem. The following code runs and does what I think you say you ought to want, with a few minor tweaks, such as making the key correspond to the row, which makes things slightly easier for me. If you can show code that runs from scratch and demonstrates your problem, I might be able to do better.
use strict; use warnings; use diagnostics; use Win32::OLE; my $xl = Win32::OLE->new('Excel.Application'); $xl->{Visible} = 1; my $wb = $xl->Workbooks->Add(); for (2..$wb->Sheets->{Count}) { $wb->Sheets(2)->Delete; } my $worksheet = $wb->Sheets(1); my %hash = (1 => 'One', 5 => 'Five', 10=> 'Ten'); foreach my $key (sort keys %hash){ print "Key: $key\nValue: $hash{$key}\n"; $worksheet->Cells($key, 1)->{Value} = $hash{$key}; }
Regards,
John Davies
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't use an undefined value as a hash reference when passing hash key into Excel OLE call.
by kgnickl (Novice) on Nov 11, 2011 at 00:21 UTC | |
by davies (Monsignor) on Nov 11, 2011 at 08:15 UTC |