Test::Excel - Interface to test and compare Excel files (.xls/.xlsx).
Version 1.42
This module is meant to be used for testing custom generated Excel files, it provides interfaces to compare_excel two Excel files if they are visually same. It now supports Excel file with extension .xls and .xlsx.
.xls
.xlsx
Using as unit test as below:
use strict; use warnings; use Test::More tests => 2; use Test::Excel; cmp_excel_ok("1.xls", "1.xls"); cmp_excel_not_ok("1.xls", "2.xls"); done_testing();
Using as standalone as below:
use strict; use warnings; use Test::Excel; if (compare_excel("1.xls", "1.xls")) { print "Excels are similar.\n"; } else { print "Excels aren't similar.\n"; }
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::Read / file path (which is in turn passed passed to the Spreadsheet::Read constructor). This one is for use in TEST MODE.
use strict; use warnings; use Test::More tests => 1; use Test::Excel; cmp_excel('foo.xls', 'bar.xls', {}, 'EXCELs are identical.'); done_testing();
Test OK if excel files are identical. Same as cmp_excel().
Test OK if excel files are NOT 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::Read / file path (which in turn passed to the Spreadsheet::Read constructor).
$got
$exp
use strict; use warnings; use Test::Excel; print "EXCELs are identical.\n" if compare_excel("foo.xls", "bar.xls");
The paramter rule can be used optionally to apply exception when comparing the contents. This should be passed in as has ref and may contain keys from the table below.
rule
+-----------------+---------------------------------------------------------+ | 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. | +-----------------+---------------------------------------------------------+
Spec file containing rules used should be in the 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
This module uses the Spreadsheet::Read module to parse the Excel files, then compares the parsed data structure for differences.We ignore certain 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.
By turning the environment variable DEBUG ON would spit out PASS/FAIL comparison.
e.g. $ $DEBUG=1 perl your_script.pl
It should be clearly noted that this module does not claim to provide 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 no longer actively being developed as I moved to another company.This work was part of one of my project. Having said, I would be more than happy to add new features if its requested. Any suggestions / ideas most welcome.
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 would do my best 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 at yahoo.com>
<mohammad.anwar at yahoo.com>
https://github.com/manwar/Test-Excel
Please report any bugs or feature requests to bug-test-excel at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Excel. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-test-excel at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Test::Excel
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Excel
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Test-Excel
CPAN Ratings
http://cpanratings.perl.org/d/Test-Excel
Search CPAN
http://search.cpan.org/dist/Test-Excel/
Copyright (C) 2010 - 2016 Mohammad S Anwar.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License.By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made by someone other than you,you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement,then this Artistic License to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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.