http://qs321.pair.com?node_id=647950


in reply to Excel and Win32::OLE chart problems

I'm not a Win32::OLE user, but that loose curly bracket looks suspect:

$chart->ChartType} = xl3DColumnClustered;
I tried to throw your code into a file like this:
use strict; use warnings; use Win32::OLE; my ($vtfalse,$sheet); # Create the chart # my $chart = $sheet->ChartObjects->Add(1, 175, 457, 300); $chart->ChartType = 'xl3DColumnClustered'; $chart->Chart->ChartWizard({Source =>$sheet->Range("D5:D12")}); $chart->Chart->SeriesCollection(1)->{Values}=$sheet->Range("D5:D12"); $chart->Chart->SeriesCollection(1)->{XValues}=$sheet->Range("B5:B12"); $chart->Chart->SeriesCollection(1)->{Values}=$sheet->Range("D5:D12"); $chart->Chart->SeriesCollection(1)->{Name}=$sheet->Range("B5:B12"); $chart->Chart->{HasLegend} = $vtfalse; $chart->Chart->{HasDataTable} = $vtfalse; $chart->Chart->SeriesCollection(1)->{HasDataLabels} = 1;
but I still get errors.
Can't call method "ChartObjects" on an undefined value at K:\Desktop\3 +d-chart.pl line 7.
Guess I'm missing something else. Can you post some minimal complete code that illustrates your problem?

Replies are listed 'Best First'.
Re^2: Excel and Win32::OLE chart problems
by the_hawk_1 (Scribe) on Oct 30, 2007 at 15:03 UTC
    Thanks for taking time to test it.

    Here is a part of code that might help:

    use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); use Win32::OLE::Const 'Microsoft Office .* Object Library'; use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Const "Microsoft Graph 9.0 Object Library"; my $vtfalse = Variant(VT_BOOL, 0); my $vttrue = Variant(VT_BOOL, 1); my $vtpagesw = Variant(VT_I4, 1); my $vtpagest = Variant(VT_I4, 999); eval {$ex = Win32::OLE->GetActiveObject('Excel.Application','Quit' +)}; die "Excel not installed" if $@; unless (defined $ex) { $ex = Win32::OLE->new('Excel.Application', sub {$_[0]- +>Quit;}) or die "Oops, cannot start Excel"; }
    I've correct the missing braket, but it didn't change anything. I've also tried to use the $chart->ChartType = 'xl3DColumnClustered';, but I ended with a Can't modify non-lvalue subroutine call at Z:\ScriptPerl\SAC\Sommaire-VL.pl line 232.

    I'll continue trying to make it work today and I'll update later with my conclusions... if any.