我已经开始使用 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');