Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi @ all, in recent days I try to talk about Perl with Excel 2007 (about WIN32::OLE). I want to create a Pivot table + chart. But I couldn't create a chart Title. Please help me.... For a better understanding my perl code:
#! perl -w use warnings; use strict; use Win32::OLE ; my $excel = Win32::OLE->new('Excel.Application'); $excel->{'Visible'} = 1; my $workbook = $excel -> Workbooks -> Add; my $sheet = $workbook->Sheets("Tabelle1"); $sheet -> Range('A1')->{'Value'} = "Temp [°C]"; $sheet -> Range('B1')->{'Value'} = "Vcc [V]"; $sheet -> Range('C1')->{'Value'} = "Vio [V]"; $sheet -> Range('D1')->{'Value'} = "Ivcc [mA]"; $sheet -> Range('A2:D3')->{'Value'} = [ ['1', '2', '3', '4' ], ['5', '6', '7', '8' ], ]; my $sheet2 = $workbook-> Sheets -> Add; $sheet -> select; #&sheet2->Shapes->AddChart->Select; #ActiveChart->SetSourceData Source->Range("Tabelle4!$A$1:$C$18"); #$workbook->PivotChaches->Add{SourceType=>1,SourceData=>'Tabelle1!Z1S1 +:Z3S4'})->({TableDestination=>'Tabelle4!Z1S1', TableName=>'PivotTable +1'}); my $pivot=$workbook->PivotTableWizard( { SourceType => 1, SourceData => 'Tabelle1!Z1S1:Z3S4', TableDestination => "Tabelle4!Z1S1", TableName => "PivotTable1", HasAutoFormat => 1 }); $pivot->PivotFields("Vcc [V]")->{Orientation} = 1; # 4=xlDataField $pivot->PivotFields("Temp [°C]")->{Orientation} = 2; # 4=xlDataField $pivot->PivotFields("Vio [V]")->{Orientation} = 1; # 4=xlDataField $pivot->PivotFields("Ivcc [mA]")->{Orientation} = 4; # 4=xlDataField $pivot->PivotFields("Summe von Ivcc [mA]")->{Function} = 2; #{Caption} + = "Mittelwert von Ivcc [mA]"; $sheet2->Range('F1')->Select; my $chart=$sheet2->Shapes->AddChart(65); $sheet2->chartObjects("Diagramm 1")->Activate; $chart->{HasTitle} = 1; $chart->ChartTitle->{Text} = "Some Title"; $excel -> Quit;
The lines
$chart->{HasTitle} = 1; $chart->ChartTitle->{Text} = "Some Title";
didn't work. Why?

Some additional questions:

Where can I find information/documentation on the "Perl excel syntax"?

Can I control excel completely with the WIN32::OLE modul?

Thanks for working on this topic

Best Regards

jazzman

Replies are listed 'Best First'.
Re: WIN32::OLE excel pivot Chart Title doesn't work
by Corion (Patriarch) on Feb 22, 2011 at 22:12 UTC
      Yes, I know. That was my first attempt=) But I have these commented out then.

        If you look at the code that the Excel Macro Recorder creates, you will find that it first sets up PivotCaches before it creates the pivot table. If you port the VB code to Perl, it is a good strategy to follow what the VB code does.