加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

使用perl的excel图表

发布时间:2020-12-15 21:44:02 所属栏目:大数据 来源:网络整理
导读:当我运行脚本时,我遇到了问题,它给出了错误,例如无法在chart_column.pl第33行通过包“Spreadsheet :: WriteExcel”找到对象方法“add_chart”.我可以知道这里有什么问题吗?我正在使用为x86_64- linux构建的perl,v5.8.5. #!/usr/bin/perl -w ##############
当我运行脚本时,我遇到了问题,它给出了错误,例如无法在chart_column.pl第33行通过包“Spreadsheet :: WriteExcel”找到对象方法“add_chart”.我可以知道这里有什么问题吗?我正在使用为x86_64- linux构建的perl,v5.8.5.
#!/usr/bin/perl -w
###############################################################################
#
# A simple demo of Column charts in Spreadsheet::WriteExcel.
#
# reverse('?'),December 2009,John McNamara,jmcnamara@cpan.org
#

use strict;
use Spreadsheet::WriteExcel;

my $workbook  = Spreadsheet::WriteExcel->new( 'chart_column.xls' );
my $worksheet = $workbook->add_worksheet();
my $bold      = $workbook->add_format( bold => 1 );

# Add the worksheet data that the charts will refer to.
my $headings = [ 'Category','Values 1','Values 2' ];
my $data = [
    [ 2,3,4,5,6,7 ],[ 1,2,1,5 ],[ 3,7,3 ],];

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


###############################################################################
#
# Example 1. A minimal chart.
#
my $chart1 = $workbook->add_chart( type => 'column' );

# Add values only. Use the default categories.
$chart1->add_series( values => '=Sheet1!$B$2:$B$7' );

# Insert the chart into the main worksheet.
$worksheet->insert_chart( 'E2',$chart1 );

解决方法

只需添加embedded => 1到add_chart调用:

Perl的

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读