I want to get the value of input '-Name-' and pass it to value in openpyxl
but the problem is (value = '-name-') openpyxl did not accept it.
test.cell(row=8,column=16).value='-Name-'
import PySimpleGUI as sg
from openpyxl import load_workbook, workbook
wb = load_workbook('test.xlsx')
test = wb.active
layout = [[sg.Text('name of employe')],
[sg.Text('Name', size=(15,1)), sg.InputText(key='-Name-')],
[sg.Button('OK'), sg.Button('Exit')]]
test.cell(row=8,column=16).value='-Name-'
window = sg.Window('title', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
elif event == 'OK':
wb.save('test.xlsx')
window.close()
CodePudding user response:
What you want to save is not the string '-Name-'
, but the content of Input element after event which is 'OK'
button clicked here.
import PySimpleGUI as sg
from openpyxl import load_workbook, workbook
wb = load_workbook('test.xlsx')
test = wb.active
layout = [[sg.Text('name of employe')],
[sg.Text('Name', size=(15,1)), sg.InputText(key='-Name-')],
[sg.Button('OK'), sg.Button('Exit')]]
window = sg.Window('title', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
elif event == 'OK':
value = values['-Name-']
test.cell(row=8, column=16).value = value
wb.save('test.xlsx')
window.close()