ExcelToLabel is a Python tool designed to automate the creation of printable shop labels. It reads tabular data from an Excel file, populates placeholders in a Word document template, and generates ready-to-print labels. Originally developed for a shop in Italy, it uses Italian terms in its example files to match the shop's labeling needs.
ExcelToLabel simplifies label creation by:
- Processing Excel data in chunks of up to 8 rows and generating a separate Word document for each chunk.
- Dynamically replacing placeholders in the Word template (e.g.,
[Marca]
,[Modello]
) with data from the Excel file. - Clearing unused placeholders in partially filled templates for a clean output.
- Formatting numerical values (e.g., prices) according to European conventions (e.g., replacing
.
with,
). - Detecting and handling locked files by prompting the user to close them before retrying.
- Python 3.8 or higher
- Clone the repository:
git clone https://github.com/yourusername/ExcelToLabel.git cd ExcelToLabel
- Install dependencies:
pip install -r requirements.txt
-
Excel File (
example.xlsx
): Place your Excel file in thefiles/
directory. It should contain columns like:Marca Modello Descrizione Codice Dettaglio Prezzo Listino Prezzo Scontato Brand A Model X Desc 1 C001 Detail A 200.50 150 Brand B Model Y Desc 2 C002 Detail B 300.75 250.00 -
Word Template (
template.docx
): Customise the Word template with placeholders like:[Marca]
,[Modello]
,[Descrizione]
,[Codice]
,[Prezzo Listino]
,[Prezzo Scontato]
.
Execute the script with:
python labels_generator.py
Generated Word documents (e.g., Risultato_part_1.docx
, Risultato_part_2.docx
) will appear in the files/ directory.
Each document corresponds to a chunk of up to 8 rows from the Excel file.