Automate Invoices Without Microsoft 365: Macros, CSVs and Mail Merge in LibreOffice
automationLibreOfficetutorial

Automate Invoices Without Microsoft 365: Macros, CSVs and Mail Merge in LibreOffice

iinvoices
2026-02-21
11 min read
Advertisement

Automate bulk invoices with LibreOffice: use macros, CSV merges and scheduled exports for low-cost invoicing that frees time and improves cashflow.

Get paid faster without Microsoft 365: low-cost bulk invoicing with LibreOffice

Slow payments, manual invoice edits and expensive software are common small-business headaches. If your finance workflow still depends on one-off PDFs and copy-paste, this guide shows a practical, low-cost path to automation in 2026: using LibreOffice macros, CSV data merges and scheduled exports to produce and deliver bulk invoices — no Microsoft 365 required.

Through late 2024–early 2026, two trends accelerated adoption of open-source office automation among freelancers and small teams:

  • Cost pressure and subscription fatigue pushed many small businesses to reduce SaaS spend and favor offline, privacy-first tools like LibreOffice.
  • Regulators and enterprise partners pushed for standardized e-invoicing and structured data exports, increasing demand for machine-readable invoice outputs (CSV/JSON/PDF).

That combination makes a LibreOffice-based pipeline — template + CSV + macro + scheduler — a pragmatic way to automate bulk invoices with minimal recurring cost.

What you’ll build

By the end of this guide you’ll be able to:

  • Create a branded LibreOffice Writer invoice template with simple placeholders.
  • Maintain client/line-item data in a CSV (easy for freelancers and accounting imports).
  • Run a LibreOffice Basic macro that iterates the CSV, fills the template and exports a PDF per invoice with predictable filenames.
  • Schedule the process (cron on macOS/Linux or Task Scheduler on Windows) for recurring runs and combine it with a simple email/upload step.

Before you start: planning and data hygiene

Automating invoices is powerful but relies on clean input. Spend 30–60 minutes on these items before scripting.

  • Standardize CSV columns: InvoiceNumber, InvoiceDate (ISO YYYY-MM-DD), ClientName, ClientEmail, ItemDescription, Quantity, UnitPrice, TaxRate, Total. Keep headers exact and in the first row.
  • Use UTF-8 encoding for the CSV (prevents character mangling in names and addresses).
  • Name conventions: Choose a predictable filename pattern like INV-2026-0001.pdf for easy reconciliation and accounting imports.
  • Backup: Keep a copy of your original CSV and template in a versioned folder so you can recover from errors.

Step 1 — Build a simple Writer invoice template

Create a professional-looking Writer document (File > New > Text Document). Keep the dynamic parts enclosed in unique markers so macros can replace them reliably. Example placeholders:

  • <<InvoiceNumber>>
  • <<InvoiceDate>>
  • <<ClientName>>
  • <<ClientAddress>>
  • <<ItemRows>> (optional — see notes below)
  • <<Total>>

Save this as invoice_template.odt in a dedicated automation folder (e.g., /home/you/invoice-automation/template/invoice_template.odt).

Tip: line items

If you need multi-line invoice items, you have two practical options:

  1. Keep each invoice to a single summary line in the CSV and attach a simple, human-readable item list in the template or an appended PDF. This is easiest for automation.
  2. Store detailed item rows in a second CSV per invoice and add a more advanced macro that builds table rows dynamically. This is doable but requires slightly more UNO scripting.

Step 2 — Prepare your CSV

Example CSV (first header row):

InvoiceNumber,InvoiceDate,ClientName,ClientEmail,ClientAddress,ItemDescription,Quantity,UnitPrice,TaxRate,Total
INV-2026-0001,2026-01-15,Acme Corp,acctpay@acme.com,"123 Main St, City",Website maintenance,1,500,0.20,600

Save as invoices.csv in the same automation folder.

Step 3 — Test a manual mail merge

Before scripting, run one manual merge to validate the template + CSV pairing.

  1. In Writer, go to Tools > Mail Merge Wizard or View > Data Sources to register the CSV as a data source (File > Open your CSV in Calc and save to the folder; Writer's mail merge can also attach to the Calc file).
  2. Use Insert > Field > More Fields > Database to insert fields tied to your CSV/Calc file.
  3. Run the merge to create a merged document and export a PDF. Confirm placeholders replaced as expected.

This step surfaces format and encoding errors early.

Step 4 — Automate with a LibreOffice macro

The following LibreOffice Basic macro is a practical, widely used pattern: it reads the CSV line-by-line, loads a fresh copy of the Writer template for each record, replaces placeholders using Writer's replace descriptor, exports the result to PDF and closes the document.

How to install: Open LibreOffice > Tools > Macros > Organize Macros > LibreOffice Basic > create a new Module (Standard.Module1) and paste the macro below. Update folder paths and run on a test CSV.

Option Explicit

Function makePropertyValue(name, value)
  Dim oProperty
  oProperty = CreateUnoStruct("com.sun.star.beans.PropertyValue")
  oProperty.Name = name
  oProperty.Value = value
  makePropertyValue = oProperty
End Function

Sub ExportInvoicesFromCSV()
  Dim sFolder As String
  Dim sTemplate As String
  Dim sCSV As String
  Dim iFile As Integer
  Dim sLine As String
  Dim aFields()
  Dim i As Long, j As Long
  Dim oDoc As Object
  Dim oPDFProps(0) As New com.sun.star.beans.PropertyValue

  ' --- UPDATE THESE PATHS ---
  sFolder = "/home/you/invoice-automation/"  ' change to your automation folder
  sTemplate = sFolder & "template/invoice_template.odt"
  sCSV = sFolder & "invoices.csv"
  ' --------------------------

  oPDFProps(0) = makePropertyValue("FilterName", "writer_pdf_Export")

  iFile = FreeFile()
  Open sCSV For Input As #iFile
  ' read header
  If Not EOF(iFile) Then Line Input #iFile, sLine

  i = 0
  Do While Not EOF(iFile)
    Line Input #iFile, sLine
    If Trim(sLine) <> "" Then
      aFields = Split(sLine, ",")
      ' map values by position (match your CSV order)
      Dim invoiceNo, invoiceDate, clientName, clientEmail, clientAddress, itemDesc, qty, unitPrice, taxRate, total
      invoiceNo = aFields(0)
      invoiceDate = aFields(1)
      clientName = aFields(2)
      clientEmail = aFields(3)
      clientAddress = aFields(4)
      itemDesc = aFields(5)
      qty = aFields(6)
      unitPrice = aFields(7)
      taxRate = aFields(8)
      total = aFields(9)

      ' load a fresh copy of the template
      oDoc = StarDesktop.loadComponentFromURL(ConvertToURL(sTemplate), "_blank", 0, Array())

      ' simple replace of placeholders like <>
      Call ReplacePlaceholder(oDoc, "<>", invoiceNo)
      Call ReplacePlaceholder(oDoc, "<>", invoiceDate)
      Call ReplacePlaceholder(oDoc, "<>", clientName)
      Call ReplacePlaceholder(oDoc, "<>", clientAddress)
      Call ReplacePlaceholder(oDoc, "<>", itemDesc)
      Call ReplacePlaceholder(oDoc, "<>", qty)
      Call ReplacePlaceholder(oDoc, "<>", unitPrice)
      Call ReplacePlaceholder(oDoc, "<>", taxRate)
      Call ReplacePlaceholder(oDoc, "<>", total)

      ' export to PDF with a safe file name
      Dim sOut As String
      sOut = sFolder & "out/" & invoiceNo & ".pdf"
      oDoc.storeToURL(ConvertToURL(sOut), oPDFProps)
      oDoc.close(True)
      i = i + 1
    End If
  Loop
  Close #iFile

  MsgBox i & " invoices exported to " & sFolder & "out/"
End Sub

Sub ReplacePlaceholder(oDoc As Object, sSearch As String, sReplace As String)
  Dim oReplace As Object
  oReplace = oDoc.createReplaceDescriptor()
  oReplace.SearchString = sSearch
  oReplace.ReplaceString = sReplace
  oDoc.replaceAll(oReplace)
End Sub

Notes on the macro:

  • Adjust the folder paths and CSV column mapping. This example uses simple CSV parsing and will break on embedded commas; for robust parsing, pre-process with a small Python script or use semicolon-separated CSV.
  • Place generated PDFs in a dedicated out/ folder to keep the automation idempotent.
  • Test extensively with a small dataset. Run the macro manually first and inspect PDFs.

Step 5 — Schedule the job

Once the macro runs manually, set it to run automatically at times appropriate to your billing cycle.

Linux/macOS (cron)

Create a small shell wrapper that opens LibreOffice headless and triggers the macro. Example wrapper (export_invoices.sh):

#!/bin/bash
# Run LibreOffice headless and invoke macro
/opt/libreoffice/program/soffice --headless --invisible "macro:///Standard.Module1.ExportInvoices()"

Then add a cron job (edit with crontab -e):

0 8 1 * * /home/you/invoice-automation/export_invoices.sh >> /home/you/invoice-automation/cron.log 2>&1

This example runs at 08:00 on the 1st of every month.

Windows (Task Scheduler)

  1. Create a .bat file that calls soffice.exe with the macro URI:
    "C:\Program Files\LibreOffice\program\soffice.exe" --invisible "macro:///Standard.Module1.ExportInvoices()"
  2. Create a scheduled task that runs the .bat at your chosen interval. Set user privileges and enable "Run whether user is logged on or not" if needed.

Important: Running macros headless can behave differently from the UI. Always test in the same environment where you will schedule the job.

Step 6 — Deliver invoices (email or upload)

Exporting PDFs is one step — getting them to clients is the other. Keep delivery simple and auditable.

  • For email, use a command-line mailer or an API-based provider (Mailgun, SendGrid). Many small teams route from a server-side script that reads the out/ folder and sends each PDF with an invoice email template.
  • For file uploads to client portals or accounting software, automate with provider APIs or a lightweight script that uploads to SFTP, AWS S3 or an accounting system.
  • Log every delivery attempt (CSV with InvoiceNumber, timestamp, deliveryMethod, status) for reconciliation and tax audits.

Advanced strategies and 2026 recommendations

As your business grows, consider these improvements to make automation more robust and future-proof.

  • Structured exports: In addition to PDF, export per-invoice JSON or CSV with line-item granularity so your accountant or ERP can import data directly.
  • Link payments: Include a static or dynamic payment link / QR code in the template. In 2025–2026, QR-based instant payments grew in many regions — embedding them raises on-time payment rates.
  • Digital signatures & archiving: For jurisdictions that require signed invoices or long-term storage, add a signing and archival step. Several open-source tools can sign PDFs programmatically.
  • Monitoring & alerts: Add a simple monitoring email if the automation fails (empty out folder, macro error). Alert within Slack or by SMS for high-value invoices.

Security, compliance and bookkeeping best practices

Automation shifts responsibility: you must protect data and maintain audit trails.

  • Secure storage: Keep your CSV, templates and generated PDFs on an encrypted disk or behind appropriate permissions.
  • Version control: Store templates and macros in a Git repo (templates in binary but macros and scripts in text) so you can trace changes.
  • Audit logs: Maintain a simple log file or database table with invoice numbers, generation timestamps, delivery attempts and results.
  • Legal compliance: Check local e-invoicing or VAT rules. Many authorities increased structured e-invoicing adoption between 2024–2026 — if you must submit invoices to a government gateway, ensure you generate the required structured payloads.

Common pitfalls and how to avoid them

  • Broken CSV parsing: Use a robust parser when your CSV contains commas in addresses; consider semicolon or pipe delimiters or pre-process with Python/Ruby.
  • Encoding issues: Force UTF-8 when saving CSVs. LibreOffice can misinterpret ANSI files on some systems.
  • Macro differences: Macros behave differently under headless mode. Test scheduled runs using the same user and environment.
  • File collisions: Use unique file names (InvoiceNumber + timestamp) and check for existing files before overwriting.

Real-world example: a 4-person freelance team

Case: A small agency with four contractors invoiced clients monthly. They adopted this LibreOffice automation in Q4 2025 and achieved these gains:

  • Reduced time to prepare monthly invoices from 6 hours to 30 minutes.
  • Fewer errors because the CSV was the single source of truth pulled from their time-tracking tool.
  • Improved DSO by 8 days after adding direct-payment links and automated reminders.

They layered a small Python script to send invoice PDFs via Mailgun and log delivery events to a Google Sheet (or local CSV), creating a lightweight, auditable pipeline without paying for a full invoicing SaaS.

When to move beyond LibreOffice automation

The LibreOffice approach is ideal for low-cost automation and small teams. Consider switching to a dedicated invoicing or billing platform once you need:

  • Real-time payment reconciliation with bank feeds and automated bank matching.
  • Integrated recurring billing with retries and dunning workflows at scale.
  • PCI-compliant hosted payment pages and deep accounting system integrations.

Even then, LibreOffice exports remain useful for backup and archival copies.

Final checklist before running a production job

  • Test macro with 3–5 sample invoices and verify PDF output.
  • Confirm email/send step on a sandbox address before sending to real clients.
  • Back up CSV and template, and snapshot the macro code in version control.
  • Schedule an automated alert for failures.
  • Document the workflow so any team member can run or troubleshoot it.
Practical automation doesn’t require expensive subscriptions. With a clean CSV, a solid Writer template and a small macro, freelancers and small teams can deliver consistent, branded invoices and free up time to focus on billable work.

Start automating today — a simple plan

  1. Create your Writer template and mark placeholders using <<LikeThis>>.
  2. Prepare a clean UTF-8 CSV with one row per invoice.
  3. Install and test the macro above, adjust field mapping, and export two or three PDFs manually.
  4. Wrap the macro call into a shell or batch script and schedule it. Add a delivery step (email or upload).

Call-to-action

Ready to stop spending hours on invoicing? Download our free starter package (template, sample CSV and macro) and test the workflow this week. If you prefer a guided setup, contact us for a 30-minute automation review — we’ll help you migrate your current invoices into a reliable, low-cost pipeline.

Advertisement

Related Topics

#automation#LibreOffice#tutorial
i

invoices

Contributor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.

Advertisement
2026-01-27T21:34:50.213Z