-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_operations.py
31 lines (28 loc) · 1.06 KB
/
file_operations.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
import tkinter as tk
from tkinter import filedialog, messagebox, ttk
import os
from openpyxl import load_workbook
class FileOperations:
def __init__(self):
pass
def load_sheet_names(self, file_path, combobox):
try:
workbook = load_workbook(file_path)
sheets = workbook.sheetnames
combobox['values'] = sheets
if sheets:
combobox.current(0)
except Exception as e:
messagebox.showerror("Error", f"Failed to load sheets: {str(e)}")
def view_file(self, file_path, combobox):
try:
if os.path.exists(file_path):
workbook = load_workbook(file_path, read_only=True)
sheets = workbook.sheetnames
combobox['values'] = sheets
if sheets:
combobox.current(0)
else:
messagebox.showerror("Error", "File not found.")
except Exception as e:
messagebox.showerror("Error", f"An error occurred: {str(e)}")