在 python 中解压 .xls 文件

Decompress .xls file in python

我正在寻找 python 中 decompress/unzip .xls 文件的方法。通过使用 7-Zip 打开 Excel 个文件,您可以看到我想要提取的目录。

我已经尝试过将 Excel 重命名为“.zip”然后解压

myExcelFile = zipfile.ZipFile("myExcel.zip") 
myExcelFile.extractall()

但它抛出

zipfile.BadZipFile: File is not a zip file

.xls in 7-Zip

.xls files use the BIFF format. .xlsx files use Office Open XML, which is a zipped XML format. BIFF is not a zipped format; files using that format are not recognized by zip libraries. – shmee

转换为 .xlsx 是 solution

import win32com.client as win32
fname = "full+path+to+xls_file"
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(fname)

wb.SaveAs(fname+"x", FileFormat = 51)    #FileFormat = 51 is for .xlsx extension
wb.Close()                               #FileFormat = 56 is for .xls extension
excel.Application.Quit()