gpt4 book ai didi

python - Openpyxl 无法读取 xlsx 文件,但如果我保存文件,它会打开

转载 作者:行者123 更新时间:2023-12-03 23:43:48 28 4
gpt4 key购买 nike

所以,我尝试用 openpyxl 用这一行打开一个 excel 文件wb_bs = openpyxl.load_workbook(filename=filepath)并得到这个错误:


C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\styles\stylesheet.py:214: UserWarning: Workbook contains no default style, apply openpyxl's default
warn("Workbook contains no default style, apply openpyxl's default")
Traceback (most recent call last):
wb_bs = openpyxl.load_workbook(filename=url_nova, data_only=True)
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\reader\excel.py", line 315, in load_workbook
reader.read()
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\reader\excel.py", line 280, in read
self.read_worksheets()
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\reader\excel.py", line 228, in read_worksheets
ws_parser.bind_all()
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\worksheet\_reader.py", line 434, in bind_all
self.bind_cells()
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\worksheet\_reader.py", line 337, in bind_cells
for idx, row in self.parser.parse():
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\worksheet\_reader.py", line 149, in parse
obj = prop[1].from_tree(element)
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
obj = desc.expected_type.from_tree(el)
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 103, in from_tree
return cls(**attrib)
TypeError: __init__() got an unexpected keyword argument 'address'
PS C:\Users\T-Gamer\Python programs\cmtrat\Cmtrat Helper> & C:/Users/T-Gamer/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/T-Gamer/Python programs/cmtrat/Cmtrat Helper/excel_scripts/ostest.py"
C:\Users\T-Gamer\Python programs\cmtrat\Cmtrat Helper\excel_scripts\copias\diario_padrao.xlsx
C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\styles\stylesheet.py:214: UserWarning: Workbook contains no default style, apply openpyxl's default
warn("Workbook contains no default style, apply openpyxl's default")
Traceback (most recent call last):
wb_bs = openpyxl.load_workbook(filename=url_nova, data_only=True)
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\reader\excel.py", line 315, in load_workbook
reader.read()
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\reader\excel.py", line 280, in read
self.read_worksheets()
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\reader\excel.py", line 228, in read_worksheets
ws_parser.bind_all()
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\worksheet\_reader.py", line 434, in bind_all
self.bind_cells()
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\worksheet\_reader.py", line 337, in bind_cells
for idx, row in self.parser.parse():
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\worksheet\_reader.py", line 149, in parse
obj = prop[1].from_tree(element)
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
obj = desc.expected_type.from_tree(el)
File "C:\Users\T-Gamer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 103, in from_tree
return cls(**attrib)
TypeError: __init__() got an unexpected keyword argument 'address'
事情是:
  • 如果我创建 .xlsx 文件,它会打开
  • 如果我从这个特定来源(我需要的那个)下载文件并尝试立即打开它,它会产生错误。
  • 如果我在打开并保存 .xlsx 文件(无更改)后运行代码,它就可以工作。

  • 我想这与excel版本冲突有关,但我已经尝试了一切,似乎没有任何效果。
    openpyxl==3.0.5
    python ==3.8.5

    最佳答案

    这似乎是关于某些 Excel 文件的 Openpyxl 错误,此处报告:https://foss.heptapod.net/openpyxl/openpyxl/-/issues/1071
    不幸的是,看起来没有解决方法,只有您找到的解决方法:

    In the just released version of Excel (Version 1803 (Build 9126.2259 Click-to-Run)), Microsoft has modified the way hyperlinks are stored in Excel files. As a workaround, you could try opening and re-saving the file in Google Sheets or LibreOffice. I am experiencing similar issues with data validation.
    Source

    关于python - Openpyxl 无法读取 xlsx 文件,但如果我保存文件,它会打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64126185/

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