The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Test::Excel - A module for testing and comparing Excel files

SYNOPSIS

  use Test::More no_plan => 1;
  use Test::Excel;
  
  cmp_excel('foo.xls', 'bar.xls', 'EXCELSs are identical.');
  
  # or
  
  my $foo = Spreadsheet::ParseExcel::Workbook->Parse('foo.xls');
  my $bar = Spreadsheet::ParseExcel::Workbook->Parse('bar.xls');
  cmp_excel($foo, $bar, 'EXCELs are identical.');
  
  # or even in standalone mode:
  
  use Test::Excel;
  print "EXCELs are identical.\n"
          if compare_excel("foo.xls", "bar.xls");

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 two 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. Future versions may include other testing functions.

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.

Important Disclaimer

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.

FUNCTIONS

cmp_excel($got, $expected, ?$message)

This function will tell you whether the two Excel files are "visually" different, ignoring differences in embedded fonts/images and metadata.

Both $got and $expected can be either instances of Spreadsheet::ParseExcel or a file path (which is in turn passed to the Spreadsheet::ParseExcel constructor).

compare_excel($got, $expected)

This function will tell you whether the two Excel files are "visually" different, ignoring differences in embedded fonts/images and metadata in standalone mode.

Both $got and $expected can be either instances of Spreadsheet::ParseExcel or a file path (which is in turn passed to the Spreadsheet::ParseExcel constructor).

CAVEATS

Testing Large Excels

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.

TO DO

More functions for more testing
Testing of font data
Testing of embedded image data

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).
Stevan Little (author of Test::PDF).

AUTHOR

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

COPYRIGHT AND LICENSE

Copyright 2010 by Mohammad S Anwar.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.