I've been attempting to link my python file to excel so that the information produced by my python programme is printed to my excel file. I've tried adding the key values from my python programme to excel and then connecting the two files via pandas, but this hasn't been successful for me.
Here is my code
import PySimpleGUI
from openpyxl.workbook import Workbook
from openpyxl import load_workbook
import pandas as pd
#wb = Workbook()
wb = load_workbook('/Users/safa/Desktop/بيان اسماء المستفيدين (أرشيف)/data2.xlsx')
ws = wb.active
# Add color to window
PySimpleGUI.theme('DarkTeal1')
EXCEL_FILE = '/Users/safa/Desktop/بيان اسماء المستفيدين (أرشيف)/data2.xlsx'
df = pd.read_excel(EXCEL_FILE)
font_size = 100
layout = [
[PySimpleGUI.Text("Please fill out the following fields: " )],
[PySimpleGUI.Text("The file number", size=(16, 1)), PySimpleGUI.InputText(key='The file number')],
[PySimpleGUI.Text("Name", size=(16, 1)), PySimpleGUI.InputText(key='Name')],
[PySimpleGUI.Text("Id number", size=(16, 1)), PySimpleGUI.InputText(key='Id number')],
[PySimpleGUI.Text("Phone number", size=(16, 1)), PySimpleGUI.InputText(key='Phone number')],
[PySimpleGUI.Text('The Commission: ', size=(16, 1)), PySimpleGUI.Combo(["doesn't deserve", "Marriage", "Housing", "broken"], key="The Commission")],
#[PySimpleGUI.Text("Date (d/m/y): ", size=(15, 1),
#[PySimpleGUI.Text('Date (d/m/y)', size=(15,1)), PySimpleGUI.Spin([i for i in range(0,13)],
#initial_value=0, key='date')],
#[PySimpleGUI.Text('Date (d/m/y)', size=(15,1)), PySimpleGUI.Spin([i for i in range(0,13)],
#initial_value=0, key='date')],
#[PySimpleGUI.Text('Date (d/m/y)', size=(15,1)), PySimpleGUI.Spin([i for i in range(0,13)],
#initial_value=0, key='date')],
[PySimpleGUI.CalendarButton("Date", key='date1'),PySimpleGUI.InputText()],
[PySimpleGUI.Text(' Convert to ', size=(16, 1)), PySimpleGUI.Combo(["doesn't deserve", "Marriage", "Housing", "broken"], key="Convert to")],
[PySimpleGUI.CalendarButton("Date", key='date2'),PySimpleGUI.InputText()],
#PySimpleGUI.Checkbox("doesn't deserve", key="doesn't deserve"),
#PySimpleGUI.Checkbox("Marriage", key="Marriage"),
#PySimpleGUI.Checkbox("housing", key="housing")],
[PySimpleGUI.Submit(), PySimpleGUI.Exit()]
]
window = PySimpleGUI.Window('Simple data entry form', layout) #, element_justification='center'
def clear_input():
for key in values:
window[key]('')
return None
while True:
event, values = window.read()
if event == PySimpleGUI.WINDOW_CLOSED or event == 'Exit':
break
if event == 'Submit':
df = df.concat(values, ignore_index=True)
df.to_excel(EXCEL_FILE, index=False)
PySimpleGUI.popup('Data has been saved')
clear_input()
window.close()
I tried using openpyxl panda and other types of modules but still, nothing worked out for me