如何创建包含多个图表和表格的Excel工作表

时间:2014-03-12 09:47:48

标签: excel perl

我的任务是创建一个包含多个图表和表格的Excel工作表。

我不知道如何通过程序创建一个特定的布局。

使用一张桌子和一张图表我没有问题

#!/usr/bin/perl
use strict;
use warnings;
use Excel::Writer::XLSX;

my $workbook  = Excel::Writer::XLSX->new( 'chart.xlsx' );
my $worksheet = $workbook->add_worksheet();

# Add the worksheet data the chart refers to.
my $data = [
    [ 'Category', 2, 3, 4, 5, 6, 7 ],
    [ 'Value',    1, 4, 5, 2, 1, 5 ],

];

$worksheet->write( 'A1', $data );

# Add a worksheet chart.
my $chart = $workbook->add_chart( type => 'column', embedded=>1 );

# Configure the chart.
$chart->add_series(
    categories => '=Sheet1!$A$2:$A$7',
    values     => '=Sheet1!$B$2:$B$7',
);

$worksheet->insert_chart( 'D1', $chart, 3, 3 );
__END__

但如果我想在下面放置另一张表格和图表,我怎么知道在哪个地方定位呢?

我如何知道上一张图表的行数和列数?

1 个答案:

答案 0 :(得分:0)

只需添加另一个图表对象

my $chart2 = $workbook->add_chart( type => 'column', embedded=>1 );

# Configure the chart.  # change the categories if required change the values as required
$chart2->add_series(
    categories => '=Sheet1!$A$2:$A$7',
    values     => '=Sheet1!$B$2:$B$7',
);

$worksheet->insert_chart( 'D1', $chart2, 3, 3 );