簡體   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

我正在將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()

然后我像這樣打開它:

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

對於我來說,它工作得很好,但是當我將它提供給其他人並在他的機器上運行時(相同的操作系統,相同的語言環境),他得到了:

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

'MyName'我完全不知道如何將其寫入xlsx文件中。 在函數getbof中的open_workbook_xls函數中getbofopen_workbook_xls 在我的機器上,代碼永遠不會輸入那里。 在檢查前4個字節是否為b"PK\\x03\\x04" ,我的檢查為true並分支到xlsx.open_workbook_2007_xml ,而他的分支到xlsx.open_workbook_xls 我們都在Python 2.7 ,我不明白完全相同的xlsxwriter腳本正在編寫不同的文件格式。 是什么原因造成的?

您的同事可能具有不支持xlsx文件的xlrd較舊版本。 如果他們更新到最新版本或您擁有的版本,它將解決此問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM