I am using is_zipfile
to check if it is a zipfile before extracting it. But the method returns True on excel file from a StringIO object. I am using Python 2.7. Does anyone know how to fix this? Is it reliable to use is_zipfiile
? Thanks.
在提取之前,我使用is_zipfile检查它是否是zipfile。但是该方法在来自StringIO对象的excel文件上返回True。我使用的是Python 2.7。有人知道怎么解决这个问题吗?使用is_zipfiile是否可靠?谢谢。
2 个解决方案
#1
2
Quoting from the Microsoft's XLSX Structure overview doc,
引用微软的XLSX结构概述文档,
Workbook data is contained in a ZIP package conforming to the Open Packaging Conventions
工作簿数据包含在符合开放打包约定的ZIP包中
So, .xlsx
files are actually zip files only. If you want not to consider them as a zip file, you may have to exclude with an if condition like this
所以。xlsx文件实际上只是zip文件。如果您不想将它们视为zip文件,那么您可能需要将其排除在这样的条件下。
if os.path.splitext(filename)[1] != ".xlsx" and zipfile.is_file(filename):
#2
3
This is because xlsx
is actually a valid zip file.
这是因为xlsx实际上是一个有效的zip文件。
See also:
参见:
- Office Open XML
- Office Open XML
- The Microsoft Office XML formats
- Microsoft Office XML格式。
#1
2
Quoting from the Microsoft's XLSX Structure overview doc,
引用微软的XLSX结构概述文档,
Workbook data is contained in a ZIP package conforming to the Open Packaging Conventions
工作簿数据包含在符合开放打包约定的ZIP包中
So, .xlsx
files are actually zip files only. If you want not to consider them as a zip file, you may have to exclude with an if condition like this
所以。xlsx文件实际上只是zip文件。如果您不想将它们视为zip文件,那么您可能需要将其排除在这样的条件下。
if os.path.splitext(filename)[1] != ".xlsx" and zipfile.is_file(filename):
#2
3
This is because xlsx
is actually a valid zip file.
这是因为xlsx实际上是一个有效的zip文件。
See also:
参见:
- Office Open XML
- Office Open XML
- The Microsoft Office XML formats
- Microsoft Office XML格式。