π« The Pain Point
You are a Sales Manager with 20 staff. Monthly, each sends a report (Sales_Staff1.xlsx, Sales_Staff2.xlsxβ¦). You have to combine them into one Master file.
Copy-pasting 20 times takes 60 minutes and risks alignment errors. Files may be locked or corrupted.
π Agentic Solution
A Desktop App that aggregates files: Point it to a folder, and it combines everything with full error handling.
Key Features:
- Traceability: Adds a
Source_Filecolumn so you know which row came from which employee. - Smart Skip: Ignores temporary files (
~$temp.xlsx) and handles locked/corrupt files gracefully. - Encoding Support: Handles UTF-8 and other encodings automatically.
βοΈ Phase 1: Commander (Quick Fix)
For quick ad-hoc merging.
Prompt:
βI have a folder
Sales_Reportscontaining multiple Excel files (.xlsx, .xls). Write a robust Python script using Pandas to:
- Find Files: Scan for all
.xlsxand.xlsfiles (skip temp files starting with~$).- Read Safely: Use
try-exceptto handle corrupted or locked files gracefully (skip with warning).- Add Metadata: Add columns
Source_File(filename) andRow_Index(original row number).- Merge: Concatenate all DataFrames, reset index.
- Export: Save to
Master_Report.xlsxwithopenpyxlengine.- Logging: Print progress (e.g., βProcessing 1/50: sales_jan.xlsxβ).
Handle encoding issues (UTF-8) and empty files (skip with warning).β
Result: A robust merge script that handles edge cases.
ποΈ Phase 2: Architect (Permanent Tool)
For Regular Reporting.
Engineering Prompt:
**Role:** Python GUI Developer (PyQt6 Specialist)
**Task:** Create "Excel Merge Master" Desktop App
**Objective:** A reliable desktop tool to consolidate hundreds of Excel files into a single master report with traceability.
**Tech Stack:**
* Language: Python 3.10+
* GUI Library: PyQt6 (Cross-platform)
* Data Engine: Pandas, openpyxl
* Packaging: PyInstaller
**Functional Requirements:**
1. **UI Layout (PyQt6):**
* **Input:** "Browse Folder" button for source reports.
* **Settings:** Output Filename field, Dropdown for "Encoding" (Auto/UTF-8).
* **Status:** Label showing "Found X valid Excel files".
* **Action:** Big "Merge All" button.
2. **Core Logic:**
* Scan folder for `.xlsx/.xls`, ignoring `~$` temp files.
* Add `Source_File` column to every row for traceability.
* Handle locked/corrupted files with try/except blocks (skip and log).
* **Threading:** File I/O operations in `QThread` to prevent freezing.
3. **Deliverables:**
* `main.py`: Complete source code.
* `requirements.txt`: Dependencies.
* **Build Instructions:**
* Windows: `pyinstaller --onefile --noconsole main.py`
* macOS: `pyinstaller --windowed --noconsole main.py`
π§ Prompt Decoding
- Source_File Column: The crucial feature. Without this, after merging, you have no idea who sold what. Engineers focus on Data Integrity.
- Try-Except: Essential for real-world use. Files may be open in Excel or corrupted.
π οΈ Instructions
- Copy Prompt β Paste to AI β Run generated script.
- Select Folder β Preview count β Merge.