使用(Spreadsheet :: WriteExcel :: Chart)Perl模块中的另一个工作表创建图表

时间:2013-04-12 11:11:15

标签: perl

我已经开始使用Spreadsheet :: WriteExcel :: Chart来编写图表。我有10个包含数据的工作表。我为图表添加了一个工作表。我的问题是,如何使用其他工作表数据创建图表。

2)我还尝试了另一种方法在其中,我创建了新工作表并从旧工作表加载数据,而不是尝试创建图表。

3)在$ data中,我们是硬编码值,有可能我们可以从单元格获取值    比硬编码值 在这两种情况下,我都无法找到解决方案。

use Spreadsheet::ParseExcel;
  use Spreadsheet::WriteExcel;
  use Spreadsheet::ParseExcel::SaveParser;

  # Open the template with SaveParseir
  my $parser   = new Spreadsheet::ParseExcel::SaveParser;
  my $workbook = $parser->Parse('DD1.xls');
  if ( !defined $workbook ) {
        die $parser->error(), ".\n";
    }

  #Create the New worksheet
  my $Flop_workbook = Spreadsheet::WriteExcel->new('Flop.xls'); 
  for my $worksheet ( $workbook->worksheets() ) {
        my ( $row_min, $row_max ) = $worksheet->row_range();
        my ( $col_min, $col_max ) = $worksheet->col_range();

        my $worksheetname         = $worksheet->get_name(); 
        print "worksheetname : ", $worksheetname ,"\n"; 

        my $sheet                 = $Flop_workbook->add_worksheet($worksheetname);

        for my $row ( $row_min .. $row_max ) {
                for my $col ( $col_min .. $col_max ) {
                    my $cell = $worksheet->get_cell( $row, $col );
                    next unless $cell;
                    print "Row, Col    = ($row, $col)\n";
                    print "Value = ", $cell->value, "\n";
                    print "Unformatted = ", $cell->unformatted(), "\n";
                    $sheet->write_string($row,$col,$cell->value);
                    print "\n";
                }
            }
        } 
  my $chartsheet = $Flop_workbook->add_worksheet('Chart_data');
  my $chart     = $Flop_workbook->add_chart( type => 'line' );

  #Configure the chart.
  $chart->add_series(
                    categories => '=SUM_F_SCDLIB_DFF!$I$2',
                    values     => '=SUM_F_SCDLIB_DFF!$I$2',
          ); (Failed here As I need to load another worksheet data)

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

    $chartsheet->write( 'AB5', $data );
    #$template->SaveAs('newfile.xlsx');

0 个答案:

没有答案