Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification to enable producing consistent binary output #495

Merged
merged 2 commits into from Apr 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions xlsxwriter/workbook.py
Expand Up @@ -10,10 +10,11 @@
import re
import os
import operator
import time
import warnings
from warnings import warn
from datetime import datetime
from zipfile import ZipFile, ZIP_DEFLATED
from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED
from struct import unpack

from .compatibility import int_types, num_types, str_types, force_unicode
Expand Down Expand Up @@ -626,13 +627,19 @@ def _store_workbook(self):
# Add XML sub-files to the Zip file with their Excel filename.
for os_filename, xml_filename, is_binary in xml_files:
if self.in_memory:

zipinfo = ZipInfo(xml_filename, (1980, 1, 1, 0, 0, 0))
if is_binary:
xlsx_file.writestr(xml_filename, os_filename.getvalue())
xlsx_file.writestr(zipinfo, os_filename.getvalue())
else:
xlsx_file.writestr(xml_filename,
xlsx_file.writestr(zipinfo,
os_filename.getvalue().encode('utf-8'))
else:
# The files are tempfiles.

timestamp = time.mktime((1980, 1, 1, 0, 0, 0, 0, 0, 0))
os.utime(os_filename, (timestamp, timestamp))

xlsx_file.write(os_filename, xml_filename)
os.remove(os_filename)

Expand Down