perlquestion
Anonymous Monk
<p>I am using the below code to generate graph and it is working fine.</p>
<c>
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const "Microsoft Excel";
my $xls = Win32::OLE->new('Excel.Application');
$xls->Workbooks->Add();
$xls->{Visible} = 1;
$xls->Sheets("Sheet1")->Range('A1')->{Value} = 'Left';
$xls->Sheets("Sheet1")->Range('B1')->{Value} = 'Right';
$xls->Sheets("Sheet1")->Range('C1')->{Value} = 'Center';
for (2 .. 5) {
$xls->Sheets("Sheet1")->Range("A$_")->{Value} = $_;
$xls->Sheets("Sheet1")->Range("B$_")->{Value} = $_ * 2;
$xls->Sheets("Sheet1")->Range("c$_")->{Value} = $_ * 3;
}
$xls->Charts->Add();
$xls->ActiveChart->SetSourceData({
Source =>$xls->Sheets('Sheet1')->Range("A1:C5"),
PlotBy =>xlColumns,
});
$xls->ActiveChart->Location({ Where => xlLocationAsObject, Name =>'Sheet1'});
</c>
<p>But what i want to do is, i want give the values through some variable, ie. the chart should not be generated from the excel data, rather i want to create by giving the values through variables or datastructure. for example, i want to create for the below data. I tried as shown below. How can i achieve that?</p>
<c>
my @a = (1, 2, 3);
my @b = (5, 10, 15);
my $a = \@a;
my $b = \@b;
$xls->ActiveChart->SetSourceData({
Source =>$xls->Sheets('Sheet1')->Range("$a:$b"),
PlotBy =>xlColumns,
});
</c>
6