XLWings - app.display_alerts = False 不抑制错误的公式错误信息

XLWings - app.display_alerts = False not suppressing bad formula error message

我正在使用 Python 3.8.3 和 XLWings 0.19.5。我正在尝试直接在工作簿中编写 try...catch while 运行 excel 方程,但具有某些错误的方程导致应用程序挂起。我认为这是由于弹出了一个消息框。

import xlwings as xw

appExcel = xw.apps.add()
appExcel.display_alerts = False
appExcel.screen_updating = False

wbEquation = xw.Book()
wbEquation.sheets.add(name='Calculate')
wsEquation = wbEquation.sheets['Calculate']

badFormula = "=A1+(A2+A3"

 try:
    wsEquation.range('B1').formula = badFormula
 except Exception:
    appExcel.quit()
    raise Exception("There was an error when running the equation.")

使用 display_alerts=False 我不确定为什么它挂在 wsEquation.range('B1').formula = badFormula 行上,我相信是由于 There is a problem with a formula 错误。在 XLWings 0.10.0 的旧版本上,我是 运行 当我尝试执行此等式时,它不会挂断并越过错误消息。

*编辑:所以我测试了两个版本之间的 which version exactly breaks it and I was able to keep it working through 0.11.5. Upgrading to 0.11.6 broke it. I do not see anything in the release notes,这表明为什么会这样。

所以现在我正在通过回滚到 0.11.5:

来修复
pip install "XLWings==0.11.5"

我已经提交了错误报告:link 它被标记为 bug 所以我认为他们会处理它。