├── requirements.txt ├── contracts-list.xlsx ├── vendor-contract.docx ├── bulk-word-creator.py └── README.md /requirements.txt: -------------------------------------------------------------------------------- 1 | docxtpl==0.11.4 2 | openpyxl==3.0.9 3 | pandas==1.3.5 4 | -------------------------------------------------------------------------------- /contracts-list.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sven-Bo/word-generator-based-on-excel-list/HEAD/contracts-list.xlsx -------------------------------------------------------------------------------- /vendor-contract.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sven-Bo/word-generator-based-on-excel-list/HEAD/vendor-contract.docx -------------------------------------------------------------------------------- /bulk-word-creator.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import pandas as pd # pip install pandas openpyxl 4 | from docxtpl import DocxTemplate # pip install docxtpl 5 | 6 | base_dir = Path(__file__).parent if "__file__" in locals() else Path.cwd() 7 | word_template_path = base_dir / "vendor-contract.docx" 8 | excel_path = base_dir / "contracts-list.xlsx" 9 | output_dir = base_dir / "OUTPUT" 10 | 11 | # Create output folder for the word documents 12 | output_dir.mkdir(exist_ok=True) 13 | 14 | # Convert Excel sheet to pandas dataframe 15 | df = pd.read_excel(excel_path, sheet_name="Sheet1") 16 | 17 | # Keep only date part YYYY-MM-DD (not the time) 18 | df["TODAY"] = pd.to_datetime(df["TODAY"]).dt.date 19 | df["TODAY_IN_ONE_WEEK"] = pd.to_datetime(df["TODAY_IN_ONE_WEEK"]).dt.date 20 | 21 | # Iterate over each row in df and render word document 22 | for record in df.to_dict(orient="records"): 23 | doc = DocxTemplate(word_template_path) 24 | doc.render(record) 25 | output_path = output_dir / f"{record['VENDOR']}-contract.docx" 26 | doc.save(output_path) 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Generate Word Documents in bulk based on Excel list 2 | 3 | If you're looking for a way to generate word documents in bulk, this script is for you. This script will generate word documents based on a excel list. 4 | 5 | ## Video Tutorial 6 | [![YouTube Video](https://img.youtube.com/vi/Zy9sx4GvjUY/0.jpg)](https://youtu.be/Zy9sx4GvjUY) 7 | 8 | 9 | ## Requirements 10 | ``` 11 | docxtpl==0.11.4 12 | openpyxl==3.0.9 13 | pandas==1.3.5 14 | ``` 15 | 16 | 17 | ## 🤓 Check Out My Excel Add-ins 18 | I've developed some handy Excel add-ins that you might find useful: 19 | 20 | - 📊 **[Dashboard Add-in](https://pythonandvba.com/grafly)**: Easily create interactive and visually appealing dashboards. 21 | - 🎨 **[Cartoon Charts Add-In](https://pythonandvba.com/cuteplots)**: Create engaging and fun cartoon-style charts. 22 | - 🤪 **[Emoji Add-in](https://pythonandvba.com/emojify)**: Add a touch of fun to your spreadsheets with emojis. 23 | - 🛠️ **[MyToolBelt Add-in](https://pythonandvba.com/mytoolbelt)**: A versatile toolbelt for Excel, featuring: 24 | - Creation of Pandas DataFrames and Jupyter Notebooks from Excel ranges 25 | - ChatGPT integration for advanced data analysis 26 | - And much more! 27 | 28 | 29 | 30 | ## 🤝 Connect with Me 31 | - 📺 **YouTube:** [CodingIsFun](https://youtube.com/c/CodingIsFun) 32 | - 🌐 **Website:** [PythonAndVBA](https://pythonandvba.com) 33 | - 💬 **Discord:** [Join the Community](https://pythonandvba.com/discord) 34 | - 💼 **LinkedIn:** [Sven Bosau](https://www.linkedin.com/in/sven-bosau/) 35 | - 📸 **Instagram:** [sven_bosau](https://www.instagram.com/sven_bosau/) 36 | 37 | ## ☕ Support 38 | If you appreciate the project and wish to encourage its continued development, consider [supporting my work](https://pythonandvba.com/coffee-donation). 39 | [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://pythonandvba.com/coffee-donation) 40 | 41 | ## Feedback & Collaboration 42 | For feedback, suggestions, or potential collaboration opportunities, reach out at contact@pythonandvba.com. 43 | ![Logo](https://www.pythonandvba.com/banner-img) 44 | 45 | --------------------------------------------------------------------------------