From 00527fd93dace562e76491ca40b26592e9539926 Mon Sep 17 00:00:00 2001 From: jze9 Date: Wed, 23 Apr 2025 23:53:43 +0500 Subject: [PATCH] add drop down --- __pycache__/reading_sheet.cpython-313.pyc | Bin 0 -> 1125 bytes main.py | 20 +++++++++++++++++++- reading_sheet.py | 17 +++++++++++++++++ save.py | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 __pycache__/reading_sheet.cpython-313.pyc create mode 100644 reading_sheet.py diff --git a/__pycache__/reading_sheet.cpython-313.pyc b/__pycache__/reading_sheet.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7b4df811762d4f7dac36926e743310eefe557174 GIT binary patch literal 1125 zcmZuv-)qxQ6uwE*HmmEpT07>%5u`6cT^%|>5TAS#_Rug86fRktwRLS$Z&GxEvUTbv z4))al!97{(hI4cCU${|WB|hrQ-gHHL^_;YkiC)Ur@BF&=ob#m{kH-j{$5#hR<02tn z(Fl&zCtU?dlW0T}ZV^UC$vL8lV?+y0K?NQr6a`f}L^_>E435wz-3*W>xeJ*ZVWK9m zkR~!o3yl#L)+E4)7G}|6M2&ibIYTd$&7xK^4CgQeh4niCF}}lhdCOgLmlVFqcinZx zU2z+Hi|_GmFd(=M!3N*wZ3TZj7~pT9r~N`Y@;&AWQf>Ur6}IzY{{w`*?W(SYuTGt zzFsv<$IceZPIg`|=(fWqC$p?K9<_14iQ0lEQ(8954y9iD_~;XX+kXI6S|puQqiX{l z`Fs~Fk`K0v2Da?C{RBvp;Kq6Z{CabwmA>y0R*F zlBW-n88?|(jdbMU^`RF-pXJd`BE1@CaVTO@fN51m`LQXGKSpWQD%2~;2PwT@*DL)< zg3`G%vzF!KuSx@WX-aKJcglIHI}R())*Zv9bc6I>!$}xQ?gP$e zCjp+5A7UshAIW0)!cRFI9_eLcqAIdPkk8H{^V{}UB46({dV`Ha0KXdhB*6EOAP8Sb O;+Hfej2saFzved$dPlne literal 0 HcmV?d00001 diff --git a/main.py b/main.py index fbd3073..cfe1711 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,8 @@ import tkinter as tk from tkinter import filedialog import algam import save +from reading_sheet import ReadingSheet + #def Pars(): @@ -14,7 +16,7 @@ import save def Pars(): data = algam.ReadMifDirectory().find_mif_files(directory=directory_entry.get()) - save.SaveDataXLSX(file_path=file_to_save_entry.get(),sheet_name="Лист1",data=data) + save.SaveDataXLSX(file_path=file_to_save_entry.get(),sheet_name=drop_var_two.get(),data=data) root = tk.Tk() root.title("Parser11(отяет по mif)") @@ -34,6 +36,18 @@ def open_excel_file(event, entry): entry.delete(0, tk.END) entry.insert(0, excel_path) + options.clear() + readingSheets = ReadingSheet(path=excel_path) + sheets = readingSheets.Read() + for _sheet in sheets: + options.append(_sheet) + + drop_var_two.set(options[0]) + menu = dropdown_two["menu"] + menu.delete(0,"end") + for option in options: + menu.add_command(label=option, command=tk._setit(drop_var_two,option)) + # первое поле с списком file_to_save_label = tk.Label(root, text="файл_для_сохранения", font=font) file_to_save_label.pack(anchor="w") @@ -41,6 +55,10 @@ file_to_save_entry = tk.Entry(root, font=font, width=70) file_to_save_entry.pack(anchor="w") file_to_save_entry.bind("", lambda event: open_excel_file(event, file_to_save_entry)) +drop_var_two=tk.StringVar() +dropdown_two = tk.OptionMenu(root, drop_var_two, *options) +dropdown_two.pack(anchor="w") + directory_label = tk.Label(root, text="Выберите директорию c mif:", font=font) directory_label.pack(anchor="w") directory_entry = tk.Entry(root, font=font, width=70) diff --git a/reading_sheet.py b/reading_sheet.py new file mode 100644 index 0000000..579166c --- /dev/null +++ b/reading_sheet.py @@ -0,0 +1,17 @@ +import openpyxl + +class ReadingSheet(): + """ + класс для чтения листов в книгах + path - путь к файлу + """ + def __init__(self, path): + self.path = path + """path - путь к файлу""" + + def Read(self): + """прочитать и вернуть все листы в виде массива названия листов""" + workbook = openpyxl.load_workbook(self.path) + sheets = workbook.sheetnames + workbook.close() + return sheets \ No newline at end of file diff --git a/save.py b/save.py index 4844b79..e09f945 100644 --- a/save.py +++ b/save.py @@ -4,7 +4,7 @@ class SaveDataXLSX(): def __init__(self,file_path:str,sheet_name:str,data): wb = xl.load_workbook(filename=file_path) sheet = wb[sheet_name] - max_row = sheet.max_row+2 + max_row = sheet.max_row+1 for new_row,file in enumerate(data): sheet.cell(row=max_row+new_row,column=2,value=file.directory) sheet.cell(row=max_row+new_row,column=3,value=file.cad_number)