简体   繁体   中英

xlsxwriter & xlrd issue - xlsx file saved as ZIP on one machine, but with other first 4 bytes on another

I'm using xlsxwriter with .xlsx files, because I intend to write huge data, that isn't supported by .xls and here is what I'm doing at first:

output_name = "MY_XLSX_LOG_FILE" + str(datetime.now().strftime('%Y-%m-%d %H.%M.%S')) + '.xlsx'
xlsx_document = xlsxwriter.Workbook(output_name)
xlsx_document_sheet = xlsx_document.add_worksheet('sheet_1')
xlsx_document_sheet.write(0, 0, 'Col1')
xlsx_document_sheet.write(0, 1, 'Col2')
xlsx_document_sheet.write(0, 2, 'Col3')
xlsx_document_sheet.write(0, 3, 'Col4')
xlsx_document_sheet.write(0, 4, 'Col5')
xlsx_document_sheet.write(0, 5, 'Col6')
xlsx_document_sheet.write(0, 6, 'Col7')
xlsx_document_sheet.write(0, 7, 'Col8')
xlsx_document_sheet.write(0, 8, 'Col9')
xlsx_document.close()

Then I open it like this:

file_name = FindLastLog() #this finds it successfuly
xlsx_document = xlrd.open_workbook(file_name)

With me it works perfectly, but when I give it to someone else and he runs it on his machine(same OS, same locale), he gets this:

XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '\x11MyName'

'MyName' - I have absolutely no idea how this is written in the xlsx file. The exception is raised in function getbof in function open_workbook_xls . On my machine, the code never enters there. At the place where it's checked if the first 4 bytes are b"PK\\x03\\x04" , mine checks true and branches to xlsx.open_workbook_2007_xml , while his branches to xlsx.open_workbook_xls . We're both on Python 2.7 and I don't understand the exact same identical xlsxwriter script is writing a different file format. What could be causing this?

Your colleague probably has an older version of xlrd that doesn't support xlsx files. If they update to the latest version or the version you have it will fix the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM