从perl中给定的excel数据绘制条形图 Excel数据:它每周动态变化。我想自动化它。
===============================
以下是该计划:
我想为它绘制excel图表。
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
my $parser = new Spreadsheet::ParseExcel::SaveParser;
my $workbook = $parser->Parse('Nilu.xls');
my $worksheet1 = $workbook->worksheet('Worksheet1');
$worksheet1->activate();
my ( $row_min, $row_max ) = $worksheet1->row_range();
my ( $col_min, $col_max ) = $worksheet1->col_range();
print "row min:$row_min row_max:$row_max col_max:$col_max\n\n";
my $worksheet2 = my $parser->add_worksheet( 'Worksheet2' );
#$parser->add_worksheet( 'Worksheet2' );
$ worksheet2->激活();
# Create a new chart object. In this case an embedded chart.
my $chart1 = $workbook->add_chart( type => 'column', embedded => 1 );
# Configure the first series.
$ chart1-> add_series( name => '=工作表Sheet1!$ B $ 1', categories => “!= Sheet1中\ $ A \ $ 2:\ $ A:$ row_max” values => “!= Sheet1中\ $ B \ $ 2:\ $ B:$ row_max” );
# Set an Excel chart style. Blue colors with white outline and shadow.
$chart1->set_style( 11 );
# Insert the chart into the worksheet (with an offset).
$worksheet2->insert_chart( 'F2', $chart1, 25, 10 );
# Write over the existing file or write a new file.
$parser -> SaveAs('Nilu1.xls');
答案 0 :(得分:0)
您可以使用Spreadsheet :: ParseExcel解析Excel工作表(或将其导出为CSV数据,然后使用Text :: CSV_XS),例如:用于绘制条形图的图表模块。
为了给出更准确的答案,我需要进一步的信息,特别是:
答案 1 :(得分:0)
以下是带有Perl的Excel中的example of drawing a bar chart。
使用Perl更新包含图表的现有文件并不容易(除了在Windows上使用Win32 :: OLE),因此我建议每周生成Excel工作簿。