Mohammad S Anwar > Test-Excel > Test::Excel

Download:
Test-Excel-1.28.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 1.28   Source  

NAME ^

Test::Excel - Interface to test and compare Excel files.

VERSION ^

Version 1.28

DESCRIPTION ^

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.

RULE ^

The new paramter has been added to both method cmp_excel() & 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 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().   |
    +-----------------+---------------------------------------------------------------------+

SPECIFICATION FILE ^

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

What is "Visually" Similar? ^

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.

METHODS ^

cmp_excel($got, $exp, { ...rule... })

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.' });

compare_excel($got, $exp, { ...rule... })

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");

NOTES ^

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 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.

CAVEATS ^

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.

BUGS ^

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.

SEE ALSO ^

Spreadsheet::ParseExcel - I could not have written this without this module.

ACKNOWLEDGEMENTS ^

John McNamara (author of Spreadsheet::ParseExcel).
Kawai Takanori (author of Spreadsheet::ParseExcel::Utility).
Stevan Little (author of Test::PDF).

AUTHOR ^

Mohammad S Anwar, <mohammad.anwar at yahoo.com>

REPOSITORY ^

https://github.com/Manwar/Test-Excel

BUGS ^

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.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Test::Excel

You can also look for information at:

LICENSE AND COPYRIGHT ^

Copyright (C) 2010 - 2014 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.

syntax highlighting: