Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is binary identical output possible with XlsxWriter?

Tags:

xlsxwriter

With the same input is it possible to make the output binary identical using XlsxWriter?

I tried changing the created property to the same date and that helped a little. Still get a lot of differences in sharedStrings.xml.

Thanks

like image 621
Jonas Avatar asked Dec 15 '25 03:12

Jonas


1 Answers

Yes for identical input, if you set the created date in the worksheet properties:

import xlsxwriter
import datetime

for filename in ('hello1.xlsx', 'hello2.xlsx'):
    workbook = xlsxwriter.Workbook(filename)
    workbook.set_properties({'created': datetime.date(2016, 4, 25)})

    worksheet = workbook.add_worksheet()
    worksheet.write('A1', 'Hello world')
    workbook.close()

Then:

$ cmp hello1.xlsx hello2.xlsx

# No output. Files are the same.

The order in which strings are added to the file will change the layout of the sharedStrings table and thus lead to non-identical files. That is generally the case with Excel as well.

Note: This requires XlsxWriter version 1.0.4 or later to work.

like image 100
jmcnamara Avatar answered Dec 16 '25 23:12

jmcnamara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!