How to convert XRechnung or ZUGFeRD to Excel or CSV
An XRechnung is an XML file, and a ZUGFeRD or Factur-X invoice is a PDF with the same kind of XML attached inside. A single invoice holds dozens of nested elements: parties, addresses, tax breakdowns, payment terms and every line. A spreadsheet wants one tidy row. So converting an e-invoice means deciding which fields become columns, then reading them out of the XML.
This page shows two ways to do that on a Mac without uploading your invoices anywhere. If you only want to look at one invoice, opening an XRechnung on a Mac is quicker. For the bigger picture, see our guide to e-invoices on a Mac.
First decide: one row per invoice, or per line?
Most people want one row per invoice: who sent it, the number, the dates, net, VAT, total and where to pay. That’s what you book, check against your bank, or hand to an accountant. Both methods below give you exactly that.
If you need one row per invoice line, for example to analyse what you bought, neither method here will do it. Say so up front when you choose a tool, because many converters only do one or the other.
Method 1: Unfela, no code
Unfela reads XRechnung (UBL and CII), ZUGFeRD, Factur-X and Peppol BIS invoices on your Mac, together with ordinary PDFs, scans and order e-mails, and puts them all in one table.
- Add the invoices. Drag the files, or a whole folder, into the Unfela window. ZUGFeRD and Factur-X PDFs go in as they are; Unfela reads the XML inside.
- Check the table. Each field shows whether it’s Verified, Needs Review or Missing. For structured e-invoices the values come straight from the data, and a total that doesn’t add up goes to Needs Review instead of Verified. How the three states work.
- Export. In the toolbar, choose Export → CSV… (free plan) or Export → Excel… (Mac Pro). JSON is there too.
You get one row per invoice. The columns are file, then a value and a status column for each field:
| Column | Holds |
|---|---|
vendor_name, vendor_name_status |
Seller, and verified, needs_review, corrected or missing |
document_number |
Invoice number |
issue_date, due_date |
Dates |
subtotal, tax_amount, total_amount |
Net, VAT and gross, as numbers |
currency |
For example EUR |
iban, tax_id |
Where to pay, and the seller’s tax ID |
The status columns are the point: you can filter to needs_review and look only at the few invoices that need you.
Region: if your Mac uses decimal commas, as in Germany, the CSV is written with semicolons and decimal commas so it opens straight into columns. To change that, go to Settings → Export → CSV files and pick your region or Standard.
Method 2: a free Python script
If you’re comfortable in Terminal, this script reads the main header fields from XRechnung, ZUGFeRD, Factur-X and Peppol XML files and writes one CSV row per invoice. It uses only Python’s standard library and runs offline.
We ran it on November 7, 2026, against all 86 invoice examples in KoSIT’s official XRechnung test suite, 45 in UBL and 41 in CII syntax. It read every value those files contain. The empty cells it left were fields the invoices don’t have, such as a due date on invoices that only give payment terms as text, or an IBAN on direct-debit invoices, where the account belongs to the buyer.
Save this as einvoice_to_csv.py:
"""Write the header fields of XRechnung, ZUGFeRD/Factur-X (CII) and Peppol/UBL XML invoices to one CSV row each.
Usage: python3 einvoice_to_csv.py invoices/*.xml > invoices.csv
Needs only Python's standard library. Line items are not included.
"""
import csv
import sys
import xml.etree.ElementTree as ET
NS = {
"rsm": "urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100",
"ram": "urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100",
"udt": "urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100",
"ubl": "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2",
"cac": "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2",
"cbc": "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2",
}
# Same fields, two syntaxes: CII (XRechnung CII, ZUGFeRD, Factur-X) and UBL (XRechnung UBL, Peppol BIS).
CII = {
"number": "rsm:ExchangedDocument/ram:ID",
"issue_date": "rsm:ExchangedDocument/ram:IssueDateTime/udt:DateTimeString",
"seller": ".//ram:SellerTradeParty/ram:Name",
"seller_vat_id": ".//ram:SellerTradeParty/ram:SpecifiedTaxRegistration/ram:ID[@schemeID='VA']",
"currency": ".//ram:InvoiceCurrencyCode",
"net": ".//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxBasisTotalAmount",
"tax": ".//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount",
"total": ".//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:GrandTotalAmount",
"due_date": ".//ram:SpecifiedTradePaymentTerms/ram:DueDateDateTime/udt:DateTimeString",
"iban": ".//ram:PayeePartyCreditorFinancialAccount/ram:IBANID",
}
UBL = {
"number": "cbc:ID",
"issue_date": "cbc:IssueDate",
"seller": ("cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName",
"cac:AccountingSupplierParty/cac:Party/cac:PartyName/cbc:Name"),
"seller_vat_id": "cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID",
"currency": "cbc:DocumentCurrencyCode",
"net": "cac:LegalMonetaryTotal/cbc:TaxExclusiveAmount",
"tax": "cac:TaxTotal/cbc:TaxAmount",
"total": "cac:LegalMonetaryTotal/cbc:TaxInclusiveAmount",
"due_date": "cbc:DueDate",
"iban": "cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID",
}
COLUMNS = ["file", "number", "issue_date", "due_date", "seller", "seller_vat_id", "currency", "net", "tax", "total", "iban"]
def cii_date(text):
# CII writes dates as 20260305 (format 102); turn them into 2026-03-05.
return f"{text[:4]}-{text[4:6]}-{text[6:8]}" if text and len(text) == 8 and text.isdigit() else text
def read(path):
root = ET.parse(path).getroot()
paths = CII if root.tag.endswith("CrossIndustryInvoice") else UBL if root.tag.endswith("}Invoice") else None
if paths is None:
raise ValueError(f"{path}: not a CII or UBL invoice")
row = {"file": path}
for name, xpaths in paths.items():
found = (root.find(x, NS) for x in ((xpaths,) if isinstance(xpaths, str) else xpaths))
el = next((e for e in found if e is not None and e.text), None)
row[name] = el.text.strip() if el is not None else ""
if paths is CII:
row["issue_date"], row["due_date"] = cii_date(row["issue_date"]), cii_date(row["due_date"])
return row
writer = csv.DictWriter(sys.stdout, fieldnames=COLUMNS)
writer.writeheader()
for path in sys.argv[1:]:
writer.writerow(read(path))
Then, in Terminal, from the folder that holds your invoices:
python3 einvoice_to_csv.py *.xml > invoices.csv
If your Mac asks to install the command line developer tools the first time you run python3, accept; that’s Apple’s own installer. For one of our sample invoices, an XRechnung in CII syntax, the output looks like this:
file,number,issue_date,due_date,seller,seller_vat_id,currency,net,tax,total,iban
lieferant-471102.xml,471102,2026-03-05,2026-04-04,Lieferant GmbH,DE123456789,EUR,473.00,56.87,529.87,DE89370400440532013000
Amounts keep the decimal point used in the XML. If your spreadsheet expects decimal commas, open the file through Excel’s text import (or Numbers) and tell it the file uses commas between columns and points for decimals. Why a CSV opens in one column in German Excel explains this, with a script that rewrites the file for German Excel.
ZUGFeRD and Factur-X PDFs: get the XML out first
The script reads XML, so take the XML out of the PDF first. It’s stored as an attachment inside the PDF, and its file name depends on the ZUGFeRD version, often factur-x.xml (PDFlib’s overview of the formats). Extracting the XML from a ZUGFeRD or Factur-X PDF covers more ways, including a whole folder in Terminal. This saves every XML attachment next to the PDF. It needs the free pypdf library, which you can install with python3 -m pip install pypdf:
import sys
from pypdf import PdfReader
for name, contents in PdfReader(sys.argv[1]).attachments.items():
if name.lower().endswith(".xml"):
open(name, "wb").write(contents[0])
print("saved", name)
We tested it with pypdf 7.0.0 on a PDF with an embedded factur-x.xml, then ran the converter on the result. If a PDF has no XML attachment, it isn’t a ZUGFeRD or Factur-X invoice, just an ordinary PDF; Unfela can still read it from the page, the script can’t.
Which one should you use?
| Unfela | Python script | |
|---|---|---|
| Setup | Install the app | Python and Terminal |
| XRechnung, Peppol (UBL and CII) | Yes | Yes |
| ZUGFeRD, Factur-X PDFs | Directly | After extracting the XML |
| Ordinary PDFs, scans, e-mails | Yes, in the same table | No |
| Checks (totals add up, IBAN checksum) | Yes, with a status per field | No, it copies what’s there |
| Line items | No | No |
| Output | CSV and JSON free, Excel with Mac Pro | CSV |
| Price | Free for 50 new documents a month, Mac Pro $39 once | Free |
| Needs | macOS 26 on Apple silicon | Any Mac with Python 3 |
If you receive a handful of e-invoices and like scripts, the script is enough. If your month mixes e-invoices with PDFs, scans and receipts, or you want the values checked, Unfela puts all of them in one table you can send on.
Whichever you use, keep the original e-invoice files. The spreadsheet is a copy for working with; the XML is the invoice.
Questions
Can I convert line items, not just totals?
Not with either method on this page. Both write one row per invoice: number, dates, seller, VAT ID, currency, net, tax, total and IBAN. If you need one row per invoice line, you need a tool that expands the line items.
Does this work for ZUGFeRD and Factur-X PDFs?
Yes. Unfela reads the XML inside the PDF directly. For the script, first save the XML attachment out of the PDF with the short pypdf snippet on this page, then convert it.
Can I delete the XML once I have the spreadsheet?
No. The spreadsheet is a working copy. Keep the original e-invoice file, and ask your tax adviser how long and how you have to keep it.
Why does my CSV open as a single column in Excel?
Your spreadsheet expects semicolons, which is usual where decimals are written with a comma, such as Germany. In Unfela, set Settings → Export → CSV files to your region. For the script, open the file through Excel's text import and choose comma as the separator.