怎样在Excel中使用python脚本
1个回答
展开全部
打开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!'
打开:文件-》导入,加载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!'
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询