Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter.ttk import Progressbar
- from xlwings import Range
- from Opiti.from_excel.classes.global_inc import registry
- from json_file_io import JsonFileIo
- class ImportExcel():
- def init(self):
- self.cols = None
- self.row_start = None
- self.row_end = None
- self.file_path = None
- self.bar_win = None
- self.progress_bar = None
- self.counter_label = None
- # cols: Речник с колоните, напр. {"code": 'A', "name": 'B', ... "close_c": 'H'}
- def defineCols(self, cols):
- self.cols = cols
- def defineRows(self, row_start: int, row_end: int):
- self.row_start = row_start
- self.row_end = row_end
- def defineFilePath(self, file_path: str):
- self.file_path = file_path
- def update_progress(self, percent, progress_bar, counter): # s -> float
- # progress_bar.start(10) # Започва през 10% , Пуска се заедно с импорта на данни command=step
- progress_bar['value'] = percent # % Запълване
- counter.config(text=f"{progress_bar['value']} %")
- counter.config()
- self.bar_win.update_idletasks()
- def read_excel_write_json_close(self):
- data = []
- row_start_indx = self.row_start
- row_end_indx = self.row_end
- for v in range(row_start_indx, row_end_indx + 1):
- row_data = {}
- for col_key in self.cols:
- col_name = self.cols[col_key]
- row_data[col_key] = Range(f'{col_name}{v}').value
- data.append(row_data)
- progress_percent = ((v - row_start_indx) / (row_end_indx - row_start_indx)) * 100
- print(progress_percent)
- progress_percent = int(progress_percent)
- self.update_progress(progress_percent, self.progress_bar, self.counter_label)
- print("ImportExcel.read_excel_write_json_close() data: ", data)
- json_file_io = JsonFileIo(file_name=self.file_path)
- json_file_io.write_content(data)
- #print("AAAAAAAAAAAAAAAAAA")
- #self.bar_win.update()
- #self.bar_win.update_idletasks()
- self.bar_win.destroy()
- self.bar_win.quit()
- def run_import(self):
- '''
- rows: Речник с първи и последен ред, напр. {"fist": 5, "last": 81}
- '''
- #def bar():
- self.bar_win = Tk()
- #bar_win.title('Импорт Оборотна ведомост')
- self.bar_win.overrideredirect(True) # Маха title bar
- self.bar_win.geometry('400x80+500+300')
- self.bar_win.configure(background='lightblue')
- text = Label(self.bar_win, text="Прехвърляне на данни от Excel", bg='lightblue', fg='darkblue')
- text.pack(side=TOP, pady=1)
- self.bar_win.update()
- self.progress_bar = Progressbar(self.bar_win, orient=HORIZONTAL, length=300, mode='determinate') # indeterminate
- self.progress_bar.pack(pady=(5, 5))
- self.counter_label = Label(self.bar_win, text='value', bg='lightblue')
- self.counter_label.pack(pady=(0, 5))
- # # Import trial balance
- # count_progress = 0
- #self.read_excel_write_json_close()
- self.bar_win.after_idle(lambda: self.read_excel_write_json_close())
- self.bar_win.mainloop()
- if __name__ == '__main__':
- import_excel = ImportExcel()
- import_excel.defineCols({"kredit_po": "G", "turn_d": "H", "turn_c": "I", "debit_po": "J"})
- import_excel.defineRows(3, 15)
- import_excel.defineFilePath("..\\rpna_test.txt")
- import_excel.run_import()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement