本文介绍了如何设置PythonPath/UDF_Modules?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用Xlwings构建自己的Excel函数.

I have been trying to build my own Excel functions using Xlwings.

使用

$ xlwings quickstart myproject

将在与Excel xlsm文件相同的目录中创建Python脚本.

would create a Python script in the same directory as the Excel xlsm file.

我想将Python脚本放在我想要的任何位置,例如"D:\ test0.py",所以我在VBA功能设置上执行了此操作:

I want to put the Python script anywhere I want, like "D:\test0.py", so I did this on VBA Function Settings:

PYTHONPATH = "D:\test0.py"
UDF_MODULES = "test0"

除了这两行外,我在功能设置"中没有进行任何更改.

Except for these two lines, I didn't change anything in Function Settings.

我知道了

如何从"D:\ test0.py"导入模块?

How do I import module from "D:\test0.py"?

推荐答案

PYTHONPATH 是路径,而不是文件,即您应该使用

PYTHONPATH, as the name says, is a path, not a file, i.e. you should be using

PYTHONPATH = "D:\"

xlwings quickstart myproject 仍然很有用,因为即使以后要移出python文件,它也会使用VBA模块设置Excel文件.

xlwings quickstart myproject is still useful because it sets up the Excel file with the VBA module, even if you want to move out the python file later on.

这篇关于如何设置PythonPath/UDF_Modules?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:11
查看更多