xlwings quickstart python 脚本不工作

问题描述 投票:0回答:0

我尝试使用

VBA
运行 python 脚本,发现
Xlwings
非常有用,如各种博客文章中所述。
我使用我的终端和 excel 加载项安装了 xlwings,并在 VPA 工具部分启用了 xlwings 按钮。

我在终端窗口中使用以下行创建了一个项目:

xlwings quickstart hallo_welt

因此,在各自的文件夹“hallo_welt”中创建了一个 python 脚本和一个 xslm 文件。两者的名称相同。 如果我尝试点击“运行主要”按钮,它没有运行,但返回以下内容

error:Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'hallo_welt'

See also screenshot attached.


python 代码如下所示:
import xlwings as xw


def main():
    wb = xw.Book.caller()
    sheet = wb.sheets[0]
    if sheet["A1"].value == "Hello xlwings!":
        sheet["A1"].value = "Bye xlwings!"
    else:
        sheet["A1"].value = "Hello xlwings!"


if __name__ == "__main__":
    xw.Book("hallo_welt.xlsm").set_mock_caller()
    main()


因此,它应该返回“Hello xlwings!”在单元格 A1 中,我第一次单击“运行主程序”时。

python excel vba xlwings
© www.soinside.com 2019 - 2024. All rights reserved.