I need help connecting my python file to excel to execute the output of my program to excel

0 votes

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

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:

    return None

while True:
    event, values = window.read()
    if event == PySimpleGUI.WINDOW_CLOSED or event == 'Exit':

    if event == 'Submit':
        df = df.concat(values, ignore_index=True)
        df.to_excel(EXCEL_FILE, index=False)
        PySimpleGUI.popup('Data has been saved')


I tried using openpyxl panda and other types of modules but still, nothing worked out for me

Feb 4, 2023 in Others by Kithuzzz
• 38,010 points

1 answer to this question.

0 votes
  • you can replace concat with append and its will work but this warning will appears in run window FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  • another solution using concat function
values_df = pd.DataFrame.from_dict(values, orient='index').T
df = pd.concat([df, values_df], ignore_index=True)
answered Feb 4, 2023 by narikkadan
• 63,420 points

Related Questions In Others

0 votes
1 answer

I have filtered my Excel data and now I want to number the rows. How do I do that?

Solution Filter your data. Select the cells you want ...READ MORE

answered Nov 14, 2022 in Others by narikkadan
• 63,420 points
0 votes
1 answer
0 votes
1 answer

In a excel formula I need to create a list of names on one sheet based upon criteria/data of another sheet

The final formula is: =IF(ROWS($H$3:H3)<=$I$1,INDEX(Personnel! ...READ MORE

answered Nov 25, 2022 in Others by narikkadan
• 63,420 points
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,061 views
0 votes
1 answer
0 votes
1 answer

How can I use a command button in excel to set the value of multiple cells in one click?

Try this: Private Scan As Integer Private Sub CommandButton1_Click() ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 63,420 points
0 votes
1 answer
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP