我正在努力解决这个问题大约2天而且我已经感到沮丧,因为我的问题并不是一个很大的算法...我想写一个perl程序,它可以节省一些值excel sheet并生成带有特定列颜色的xlColumnStacked100标记图。到目前为止,我设法制作堆叠图(Win32 :: OLE)或标记的(Excel :: Writer :: XLSX)。我究竟做错了什么??我尝试了很多东西,但不知怎的,因为它必须得到它...提前感谢任何提示!
#!/usr/bin/perl -w
use warnings;
use Win32::OLE;
use Win32::OLE qw(in);
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::Const 'Microsoft Office .* Object Library';
use diagnostics;
use strict;
my $xlApp = Win32::OLE->new('Excel.Application');
$xlApp->{Visible} = 1;
my $xlBook = $xlApp->Workbooks->Add;
my $mydata = [["", "A", "B", "C", "D", "E"],
["X", "1", "2", "3", "4", "5"],
["Y", "2", "3", "4", "5", "6"],
["Z", "3", "4", "5", "6", "7"],
];
my $rng = $xlBook->ActiveSheet->Range("A1:F4");
$rng->{Value} = $mydata;
my $chart = $xlBook->Charts->Add;
$chart->SetSourceData($rng, 2);
$chart->{ChartType} = 53;
$chart->Location(2, "Tabelle1");
$xlApp->$xlBook->$chart->ApplyDataLabels({AutoText => 1});
其他代码:
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Excel::Writer::XLSX;
my $workbook = Excel::Writer::XLSX->new('C:\\diagramm.xlsx');
my $worksheet = $workbook->add_worksheet();
my $bold = $workbook->add_format( bold => 1 );
my $headings = [ ' ', 'A', 'B', 'C', 'D', 'E'];
my $data = [
['X', 'Z', 'Y'],
[1, 2, 3],
[2, 3, 43],
[3, 4, 5],
[4, 5, 6],
[5, 6, 7],
];
$worksheet->write( 'A1', $headings, $bold );
$worksheet->write( 'A2', $data );
my $chart = $workbook->add_chart( type => 'Column', embedded => 1 );
$chart->add_series(
categories => '=Sheet1!$A$2:$A$4',
values => '=Sheet1!$B$2:$B$4',
data_labels => { value => 1 },
name => 'A',
);
$chart->add_series(
categories => '=Sheet1!$A$2:$A$4',
values => '=Sheet1!$C$2:$C$4',
data_labels => { value => 1 },
name => 'B',
);
$chart->add_series(
categories => '=Sheet1!$A$2:$A$4',
values => '=Sheet1!$D$2:$D$4',
data_labels => { value => 1 },
name => 'C',
);
$chart->add_series(
categories => '=Sheet1!$A$2:$A$4',
values => '=Sheet1!$E$2:$E$4',
data_labels => { value => 1 },
name => 'D',
);
$chart->add_series(
categories => '=Sheet1!$A$2:$A$4',
values => '=Sheet1!$F$2:$F$4',
data_labels => { value => 1 },
name => 'E',
);
$chart->set_x_axis( name => 'SomeName' );
$chart->set_title( name => 'SomeTitle' );
$chart->set_style( 10 );
$worksheet->insert_chart( 'J2', $chart, 25, 10 );