Python Forum
Append Data from TkInter to Excel
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Append Data from TkInter to Excel
#1
Hi, I'm new in python.

I stole this code here and i need adat it.

How save data in existing excel file (below last data)
I need a function to save into excel.
from tkinter import *

class GUI:
    def __init__(self, master):
        self.master = master
        master.title("Torneio de Sinuca...")
        self.var = IntVar()
        self.label = Label(master, textvariable=self.var)
        self.label.pack()

        self.listbox = Listbox(master)
        self.listbox.pack()
        self.var.set(self.listbox.size())

        self.element = StringVar()

        self.Entry = Entry(master, textvariable=self.element)
        self.Entry.pack()

        self.close_button = Button(master, text="Adicionar", command=self.test)
        self.close_button.pack()

    def test(self):
        if len(self.element.get()) != 0:
            value1 = (self.element.get())
            self.listbox.insert(END, value1)
            #shows how many items in list
            #print (self.listbox.size()) 
            self.var.set(self.listbox.size())
            self.Entry.delete(0, END)
    def howSaveExistingExcelFile():
        # I need save data (name inside listbox) into excel, below last data
root = Tk()
my_gui = GUI(root)
root.geometry("230x250")
root.mainloop()
I find it
from xlrd import open_workbook
from xlwt import Workbook
from xlutils.copy import copy

rb = open_workbook("Login.xls")
wb = copy(rb)

s = wb.get_sheet(0)
s.write(0,0,'A1') #This code save ever on first cell, I need save below last row
wb.save('Login.xls')
Thank you!!
Reply
#2
Hi.

Someone understand my post?

I can try explaning again...
Reply
#3
(Feb-03-2017, 01:15 PM)zinho Wrote: Hi, I'm new in python.

I stole this code here and i need adat it.

How save data in existing excel file (below last data)
I need a function to save into excel.
from tkinter import *

class GUI:
    def __init__(self, master):
        self.master = master
        master.title("Torneio de Sinuca...")
        self.var = IntVar()
        self.label = Label(master, textvariable=self.var)
        self.label.pack()

        self.listbox = Listbox(master)
        self.listbox.pack()
        self.var.set(self.listbox.size())

        self.element = StringVar()

        self.Entry = Entry(master, textvariable=self.element)
        self.Entry.pack()

        self.close_button = Button(master, text="Adicionar", command=self.test)
        self.close_button.pack()

    def test(self):
        if len(self.element.get()) != 0:
            value1 = (self.element.get())
            self.listbox.insert(END, value1)
            #shows how many items in list
            #print (self.listbox.size()) 
            self.var.set(self.listbox.size())
            self.Entry.delete(0, END)
    def howSaveExistingExcelFile():
        # I need save data (name inside listbox) into excel, below last data
root = Tk()
my_gui = GUI(root)
root.geometry("230x250")
root.mainloop()
I find it
from xlrd import open_workbook
from xlwt import Workbook
from xlutils.copy import copy

rb = open_workbook("Login.xls")
wb = copy(rb)

s = wb.get_sheet(0)
s.write(0,0,'A1') #This code save ever on first cell, I need save below last row
wb.save('Login.xls')
Thank you!!


Okay so let me get this right... You want to get input from a GUI and store it into a excel file / csv file?
Reply
#4
Hi johnathon , yes, i need get data into GUI and store it into a excel file, but ever below old data inside excel file.
Reply
#5
You should post this thread under jobs.

This forum is to help with programming.

We expect you to make an effort, and to ask questions when you need help.

We will write code, sometimes, if a spec is listed under jobs, and compensation is offered.


If you want to give it a try, you can start here: https://pymotw.com/3/csv/
Reply
#6
(Feb-15-2017, 06:23 PM)zinho Wrote: Hi johnathon , yes, i need get data into GUI and store it into a excel file, but ever below old data inside excel file.

I won't write the code for you as documentation for this module is openly available and easy to understand... But use the csv module.  It is a very easy to understand module.  When writing to the CSV file use "append / a" so it doesn't overwrite previously existing data.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Data from Excel GUI maaad 1 1,872 Aug-31-2020, 04:24 PM
Last Post: Larz60+
  [Tkinter] Python - Tkinter : How can I send path Excel from GUI to scripte johnjh 2 4,235 Aug-28-2020, 05:38 PM
Last Post: maaad
  [Tkinter] Override the paste function(copy from excel file - paste in separate tkinter entryes) AndreiV 3 4,557 Jun-05-2020, 04:46 PM
Last Post: AndreiV
  [Tkinter] Tkinter - I need to read file excel from GUI app to script file johnjh 0 10,670 Apr-17-2020, 08:14 PM
Last Post: johnjh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020