pandas openpyxl错误&quot< class' openpyxl.styles.fills.fills.fill'>

发布于 2025-01-29 13:05:43 字数 1490 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧夏天 2025-02-05 13:05:43

我在Github上看到了另一个类似的查询,他们唯一的解决方案是与win32.com Resave或Roll后退Pandas打开。因此,这样的事情可能无需更改版本或单独修改文件就可以解决问题。
提供的示例文件已使用此代码进行了测试。
如果XLSX文件具有 gresent<类'openpyxl.styles.fills.fills.fill'> exception exception在打开时,然后使用xlwings打开并用新名称保存并尝试打开该文件,然后尝试再次使用该文件第二次,允许您阅读数据。

import xlwings as xw
import pandas as pd


path = 'Espelho.xlsx'
path2 = "renamed_" + path

while True:
    try:
        df = pd.read_excel(path, engine='openpyxl')
    except Exception as e:
        print("Failed to open workbook; error: ")
        print(e)
        wingsbook = xw.Book(path)
        wingsapp = xw.apps.active
        wingsbook.save(path2)
        wingsapp.quit()

        path = path2
    else:
        break

for col in df.columns:
    print(col)

I saw another similar query on github and their only solution was to open with win32.com resave or roll back pandas. Therefore something like this may do the trick without having to change versions or separately modify the files.
The example file provided was tested with this code.
If the xlsx file has an expected <class 'openpyxl.styles.fills.Fill'> exception when opening then use xlwings to open and save with new name and try opening the file again which should work second time and allow you to read the data.

import xlwings as xw
import pandas as pd


path = 'Espelho.xlsx'
path2 = "renamed_" + path

while True:
    try:
        df = pd.read_excel(path, engine='openpyxl')
    except Exception as e:
        print("Failed to open workbook; error: ")
        print(e)
        wingsbook = xw.Book(path)
        wingsapp = xw.apps.active
        wingsbook.save(path2)
        wingsapp.quit()

        path = path2
    else:
        break

for col in df.columns:
    print(col)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文