#!/usr/bin/perl -w ############################################################################### # # A test for Spreadsheet::WriteExcelXML. # # Tests cell comments. # # reverse('©'), April 2005, John McNamara, jmcnamara@cpan.org # use strict; use Spreadsheet::WriteExcelXML; use Test::More tests => 8; ############################################################################## # # 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(); my $format = $workbook->add_format(fg_color => 'yellow', border => 6); $worksheet->set_column('B:B', 18); # Ordinary string $worksheet->write ('B2', 'Hello'); # Ordinary string (Html to be escaped) $worksheet->write ('B3', 'Some bold'); # Ordinary string with format (Html to be escaped) $worksheet->write ('B4', 'Some bold', $format); # Html string $worksheet->write_html_string('B5', 'Some bold'); # Html string with format $worksheet->write_html_string('B6', 'Some bold', $format); # Html string (undocumented extra parameter) $worksheet->write ('B7', 'Some bold', undef, 1); # Html string (undocumented extra parameter) $worksheet->write ('B8', 'Some bold', $format, 1); $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); my $cell = "B2"; for my $i (0 .. @test_data -1) { is($swex_data[$i],$test_data[$i], " \tTesting Html strings: ". $cell++); } ############################################################################## # # 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/]) { $in_cell = 0; #$cell =~ s{>.*}{>}; #$cell =~ s{/>$}{>}; push @cells, $cell; $cell = ''; } } return @cells; } # The following data was generated by Excel. __DATA__ Hello Some <B>bold</B> Some <B>bold</B> Some bold Some bold Some bold Some bold
False False