Im creating a Windows Forms Project based on C# using python scripts. But when click the button, which should start a python script i have an error “No module named ‘openpyxl'”
private void Save_Click(object sender, EventArgs e)
{
StreamWriter fs = new StreamWriter("TxtData.txt", false);
for (int i = 0; i < data.Length; i++)
{
if (i == 2)
{
fs.WriteLine(today);
}
else
{
fs.WriteLine(data[i]);
}
}
fs.Close();
Console.WriteLine("Saved");
var engine = Python.CreateEngine();
var scope = engine.CreateScope();
engine.ExecuteFile("MainData.py", scope); //Right here
dynamic load_mas = scope.GetVariable("load_mas");
dynamic saved = load_mas();
}
And this is my ython code:
from openpyxl import load_workbook
Pydata = [" ", " ", " ", " ", "Нет данных", "Нет данных", " ", " ", " ",]
# 1 - Справ№, 2 - Рев, 3 - Дата, 4 - Заказчик, 5 - Потребитель, 6 - Проект, 7 - Установка, 8 - Проектант
helper = 7
def load_mas():
with open('TxtData.txt') as f:
for i in range(0, 9):
Pydata[i] = f.readline()
def save_table():
wb = load_workbook(filename = r'C:UsersElisey KartavyyDocumentsШколаООПVisual StudioNTVALVEShablon.xlsx', data_only = True)
sheet = wb['Лист1']
for i in range(len(Pydata)):
index = 'D' + str(helper)
sheet[index].value = Pydata[i]
helper += 1
wb.save('Shablon.xlsx')
Ive alredy installed openpyxl using pip and IronPython into the Visual Studio 2020
New contributor
Елисей Картавый is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.