use strict; use warnings; use File::Spec; use Cwd; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors my $excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application'); $excel->{Visible} = 0; my $xls = File::Spec->catfile(cwd(), 'tmp.xls'); my $book2 = $excel->Workbooks->Open($xls); my $sheet2 = $book2->Worksheets(1); my @keys = ('a', 'b', 'c', 'd', 'e', 'f', 'g'); my @vals = (12, 23, 42, 13, 2, 33, 44); my $title = qq(diagram1); make_chart($title, \@keys, \@vals); $book2->Close(0); $excel->Quit(); sub make_chart($$$) { my ($title, $key, $val) = @_; my $range = $sheet2->Range("A1:G2"); $range->{Value} = [$key, $val]; my $chart = $excel->Charts->Add; $chart->{ChartType} = xlPie; $chart->SetSourceData( { Source => $range, PlotBy => xlRows } ); $chart->{HasTitle} = 1; $chart->ChartTitle->{Text} = $title; # ??? # $chart->ApplyDataLabels->{ShowValue}; $chart->Location( { Where => xlLocationAsObject, Name => "Tabelle2" } ); #$sheet2->{Name}); $chart = $excel->ActiveChart; my $file = File::Spec->catfile(cwd(), $title.qq(.gif)); $chart->Export($file, "GIF", 0); }