This lightweight desktop application written in Python automates the enrichment of a customer base stored in an Excel spreadsheet and a SQL Server database.
- Import an
.xlsxfile that holds the CPF/CNPJ root (column A) and person type (column B). - The data is truncated and re‑inserted into a staging table.
- A stored procedure updates or generates three result tables.
- The three tables are exported to a new Excel workbook named
<input> ‑ Resultado.xlsx.
Everything happens through a minimal GUI built with CustomTkinter.
- One‑screen interface: select file -> enrich -> get results.
- Bulk insert powered by pandas + SQLAlchemy (
fast_executemany=True). - Works with Windows Authentication by default (can be switched to SQL Auth).
- Output workbook created with openpyxl – no Excel installation required.
- Python ≥ 3.10
- A reachable SQL Server instance
- ODBC Driver 17 for SQL Server (or adjust the driver name in the code)
# put the four project files in a folder (or clone the repo)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtOpen backend.py and edit the constants in the CONFIGURE HERE block:
| Constant | Meaning |
|---|---|
SQL_SERVER |
SQL Server host or host\instance |
SQL_DATABASE |
Target database |
TABELA_STAGING |
Staging table that will be truncated and re‑filled |
STORED_PROCEDURE |
Procedure that processes the staging data |
TABELA 1 / 2 / 3 |
Result tables exported to Excel |
Need SQL authentication?
Replacetrusted_connection=yeswithUID=<user>;PWD=<password>insidecriar_engine().
python frontend.py- Click Select file and choose an Excel workbook.
- Press Enrich; the button disables to prevent double clicks.
- Wait for the dialog showing the success (or error) message.
- Find the output file in the same folder as the input.
| Step | Action |
|---|---|
| 1 | GUI passes the selected file path to backend.processar_enriquecimento() |
| 2 | The file is read with pandas (row 2 ↓, columns A & B) |
| 3 | Data is bulk‑inserted into the staging table |
| 4 | Stored procedure runs (EXEC <your_procedure>) |
| 5 | SELECT * from the three tables, then exported to Excel |
| Library | Purpose |
|---|---|
| customtkinter | Modern Tkinter widgets & dark theme |
| pandas | Excel I/O & DataFrame manipulation |
| SQLAlchemy + pyodbc | SQL Server connectivity |
| openpyxl | Writing the output workbook |
| Symptom | Fix |
|---|---|
Driver does not exist |
Install the matching ODBC driver and adjust SQL_DRIVER. |
| GUI freezes for long procedures | The app runs on the main thread for simplicity. If your SP takes minutes, wrap the call in threading.Thread or asyncio to keep the UI responsive. |
| Permission errors | Ensure the login used for the connection can TRUNCATE, INSERT and EXEC the procedure. |
Leonardo Grupioni
MIT — Free to use, modify and distribute. No warranties.
