The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Generate PDF invoices from spreadsheets

To generate PDF invoices from spreadsheets (like Excel or Google Sheets), you can follow these general steps:

1. Prepare Your Spreadsheet Data

Ensure that your spreadsheet is organized with all the necessary details for the invoice. Common fields include:

  • Invoice number

  • Customer name and address

  • Item description(s)

  • Quantity, unit price, and total

  • Tax, discounts, and other charges

  • Total amount due

  • Date and due date

Example structure in a spreadsheet:

Invoice NumberCustomer NameItem DescriptionQuantityUnit PriceTotal
INV-001John DoeWidget A2$50.00$100.00
INV-001John DoeWidget B1$75.00$75.00
Subtotal$175.00
Tax (10%)$17.50
Total$192.50

2. Use Python (with Pandas and ReportLab)

If you prefer a programmatic solution, Python can help automate the process of generating invoices in PDF format.

Install required libraries:

  • pandas for reading spreadsheet data

  • reportlab for creating PDF documents

Use the following code as an example:

bash
pip install pandas reportlab openpyxl

Python Script to Generate PDF Invoice:

python
import pandas as pd from reportlab.lib.pagesizes import letter from reportlab.lib import colors from reportlab.pdfgen import canvas # Load the data from the Excel file df = pd.read_excel('invoices.xlsx', sheet_name='Sheet1') def create_pdf(invoice_data, output_filename): c = canvas.Canvas(output_filename, pagesize=letter) c.setFont("Helvetica", 10) # Title c.setFont("Helvetica-Bold", 14) c.drawString(200, 750, f"Invoice #{invoice_data['Invoice Number'][0]}") # Customer Name and Address c.setFont("Helvetica", 10) c.drawString(50, 730, f"Customer: {invoice_data['Customer Name'][0]}") c.drawString(50, 710, f"Address: {invoice_data['Customer Address'][0]}") # Table headers c.setFont("Helvetica-Bold", 10) c.drawString(50, 680, "Item Description") c.drawString(200, 680, "Quantity") c.drawString(300, 680, "Unit Price") c.drawString(400, 680, "Total") y_position = 660 for index, row in invoice_data.iterrows(): c.setFont("Helvetica", 10) c.drawString(50, y_position, row['Item Description']) c.drawString(200, y_position, str(row['Quantity'])) c.drawString(300, y_position, f"${row['Unit Price']:.2f}") c.drawString(400, y_position, f"${row['Total']:.2f}") y_position -= 20 # Subtotal, Tax, and Total subtotal = invoice_data['Total'].sum() tax = subtotal * 0.10 total = subtotal + tax c.setFont("Helvetica-Bold", 10) c.drawString(300, y_position - 20, f"Subtotal: ${subtotal:.2f}") c.drawString(300, y_position - 40, f"Tax (10%): ${tax:.2f}") c.drawString(300, y_position - 60, f"Total: ${total:.2f}") # Save the PDF c.save() # Assuming your data is in the first sheet of the Excel file create_pdf(df, "invoice_output.pdf")

This script will:

  • Read invoice data from an Excel file.

  • Generate a PDF with customer information and a table of items.

  • Calculate subtotal, tax, and total, then add those values to the invoice.

3. Use Google Sheets (with Google Apps Script)

If you’re using Google Sheets, you can use Google Apps Script to automate the PDF creation. Here’s a basic example:

Steps:

  • Go to Google Sheets > Extensions > Apps Script.

  • Copy and paste the following script.

javascript
function createInvoicePDF() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var invoiceData = sheet.getDataRange().getValues(); var doc = DocumentApp.create('Invoice PDF'); var body = doc.getBody(); // Add Invoice title body.appendParagraph("Invoice #" + invoiceData[1][0]); // Add customer information body.appendParagraph("Customer: " + invoiceData[1][1]); body.appendParagraph("Address: " + invoiceData[1][2]); // Add table with item details var table = body.appendTable(); table.appendTableRow(['Item Description', 'Quantity', 'Unit Price', 'Total']); for (var i = 2; i < invoiceData.length; i++) { table.appendTableRow([invoiceData[i][3], invoiceData[i][4], invoiceData[i][5], invoiceData[i][6]]); } // Add totals var subtotal = 0; for (var i = 2; i < invoiceData.length; i++) { subtotal += invoiceData[i][6]; } var tax = subtotal * 0.10; var total = subtotal + tax; body.appendParagraph("Subtotal: $" + subtotal); body.appendParagraph("Tax (10%): $" + tax); body.appendParagraph("Total: $" + total); // Save the document as PDF var pdf = DriveApp.getFileById(doc.getId()).getAs('application/pdf'); var folder = DriveApp.getFolderById('your-folder-id'); folder.createFile(pdf); doc.setTrashed(true); }

This script:

  • Reads the spreadsheet.

  • Generates a Google Doc with invoice details.

  • Converts it into a PDF.

  • Saves it to a specified Google Drive folder.

4. Use Online Tools

There are also online platforms that can automate this process without needing programming:

  • Invoicely

  • Zoho Invoice

  • Wave

  • Google Sheets add-ons like “Autocrat”

These tools typically have integrations that allow you to upload a spreadsheet and create PDF invoices automatically.

Let me know if you need help with a specific method!

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About