Automate Excel Data Import Into PDF Forms and Email Them
Question details
Populate a PDF form from approximately 100 Excel rows and email each completed PDF to the address in its corresponding row.

- Product
- Microsoft Excel and fillable PDF forms
- Device & OS
- not provided
- Scenario
- A business needs to create and distribute an individual PDF for each spreadsheet record.
- Observed behavior
- Each row should produce a uniquely named PDF that is emailed to the recipient listed in that row.
Create a fillable PDF with text field names that match the spreadsheet column headers, and include an Email column. Confirm that you have permission to send the data and access to an SMTP account that supports authenticated sending.
Use Python to fill PDF forms and email each recipient
Use this approach when you need a repeatable workflow for an Excel workbook, a fillable PDF, and an SMTP email account.
The example below handles text fields and reads the first worksheet of an .xlsx file. It sends a real email for each processed row, so test it with one authorized recipient first.
PDF forms with checkboxes, complex field structures, or special rendering requirements may need a different script or a dedicated PDF automation tool.
In Excel or WPS Spreadsheet, put column headers in the first row and name the recipient column Email. In a PDF form editor, create text fields with names that exactly match the columns to import. Save the files as data.xlsx and template.pdf in the same folder.
Open a terminal in that folder and run: python -m pip install openpyxl pypdf. The computer must also have Python installed.
Create a file named send_forms.py in the same folder and paste this code: import os import smtplib from email.message import EmailMessage from pathlib import Path from openpyxl import load_workbook from pypdf import PdfReader, PdfWriter SMTP_HOST = os.environ['SMTP_HOST'] SMTP_USER = os.environ['SMTP_USER'] SMTP_PASSWORD = os.environ['SMTP_PASSWORD'] MAX_ROWS = 1 # Test one real recipient first; change to 100 when verified. sheet = load_workbook('data.xlsx', data_only=True).active rows = sheet.iter_rows(values_only=True) headers = [str(value).strip() if value is not None else '' for value in next(rows)] if 'Email' not in headers: raise ValueError('The workbook must have an Email column.') reader = PdfReader('template.pdf') field_names = set((reader.get_fields() or {}).keys()) if not field_names.intersection(headers): raise ValueError('No PDF field names match the workbook headers.') Path('completed').mkdir(exist_ok=True) with smtplib.SMTP(SMTP_HOST, 587) as smtp: smtp.starttls() smtp.login(SMTP_USER, SMTP_PASSWORD) for row_number, row in enumerate(rows, start=2): if row_number - 2 >= MAX_ROWS: break record = dict(zip(headers, row)) recipient = str(record.get('Email') or '').strip() if not recipient: print(f'Skipped row {row_number}: no email address') continue values = {name: str(record[name]) if record[name] is not None else '' for name in field_names if name in record} writer = PdfWriter() writer.append(reader) for page in writer.pages: writer.update_page_form_field_values(page, values, auto_regenerate=False) output = Path('completed') / f'form_row_{row_number}.pdf' with output.open('wb') as pdf_file: writer.write(pdf_file) message = EmailMessage() message['From'] = SMTP_USER message['To'] = recipient message['Subject'] = 'Your completed form' message.set_content('Please find your completed form attached.') message.add_attachment(output.read_bytes(), maintype='application', subtype='pdf', filename=output.name) smtp.send_message(message) print(f'Sent row {row_number} to {recipient}')
Set the SMTP_HOST, SMTP_USER, and SMTP_PASSWORD environment variables using your email provider's settings, then run python send_forms.py. Open the PDF in the completed folder and confirm that the test recipient received the correct information. After verification, change MAX_ROWS to 100 and run the script again.

Prepare Excel data for PDF form automation with WPS Office
Use WPS Spreadsheet to organize the workbook and inspect the PDF template in WPS Office. Complete the bulk form filling and email delivery with the external Python workflow above; these steps are not a built-in WPS email automation feature.
- 1. Open the workbook: In WPS Spreadsheet, open the .xlsx file containing the records and recipient addresses.
- 2. Check the headers: In the first worksheet, name the recipient column Email and make the other headers match the fillable PDF text field names.
- 3. Save and inspect the template: Save the workbook as data.xlsx, then open template.pdf in WPS Office to review its layout. Use a PDF form editor to create or verify its fillable fields.
- 4. Run the external workflow: Place data.xlsx and template.pdf beside send_forms.py, configure the SMTP environment variables, and follow the Python solution above to test and send the completed forms.

Frequently Asked Questions
Does the PDF need to be fillable before I import Excel data?
Yes, for the script above. Create text fields in a PDF form editor and give them names that exactly match the spreadsheet headers.
How do I keep each PDF linked to the right email address?
Keep the recipient's address and form values on the same worksheet row. The script reads the Email column from that row and attaches the PDF generated from its matching fields.
Can I test the process without emailing all 100 recipients?
Yes. Leave MAX_ROWS set to 1 in send_forms.py and use an authorized test address in the first data row. The script sends a real email, so verify the address before running it.
Why are some PDF fields blank?
Check that the PDF field names exactly match the first-row spreadsheet headers and that the corresponding cells contain values. Also open the PDF in another viewer to check whether it displays the generated field appearances.
Can WPS Office send all the completed PDFs automatically by itself?
The workflow described here uses WPS Office to prepare and review files, but it requires an external Python script and an authenticated SMTP account to fill and send the PDFs in bulk.




