1############################################################################### 2# 3# Tests the output of Excel::Writer::XLSX against Excel generated files. 4# 5# Copyright 2000-2021, John McNamara, jmcnamara@cpan.org 6# 7 8use lib 't/lib'; 9use TestFunctions qw(_compare_xlsx_files _is_deep_diff); 10use strict; 11use warnings; 12 13use Test::More tests => 1; 14 15############################################################################### 16# 17# Tests setup. 18# 19my $filename = 'chart_format12.xlsx'; 20my $dir = 't/regression/'; 21my $got_filename = $dir . "ewx_$filename"; 22my $exp_filename = $dir . 'xlsx_files/' . $filename; 23 24my $ignore_members = []; 25 26my $ignore_elements = { 'xl/charts/chart1.xml' => ['<c:pageMargins'] }; 27 28 29############################################################################### 30# 31# Test the creation of an Excel::Writer::XLSX file with chart formatting. 32# 33use Excel::Writer::XLSX; 34 35my $workbook = Excel::Writer::XLSX->new( $got_filename ); 36my $worksheet = $workbook->add_worksheet(); 37my $chart = $workbook->add_chart( type => 'line', embedded => 1 ); 38 39# For testing, copy the randomly generated axis ids in the target xlsx file. 40$chart->{_axis_ids} = [ 54794880, 56296576 ]; 41 42 43my $data = [ 44 [ 1, 2, 3, 4, 5 ], 45 [ 2, 4, 6, 8, 10 ], 46 [ 3, 6, 9, 12, 15 ], 47 48]; 49 50$worksheet->write( 'A1', $data ); 51 52$chart->add_series( 53 categories => '=Sheet1!$A$1:$A$5', 54 values => '=Sheet1!$B$1:$B$5', 55 trendline => { 56 type => 'moving_average', 57 period => 2, 58 line => { 59 color => 'red', 60 width => 1, 61 dash_type => 'long_dash', 62 }, 63 }, 64); 65 66$chart->add_series( 67 categories => '=Sheet1!$A$1:$A$5', 68 values => '=Sheet1!$C$1:$C$5', 69); 70 71$worksheet->insert_chart( 'E9', $chart ); 72 73$workbook->close(); 74 75 76############################################################################### 77# 78# Compare the generated and existing Excel files. 79# 80 81my ( $got, $expected, $caption ) = _compare_xlsx_files( 82 83 $got_filename, 84 $exp_filename, 85 $ignore_members, 86 $ignore_elements, 87); 88 89_is_deep_diff( $got, $expected, $caption ); 90 91 92############################################################################### 93# 94# Cleanup. 95# 96unlink $got_filename; 97 98__END__ 99 100 101 102