I am pretty new to Windows Forms and Ironpython and I have to connect a python script that reads the column values of an excel file and returns a list to a windows Form, so I did a class for doing so:
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;
}
And when mi form is initialized I do this:
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);
}
This is my python script
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
But when I run the code I get the error: IronPython.Runtime.Exceptions.ImportException: 'No module named xlrd'
I have no idea on how to install the xlrd module in Ironpython, I installed it with the command promt for python 3.8 and my python enviroment in visual strudio tells me I am running python 3.8 Visual studio python enviroment