在Windows窗体中与Ironpython一起使用xlrd
我对Windows窗体和Ironpython非常陌生,我必须连接一个python脚本,该脚本读取excel文件的列值,并将列表返回到Windows窗体,因此我为此编写了一个类:在Windows窗体中与Ironpython一起使用xlrd,python,c#,visual-studio,winforms,ironpython,Python,C#,Visual Studio,Winforms,Ironpython,我对Windows窗体和Ironpython非常陌生,我必须连接一个python脚本,该脚本读取excel文件的列值,并将列表返回到Windows窗体,因此我为此编写了一个类: class Python_Script { private ScriptEngine engine; private ScriptScope scope; private ScriptSource source; public Python_Scri
class Python_Script
{
private ScriptEngine engine;
private ScriptScope scope;
private ScriptSource source;
public Python_Script(string name)
{
engine = Python.CreateEngine();
scope = engine.CreateScope();
string str = @"script_route" + name;
engine.ExecuteFile(@str, scope);
}
public List<string> Col_Values(int sheet, int col)
{
List<string> result;
dynamic col_values = scope.GetVariable("Col_Values");
result = col_values(sheet, col);
return result;
}
但是当我运行代码时,我得到了错误:
IronPython.Runtime.Exceptions.ImportException:“没有名为xlrd的模块”
我不知道如何在Ironpython中安装xlrd模块,我是使用命令promt for python 3.8安装的,我在visual strudio中的python环境告诉我我正在运行python 3.8
public partial class Form2 : Form
{
List<string> test_col = new List<string>();
Python_Script my_py = new Python_Script("script_leer_excel.py");
public Form2()
{
test_col = my_py.Col_Values(0,0);
}
import sys
import xlrd
loc = ("excel_route")
wb = xlrd.open_workbook(loc)
def Col_Values(sheet, col):
sheet = wb.sheet_by_index(sheet)
result = sheet.col_values(col)
return result