Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inforkgodara/generate-bulk-documents-python
It is a python script that generates bulk documents automatically from excel sheet data using replace concept.
https://github.com/inforkgodara/generate-bulk-documents-python
automation bulk bulk-cards bulk-certificates bulk-documents bulk-letters cards document document-generator excel generator letters pandas python python-docx python-script python3 sheet word xlrd
Last synced: 16 days ago
JSON representation
It is a python script that generates bulk documents automatically from excel sheet data using replace concept.
- Host: GitHub
- URL: https://github.com/inforkgodara/generate-bulk-documents-python
- Owner: inforkgodara
- Created: 2021-06-12T13:44:18.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-07-04T17:02:40.000Z (over 3 years ago)
- Last Synced: 2024-10-30T08:21:16.025Z (2 months ago)
- Topics: automation, bulk, bulk-cards, bulk-certificates, bulk-documents, bulk-letters, cards, document, document-generator, excel, generator, letters, pandas, python, python-docx, python-script, python3, sheet, word, xlrd
- Language: Python
- Homepage:
- Size: 127 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Generate Bulk Documents Python
It is a python script that generate bulk documents automatically from excel sheet data using replace concept. It can be used to generate bulk documents like letters, cards and certificates. It read data from an excel sheet and generate multiple documents.
## Demo
* Video clip on youtube of the script execution. https://youtu.be/SBubFoe84M0## Important Note
* If this repository helped you to understand at least something new please give star this repository which motivates me to work further for the similar kinds for projects.## Prerequisites
In order to run the python script, your system must have the following programs/packages installed.
* Python 3.8: Download it from https://www.python.org/downloads
* Pandas : Run in command prompt **pip install pandas**
* Xlrd : Run in command prompt **pip install xlrd**
* python-docx: Run in command prompt **pip install python-docx**## Approach
* First need to clone this respiratory.
* Run python script which is in script.py using py script.py
* The script reads data from excel sheet, replace texts and generate documents.
* Loop execute until and unless all rows completes in excel sheet.## Code
```
import pyautogui
import pandas
import datetime
import time
from docx import Document
import os# Author @inforkgodara
# Read data from excel
excel_data = pandas.read_excel('data.xlsx', sheet_name='Recipient Details')
count = 0
directory = 'generated letters'def replaceWord(oldString, newString, paragraph):
if oldString in paragraph:
inline = p.runs
# Loop added to work with runs (strings with same style)
for i in range(len(inline)):
if oldString in inline[i].text:
text = inline[i].text.replace(oldString, newString)
inline[i].text = text# Iterate excel rows till to finish
for column in excel_data['Recipient Full Name'].tolist():
document = Document('letter template.docx')
doc = document
empName = excel_data['Recipient Full Name'][count]
for p in doc.paragraphs:
replaceWord('RECIPIENT NAME', excel_data['Recipient Full Name'][count], p.text)
replaceWord('FIRST NAME', excel_data['Recipient First Name'][count], p.text)
replaceWord('TITLE', excel_data['Recipient Title'][count], p.text)
replaceWord('COMPANY NAME', excel_data['Recipient Company Name'][count], p.text)
replaceWord('STREET ADDRESS', excel_data['Recipient Street Address'][count], p.text)
replaceWord('CITY, ST ZIP CODE', str(excel_data['Recipient City, ST ZIP Code'][count]), p.text)try:
path = os.getcwd()+"/"+directory+"/"+empName
os.mkdir(path)
except OSError:
a = 10
doc.save(os.getcwd()+"/"+directory+"/"+empName+"/"+empName+' Latter.docx')
print("Letter generated for " + empName)
count = count + 1print("Total letters are created " + str(count))
```
Video on youtube: https://youtu.be/SBubFoe84M0