gpt4 book ai didi

python - 无法加载 xlsx 文件

转载 作者:行者123 更新时间:2023-11-30 23:24:10 28 4
gpt4 key购买 nike

我正在尝试使用 python openpyxl 读取附加的 xlsx ( Click here to download ) 文件。但是,无法加载工作簿。这是我尝试在 python 中打开 xlsx 文件 -

>>> from openpyxl import load_workbook
>>> workbook = load_workbook(filename = "test.xlsx")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\openpyxl\reader\excel.py", line 136, in load_workbook
_load_workbook(wb, archive, filename, use_iterators, keep_vba)
File "C:\Python27\lib\site-packages\openpyxl\reader\excel.py", line 198, in _load_workbook
keep_vba=keep_vba)
File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 332, in read_worksheet
fast_parse(ws, xml_source, string_table, style_table, color_index)
File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 320, in fast_parse
parser.parse()
File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 137, in parse
dispatcher[tag_name](element)
File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 176, in parse_merge
self.ws.merge_cells(mergeCell.get('ref'))
File "C:\Python27\lib\site-packages\openpyxl\worksheet.py", line 815, in merge_cells
raise InsufficientCoordinatesException(msg)
openpyxl.shared.exc.InsufficientCoordinatesException: Range must be a cell range (e.g. A1:E1)

最佳答案

您的 .xlsx 文件似乎已损坏或永久损坏。原因可能有很多。其中之一可能是您可能已将文件的扩展名重命名为 .xlsx,这将使该文件无效。要确认此行为,请尝试在 Microsoft Excel 中打开此文件。

我尝试通过 openpyxlxlrdpandas 读取文件,但它们都不起作用。

>>> import xlrd
>>> xlrd.open_workbook('test.xlsx')
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '<html> <'


>>> from openpyxl import load_workbook
>>> workbook = load_workbook(filename = "test.xlsx")
InvalidFileException: File is not a zip file

>>> import pandas
>>> pandas.ExcelFile('test.xlsx')
InvalidFileException: File is not a zip file

关于python - 无法加载 xlsx 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23603674/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com