Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.0 kB
1
Indexable
Never
import pandas as pd
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox

def process_excel():
    # Prompt user to select input Excel file
    input_file_path = filedialog.askopenfilename(title="Select Input Excel File", filetypes=[("Excel Files", "*.xlsx")])
    if not input_file_path:
        return

    try:
        # Read input from Excel file
        input_df = pd.read_excel(input_file_path)

        # Strip whitespace from columns
        input_df['Requirement(s)'] = input_df['Requirement(s)'].str.strip()
        input_df['Specification(s)'] = input_df['Specification(s)'].str.strip()
        input_df['Software Features'] = input_df['Software Features'].str.strip()

        # Fill NaN values in 'Specification(s)' column with an empty string
        input_df['Specification(s)'].fillna("", inplace=True)

        # Group by Requirement(s) and Specification(s) and aggregate Software Features
        output_df = input_df.groupby(['Requirement(s)', 'Specification(s)'])['Software Features'].apply(lambda x: ', '.join(x)).reset_index()

        # Create Tkinter window for displaying output
        output_window = tk.Toplevel(root)
        output_window.title("Processed Data")

        # Create output Text widget
        output_text = tk.Text(output_window, height=20, width=80)
        output_text.pack()

        # Display the output in the Text widget
        output_text.insert(tk.END, "| Requirement(s) | Specification(s) | Software Features |\n")
        output_text.insert(tk.END, "|----------------|-------------------|-------------------|\n")
        for index, row in output_df.iterrows():
            requirement = row['Requirement(s)']
            specification = row['Specification(s)']
            features = row['Software Features']
            if specification == "":
                output_text.insert(tk.END, f"| {requirement} |  | {features} |\n")
            else:
                output_text.insert(tk.END, f"| {requirement} | {specification} | {features} |\n")

        # Save the output to an Excel file
        def save_output():
            output_file_path = filedialog.asksaveasfilename(defaultextension=".xlsx", filetypes=[("Excel Files", "*.xlsx")])
            if output_file_path:
                output_df.to_excel(output_file_path, index=False)
                messagebox.showinfo("Info", "Output saved successfully!")

        # Add Save button to save the output to an Excel file
        save_button = tk.Button(output_window, text="Save Output", command=save_output)
        save_button.pack()

    except Exception as e:
        messagebox.showerror("Error", str(e))

# Create Tkinter window
root = tk.Tk()
root.title("Excel Processor")

# Add Process button to start processing the Excel file
process_button = tk.Button(root, text="Process Excel", command=process_excel)
process_button.pack()

# Run the Tkinter event loop
root.mainloop()
Leave a Comment