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
respectively I couldn't set up the settings of my pivot chart (Title, name of
the x-axes ....) . 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('A23')->{'Value'} = [
['1', '2', '3', '4' ],
['5', '6', '7', '8' ],
];
my $sheet2 = $workbook-> Sheets -> Add;
$sheet -> select;
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;
=======================================
end
=======================================
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
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
respectively I couldn't set up the settings of my pivot chart (Title, name of
the x-axes ....) . 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('A23')->{'Value'} = [
['1', '2', '3', '4' ],
['5', '6', '7', '8' ],
];
my $sheet2 = $workbook-> Sheets -> Add;
$sheet -> select;
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;
=======================================
end
=======================================
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