简体   繁体   English

xlsxwriter和xlrd问题-xlsx文件在另一台计算机上另存为ZIP,在另一台计算机上另存为前4个字节

[英]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: 我正在将xlsxwriter与.xlsx文件一起使用,因为我打算写入海量数据,但.xls不支持,这是我最初要做的事情:

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. 'MyName'我完全不知道如何将其写入xlsx文件中。 The exception is raised in function getbof in function open_workbook_xls . 在函数getbof中的open_workbook_xls函数中getbofopen_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 . 在检查前4个字节是否为b"PK\\x03\\x04" ,我的检查为true并分支到xlsx.open_workbook_2007_xml ,而他的分支到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. 我们都在Python 2.7 ,我不明白完全相同的xlsxwriter脚本正在编写不同的文件格式。 What could be causing this? 是什么原因造成的?

Your colleague probably has an older version of xlrd that doesn't support xlsx files. 您的同事可能具有不支持xlsx文件的xlrd较旧版本。 If they update to the latest version or the version you have it will fix the issue. 如果他们更新到最新版本或您拥有的版本,它将解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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