Test::Excel - Interface to test and compare Excel files.
Version 1.24
Test::Excel has been granted the "Famous Software Award" by Download.FamousWhy.com on Wed 17 Nov 2010.
http://download.famouswhy.com/test_excel/
This module is meant to be used for testing custom generated Excel files, it provides two functions at the moment, which is cmp_excel and compare_excel. These can be used to compare_excel 2 Excel files to see if they are visually similar. The function cmp_excel is for testing purpose where function compare_excel can be used as standalone.
cmp_excel
compare_excel
The new paramter has been added to both method cmp_excel() and method compare_excel() called RULE. This is optional, however, this would allow to apply your own rule for comparison. This should be passed in as a reference to a HASH with the keys sheet, tolerance, sheet_tolerance and optionally swap_check, error_limit and message (only relevant to method cmp_excel()).
+-----------------+---------------------------------------------------------------------+ | Key | Description | +-----------------+---------------------------------------------------------------------+ | sheet | "|" seperated sheet names. | | tolerance | Number. Apply to all NUMBERS except on 'sheet'/'spec'. e.g. 10**-12 | | sheet_tolerance | Number. Apply to sheets/ranges in the spec. e.g. 0.20 | | spec | Path to the specification file. | | swap_check | Number (optional) (1 or 0). Row swapping check. Default is 0. | | error_limit | Number (optional). Limit error per sheet. Default is 0. | | message | String (optional). Only required when calling method cmp_excel(). | +-----------------+---------------------------------------------------------------------+
This module uses the Spreadsheet::ParseExcel module to parse Excel files, then compares the parsed data structure for differences. We ignore cetain components of the Excel file, such as embedded fonts, images, forms and annotations, and focus entirely on the layout of each Excel page instead. Future versions will likely support font and image comparisons, but not in this initial release.
Spreadsheet::ParseExcel
This function will tell you whether the two Excel files are "visually" different, ignoring differences in embedded fonts/images and metadata. Both $got and $exp can be either instances of Spreadsheet::ParseExcel / file path (which is in turn passed to the Spreadsheet::ParseExcel constructor). This one is for use in TEST MODE.
use strict; use warnings; use Test::More no_plan => 1; use Test::Excel; cmp_excel('foo.xls', 'bar.xls', { message => 'EXCELSs are identical.' }); # or my $foo = Spreadsheet::ParseExcel::Workbook->Parse('foo.xls'); my $bar = Spreadsheet::ParseExcel::Workbook->Parse('bar.xls'); cmp_excel($foo, $bar, { message => 'EXCELs are identical.' });
This function will tell you whether the two Excel files are "visually" different, ignoring differences in embedded fonts/images and metadata. Both $got and $exp can be either instances of Spreadsheet::ParseExcel / file path (which is in turn passed to the Spreadsheet::ParseExcel constructor). This one is for use in STANDALONE MODE.
use strict; use warnings; use Test::Excel; print "EXCELs are identical.\n" if compare_excel("foo.xls", "bar.xls");
This method parse specification file provided by the user. It expects spec file to be in a format mentioned below. Key and values are space seperated.
sheet Sheet1 range A3:B14 range B5:C5 sheet Sheet2 range A1:B2 ignorerange B3:B8
They are grouped as sheet followed by one or more ranges.
use strict; use warnings; use Test::Excel; my $data = Test::Excel::parse('spec-1.txt');
This method accepts a cell address and returns column and row address as a list.
use strict; use warnings; use Test::Excel; my $cell = 'A23'; my ($col, $row) = Test::Excel::column_row($cell);
This method accepts a letter and returns back its equivalent number. This simply wraps around Spreadsheet::ParseExcel::Utility::col2int().
use strict; use warnings; use Test::Excel; my $number = Test::Excel::letter_to_number('AB');
This number accepts a number and returns its equivalent letter. This simply wraps around Spreadsheet::ParseExcel::Utility::int2col().
use strict; use warnings; use Test::Excel; my $letter = Test::Excel::number_to_letter(27);
This method accepts address range and returns all cell address within the range.
use strict; use warnings; use Test::Excel; my $range = 'A1:B3'; my $cells = Test::Excel::cells_within_range($range);
Debug mode can be turned on or off by setting package variable $DEBUG, for example,
$Test::Excel::DEBUG = 1;
You can set it anything greater than 1 for fine grained debug information. i.e.
$Test::Excel::DEBUG = 2;
It should be clearly noted that this module does not claim to provide a fool-proof comparison of generated Excels. In fact there are still a number of ways in which I want to expand the existing comparison functionality. This module is actively being developed for a number of projects I am currently working on, so expect many changes to happen. If you have any suggestions/comments/questions please feel free to contact me.
Testing of large Excels can take a long time, this is because, well, we are doing a lot of computation. In fact, this module test suite includes tests against several large Excels, however I am not including those in this distibution for obvious reasons.
None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it. This is still a very early version, so it is always possible that I have just "gotten it wrong" in some places.
Mohammad S Anwar, <mohammad.anwar@yahoo.com>
Copyright 2010-2011 by Mohammad S Anwar.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To install Test::Excel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Excel
CPAN shell
perl -MCPAN -e shell install Test::Excel
For more information on module installation, please visit the detailed CPAN module installation guide.