满意答案
nteoane
2016.08.20
采纳率:41% 等级:7
已帮助:362人
打开excel的vba编辑器,敲入以下代码即可:
打开:文件-》导入,加载xlwings.bas进去
编辑function setting文件:
PYTHON_WIN = ""
PYTHON_MAC = ""
PYTHON_FROZEN = ThisWorkbook.Path & "\build\exe.win32-2.7"
PYTHONPATH = ThisWorkbook.Path
UDF_MODULES = ""
UDF_DEBUG_SERVER = False
LOG_FILE = ""
SHOW_LOG = True
OPTIMIZED_CONNECTION = False
编写sub模块运行:
Sub HelloWorld()
RunPython ("import hello; hello.world()")
End Sub
实际调用的方法:
# hello.py
import numpy as np
import xlwings as xw
def world():
wb = xw.Book.caller()
wb.sheets[0].range('A1').value = 'Hello World!'
00分享举报