从 perl Excel 数据中的给定 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');