I have created an Excel file using openpyxl library. Then, I decided to get the checksum of the generated file. I have used md5 and it returns the hash value (say XYZ). So far so good
After that, I re-generated the file again, but this time I have got a hash value which is not XYZ. I have used the same seed data to generate the files and the script returns different hash values each time.
Why this is happening?
Environment
- Python==3.6
- openpyxl==3.0.3
minimal verifiable example
import datetime
import hashlib
from openpyxl import Workbook
def get_file_hash(filename):
with open(filename, 'rb') as file_to_hash:
return hashlib.md5(file_to_hash.read()).hexdigest()
work_book = Workbook()
work_sheet = work_book.active
sample_data = [{'name': 'Matthew Morales',
'address': '3539 Knight Plaza\nSmithland, OR 76492',
'zipcode': '85464',
'num': 0,
'datetime': datetime.datetime(2018, 10, 24, 15, 33, 54),
'float': 0.12,
'bool': True},
{'name': 'Jack Jones',
'address': 'Unit 7284 Box 4842\nDPO AE 66772',
'zipcode': '08425',
'num': 1,
'datetime': datetime.datetime(2018, 10, 24, 15, 33, 54),
'float': 1.12,
'bool': True},
{'name': 'Jennifer Higgins',
'address': 'Unit 6492 Box 6602\nDPO AP 86505',
'zipcode': '72306',
'num': 2,
'datetime': datetime.datetime(2018, 10, 24, 15, 33, 54),
'float': 2.12,
'bool': True},
]
field_names = list(sample_data[0])
for column_index, field_name in enumerate(field_names, 1): # writing header
work_sheet.cell(1, column_index, field_name)
for row_index, data in enumerate(sample_data, 2):
for column_index, field_name, in enumerate(data, 1):
work_sheet.cell(row_index, column_index, data[field_name])
mve_file_name = 'mve_xlsx_file.xlsx'
work_book.save(mve_file_name)
print(get_file_hash(mve_file_name))