#!/usr/bin/perl -w ############################################################################### # # A test for Spreadsheet::WriteExcelXML. # # Tests array formulas. # # reverse('©'), July 2004, John McNamara, jmcnamara@cpan.org # use strict; use Spreadsheet::WriteExcelXML; use Test::More tests => 6; ############################################################################## # # Create a new Excel XML file with row data set. # my $test_file = "temp_test_file.xml"; my $workbook = Spreadsheet::WriteExcelXML->new($test_file); my $worksheet = $workbook->add_worksheet(); $worksheet->write('A1', [[500, 10], [300, 15]]); $worksheet->write('A3', '{=SUM(A1:B1*A2:B2)}'); $worksheet->write_array_formula('A4:A4', '{=SUM(A1:B1*A2:B2)}'); $worksheet->write('A6', [[1, 2, 3], [20234, 21003, 10000]]); $worksheet->write_array_formula('C6:C8', '{=TREND(B6:B8,A6:A8)}'); $worksheet->write_array_formula('D6:D8', '=TREND(B6:B8,A6:A8)' ); $worksheet->write_array_formula('E6:E8', 'TREND(B6:B8,A6:A8)' ); $workbook->close(); ############################################################################## # # Re-open and reread the Excel file. # open XML, $test_file or die "Couldn't open $test_file: $!\n"; my @swex_data = extract_cells(*XML); close XML; unlink $test_file; ############################################################################## # # Read the data from the Excel file in the __DATA__ section # my @test_data = extract_cells(*DATA); ############################################################################## # # Check for the same number of elements. # is(@swex_data, @test_data, " \tCheck for data size"); ############################################################################## # # Test that the SWEX elements and Excel are the same. # # Pad the SWEX data if necessary. push @swex_data, ('') x (@test_data -@swex_data); for my $i (0 .. @test_data -1) { is($swex_data[$i],$test_data[$i], " \tTesting ss:ArrayRange attribute"); } ############################################################################## # # Extract elements from a given filehandle. # sub extract_cells { my $fh = $_[0]; my $in_cell = 0; my $cell = ''; my @cells; while (<$fh>) { s/^\s+([<| ])/$1/; s/\s+$//; if (m/.*}{>}; $cell =~ s{/>$}{>}; push @cells, $cell; $cell = ''; } } return @cells; } # The following data was generated by Excel. __DATA__ 500 300 10 15 9500 9500 1 20234 22196 22196 22196 2 21003 17079 17079 17079 3 10000 11961.999999999996 11961.999999999996 11961.999999999996
3 7 4 False False