-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBell_Excel2.5.py
148 lines (94 loc) · 3.66 KB
/
Bell_Excel2.5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import os
import sys
import tkinter as tk
from tkinter import filedialog
from tkinter import *
from PIL import ImageTk, Image
import pandas as pd
##########generate filepath
'getcwd: ', os.getcwd()
osfile, maindir =('__file__: ', __file__)
filename = os.path.basename(sys.argv[0])
bulkpath = maindir.replace(filename,"BulkFile.xlsx")
seperatedpath = maindir.replace(filename,"Excels")
#########globals
root = tk.Tk()
tfont = ("", 11)
tbg = "black"
tfg = "white"
ltfg = "white"
btfont = ("", 13)
btfg = "cyan"
bellfiles = []
#############configs window
root.title('Bell Excel')
root.resizable(width=False,height=False,)
root.iconbitmap("imgs/Bell_Excel_App_Icon.ico")
#############generates backround
canvas = tk.Canvas(root, height=475, width= 425)
canvas.pack()
backroundimage = tk.PhotoImage(file="imgs/tielvapor.png")
backround = tk.Label(canvas, image=backroundimage)
backround.place(relwidth=1, relheight=1)
########generates listbox
list_frame = tk.Frame(root,background=tbg)
list_frame.place(relwidth=0.8, relheight=0.365, relx=0.1, rely=0.15)
scrollbar = Scrollbar(list_frame, orient="vertical",bg=tbg)
xl_list = Listbox(list_frame,width=50,height=10,yscrollcommand=scrollbar.set,bg=tbg,fg=ltfg,font=tfont)
scrollbar.config(command=xl_list.yview)
scrollbar.pack(side="right", fill="y")
xl_list.configure(justify=CENTER)
xl_list.pack()
#464
########generates emblem
ico_frame = tk.Frame(root,background=tbg)
ico_frame.place(relwidth=0.8, relheight=0.365, relx=0.1, rely=0.515)
pilframeimage = Image.open("imgs/Bell_Virtual_Emblem.png")
resized_pilframeimage = pilframeimage.resize((150, 150), Image.ANTIALIAS)
frameimage = ImageTk.PhotoImage(resized_pilframeimage)
framelabel = tk.Label(ico_frame, image=frameimage)
framelabel.place(relwidth=0.4, relheight=0.8, relx=0.3, rely=0.1)
##########add file button
def add_file():
filepath = filedialog.askopenfilename(
initialdir="/", title="Select file", filetypes=[("Excel files", ".xlsx .xls")])
bellfiles.append(filepath)
path ,filename = os.path.split(filepath)
xl_list.insert(END, filename)
add_file_button = Button(root, text="Choose an Excel File", command=add_file, bg=tbg,fg=tfg,font=tfont)
add_file_button.place(relx=.3, rely=0, relwidth=.4, relheight=.05)
###### add dir button
def read_xl_dir(folderpath):
for root, dirs, files in os.walk(folderpath):
for f in files:
filepath = os.path.join(root, f)
path, filetext = os.path.split(filepath)
name, extension = os.path.splitext(filepath)
if extension == '.xlsx':
bellfiles.append(filepath)
xl_list.insert(END,filetext)
def add_dir():
fpath = filedialog.askdirectory()
read_xl_dir(fpath)
add_dir_button = Button(root, text="Choose a Folder", command=add_dir, bg=tbg,fg=tfg,font=tfont)
add_dir_button.place(relx=.3, rely=.05, relwidth=.4, relheight=.05)
############# data processing button
def process_files():
if bellfiles == '':
return
for file in bellfiles:
compact_xl(file)
cleardata()
def cleardata():
bellfiles.clear()
xl_list.delete(0,END)
process_file_button = Button(root, text="Process Files", command=process_files, bg=tbg,fg=btfg,font=btfont)
process_file_button.place(relx=.23, rely=.92, relwidth=.5, relheight=.08)
#########pandas function
def compact_xl(filepath):
excelframe = pd.read_excel(filepath)
dataframes = [excelframe]
compactframes = pd.concat(dataframes)
compactframes.to_excel(bulkpath)
#####Run app
root.mainloop()