On 6/26/2023 1:46 PM, small marcc via Python-list wrote:
pandas.ExcelWriter

import pandas

This code creates the path to the Excel file where the data will be written. It 
checks if the file already exists, and if so, reads the existing data into a 
DataFrame. Otherwise, it creates a new empty DataFrame. Then it concatenates 
the existing data with the new data and writes the result to the Excel file. 
Finally, it displays a message that the backup was successful and closes the 
information window.

I do not understand why it does not work, the new data is not displayed in 
excel when I am in python tkinter, my data in python must be displayed in excel.
I use the following code to write data to an excel file using pandas:

please help meHowever, when I run this code, the new data is not showing in the 
excel file.

Do you meant the modified data is not displayed in a linked Excel window, or that the Excel file itself does not get changed?

I don't understand why this isn't working. Can you help me solve this problem?

data = {'Numero du client': [numero_du_client],
     'Prénom': [prenom],
     'Nom': [nom],
     'Adresse': [adresse],
     'Numero de téléphone': [numero_de_tel],
     'Longueur de cour': [longueur_de_cour],
     'Largeur de cour': [largeur_de_cour],
     "Unite(p ou m)":[boutonPieds, boutonMetres] #edit
     "Prix_coutant:[prix_coutant],   #new add  he asks me to define when I 
haven't done for others
     "Prix soumission":[prix_soumission], # new add  he asks me to define when 
I haven't done for others
     "MargeProfit":[marge_profit]} # new dd   he asks me to define when I 
haven't done for others


#my link with live excel valid for any move as long as the script and excel are 
in the same folder


chemin_script = os.path.abspath(__file__)
dossier_script = os.path.dirname(chemin_script)
nom_fichier_excel = "testpython.xlsx"
chemin_fichier_excel = os.path.join(dossier_script, nom_fichier_excel)
  df = pd.DataFrame(data)
         if os.path.exists(chemin_fichier_excel):
          df_existant = pd.read_excel(chemin_fichier_excel)
         else:
          df_existant = pd.DataFrame()
         df_concat = pd.concat([df_existant, df], ignore_index=True)
         df_concat.to_excel(chemin_fichier_excel, index=False)
         with pd.ExcelWriter(path, engine='xlsxwriter') as writer:
          df.to_excel(writer, index=False, sheet_name='Clients')
         print("sauvegarde reussi")
         fenetre_info.destroy()


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to