jmcnamara/excel-writer-xlsx

files created the same way with same contents differ

spz1st opened this issue · 2 comments

How two files created the same way differ from each other as reported by the diff commander? I just created files with the following codes, they're all different as reported by diff (while their sizes are the same). Is it possible to create identical files with the same contents with the same script? It's desirable in some cases if one wants to know if two files created by the same script executed in the same way have the same contents. Right now when the command diff reports two files with the same size are different, I can't tell whether or not the data/contents in the files are different.

use Excel::Writer::XLSX;
$wb = Excel::Writer::XLSX->new("test.xlsx");
$ws = $wb->add_worksheet();
$wb->close();

Hi,

Excel files contain metadata about the creation date/time of the file which means that 2 files that are exactly the same but that are saved 1 second or more apart will be binary different.

You can avoid this be setting a fixed file creation date such as 2022-01-01 using the workbook set_properties method:

use Excel::Writer::XLSX;

my $workbook  = Excel::Writer::XLSX->new( 'properties.xlsx' );
my $worksheet = $workbook->add_worksheet();

$workbook->set_properties(created  => [ 0, 0, 0, 1, 1, 122 ]);

$workbook->close();

See the following for more information:

https://metacpan.org/pod/Excel::Writer::XLSX#set_properties()

https://metacpan.org/release/JMCNAMARA/Excel-Writer-XLSX-1.09/source/examples/properties.pl