|
| 1 | +############################################################################### |
| 2 | +# |
| 3 | +# Tests the output of Excel::Writer::XLSX against Excel generated files. |
| 4 | +# |
| 5 | +# Copyright 2000-2025, John McNamara, jmcnamara@cpan.org |
| 6 | +# |
| 7 | +# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later |
| 8 | +# |
| 9 | + |
| 10 | +use lib 't/lib'; |
| 11 | +use TestFunctions qw(_compare_xlsx_files _is_deep_diff); |
| 12 | +use strict; |
| 13 | +use warnings; |
| 14 | + |
| 15 | +use Test::More tests => 1; |
| 16 | + |
| 17 | +############################################################################### |
| 18 | +# |
| 19 | +# Tests setup. |
| 20 | +# |
| 21 | +my $filename = 'table37.xlsx'; |
| 22 | +my $dir = 't/regression/'; |
| 23 | +my $got_filename = $dir . "ewx_$filename"; |
| 24 | +my $exp_filename = $dir . 'xlsx_files/' . $filename; |
| 25 | + |
| 26 | +my $ignore_members = []; |
| 27 | +my $ignore_elements = {}; |
| 28 | + |
| 29 | + |
| 30 | +############################################################################### |
| 31 | +# |
| 32 | +# Test the creation of a simple Excel::Writer::XLSX file with tables. |
| 33 | +# |
| 34 | +use Excel::Writer::XLSX; |
| 35 | + |
| 36 | +my $workbook = Excel::Writer::XLSX->new( $got_filename ); |
| 37 | +my $worksheet = $workbook->add_worksheet(); |
| 38 | +my $chart = $workbook->add_chart( type => 'column', embedded => 1 ); |
| 39 | + |
| 40 | +$worksheet->write(1, 0, 1); |
| 41 | +$worksheet->write(2, 0, 2); |
| 42 | +$worksheet->write(3, 0, 3); |
| 43 | +$worksheet->write(4, 0, 4); |
| 44 | +$worksheet->write(5, 0, 5); |
| 45 | + |
| 46 | +$worksheet->write(1, 1, 10); |
| 47 | +$worksheet->write(2, 1, 15); |
| 48 | +$worksheet->write(3, 1, 20); |
| 49 | +$worksheet->write(4, 1, 10); |
| 50 | +$worksheet->write(5, 1, 15); |
| 51 | + |
| 52 | +# Set the column width to match the target worksheet. |
| 53 | +$worksheet->set_column('A:B', 10.288); |
| 54 | + |
| 55 | +# For testing, copy the randomly generated axis ids in the target xlsx file. |
| 56 | +$chart->{_axis_ids} = [ 88157568, 89138304 ]; |
| 57 | + |
| 58 | +$chart->add_series( |
| 59 | + name => '=Sheet1!$B$1', |
| 60 | + categories => '=Sheet1!$A$2:$A$6', |
| 61 | + values => '=Sheet1!$B$2:$B$6', |
| 62 | +); |
| 63 | + |
| 64 | +$chart->set_title( none => 1 ); |
| 65 | + |
| 66 | +$worksheet->insert_chart( 'E9', $chart ); |
| 67 | + |
| 68 | +# Add the table. |
| 69 | +$worksheet->add_table('A1:B6'); |
| 70 | + |
| 71 | + |
| 72 | +$workbook->close(); |
| 73 | + |
| 74 | + |
| 75 | +############################################################################### |
| 76 | +# |
| 77 | +# Compare the generated and existing Excel files. |
| 78 | +# |
| 79 | + |
| 80 | +my ( $got, $expected, $caption ) = _compare_xlsx_files( |
| 81 | + |
| 82 | + $got_filename, |
| 83 | + $exp_filename, |
| 84 | + $ignore_members, |
| 85 | + $ignore_elements, |
| 86 | +); |
| 87 | + |
| 88 | +_is_deep_diff( $got, $expected, $caption ); |
| 89 | + |
| 90 | + |
| 91 | +############################################################################### |
| 92 | +# |
| 93 | +# Cleanup. |
| 94 | +# |
| 95 | +unlink $got_filename; |
| 96 | + |
| 97 | +__END__ |
| 98 | +
|
| 99 | +
|
| 100 | +
|
0 commit comments