π« 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 Tool Developer
**Task:** Create an "Excel Merge Desktop App".
**Requirements:**
1. **GUI (Tkinter):**
* **Input Section:** Browse button to select Input Folder.
* **Output Section:** Filename field (default: Merge_Result.xlsx).
* **Options:** Encoding dropdown (UTF-8, Latin-1, Auto-detect).
* **Preview:** Label showing "Found X files to merge".
* **Action:** Big green "Merge Files" button.
* **Feedback:** Progress Bar + Status Label ("Processing 1/50...").
2. **Logic (Pandas):**
* Scan for .xlsx/.xls files (skip ~$* temp files).
* Try-except for each file (show error popup if locked).
* Add Source_File column.
* pd.concat and save with openpyxl engine.
* Show success popup with file count.
3. **Deliverables:**
* `setup_gui.py`
* `run.bat` (auto-install pandas, openpyxl, xlrd)
* `run.sh`
* `requirements.txt`
π§ 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.