Skip to content

Invoices from CSV, Excel and XML exports

Many older accounting and ERP systems can export invoices as CSV, Excel, fixed-width text or their own XML, but cannot create XRechnung or ZUGFeRD. Map the columns or XML elements once, then every export becomes validated e-invoices — in the dashboard (Import from CSV, Excel or XML, with saved mappings per file type and an optional bureau client) or over the API:

POST /v1/invoices/generate/csv
{ "csv": "<file content>", "target": "xrechnung-ubl", "mapping": { … }, "store": true }

The same endpoint takes an Excel workbook as base64 in xlsx, or fixed-width text in fixedWidth (send exactly one of csv, xlsx, fixedWidth). Custom XML goes to POST /v1/invoices/generate/xml with xml. A complete script that sends any of them is in import-export.ts.

The mapping (CSV)

{
  "decimal": ",",
  "dateFormat": "DD.MM.YYYY",
  "groupBy": "Rechnungsnr",
  "fields": {
    "id": "Rechnungsnr",
    "issueDate": "Datum",
    "currency": { "value": "EUR" },
    "buyerReference": "Leitweg-ID",
    "seller.name": { "value": "Muster Software GmbH" },
    "buyer.name": "Kunde",
    "lines[].item.name": "Artikel",
    "lines[].quantity": "Menge",
    "lines[].price.net": "Einzelpreis",
    "lines[].vat.rate": "USt"
  }
}
  • Keys are fields of the canonical model (components.schemas.Invoice); lines[].… are line fields. Values are a column name or { "value": "…" } for a fixed value.
  • Rows with the same value in groupBy become the lines of one invoice; header fields are taken from the first row.
  • delimiter is detected (;, , or tab) unless given; decimal is . or ,; dateFormat is YYYY-MM-DD, DD.MM.YYYY, DD/MM/YYYY or MM/DD/YYYY.

Excel (.xlsx)

Send the workbook as base64 in xlsx. The mapping is the CSV mapping plus two optional keys:

{ "sheet": "Rechnungen", "headerRow": 3, "groupBy": "Rechnungsnr", "fields": { … } }
  • sheet is the sheet name or its position from 1; default: the first sheet. headerRow is the row with the column names; default: the first row that is not empty. Empty rows are skipped.
  • Cells are read as Excel stored them, not as they are displayed. Text cells use decimal and dateFormat like CSV. Number cells are numbers whatever their display format (currency, thousands separators); a number cell mapped to a date field is an Excel date (both the 1900 and the 1904 date system). Numbers keep Excel's 15 significant digits, so a calculated 1199.9999999999998 is read as 1200.
  • Formulas count with the value Excel last calculated and saved in the file; the service does not recalculate. Text, inline text and shared strings, TRUE/FALSE and error values (#N/A) are read as text; an error value in a number field is reported like any unreadable value.
  • Only .xlsx (Office Open XML) is read. Old .xls, binary .xlsb, password-protected and .ods files are rejected with invalid_spreadsheet; save them as Excel Workbook first.
  • Row numbers in the result are the rows of the sheet.

Fixed-width text

Some systems print each field at a fixed character position. Send the text in fixedWidth and describe the columns:

{
  "columns": [
    { "name": "Nr", "start": 1, "length": 10 },
    { "name": "Datum", "start": 11, "length": 10 },
    { "name": "Text", "start": 21, "length": 30 },
    { "name": "Menge", "start": 51, "length": 8 },
    { "name": "Preis", "start": 59, "length": 10 }
  ],
  "headerRow": 1,
  "groupBy": "Nr",
  "decimal": ",",
  "dateFormat": "DD.MM.YYYY",
  "fields": { "id": "Nr", "issueDate": "Datum", "lines[].item.name": "Text", "lines[].quantity": "Menge", "lines[].price.net": "Preis" }
}

start counts characters from 1 (not bytes; send UTF-8), headerRow here is the number of lines to skip at the top. Cells are trimmed; empty lines are skipped. The column names are then used in fields and groupBy as in CSV.

Custom XML

POST /v1/invoices/generate/xml
{ "xml": "<file content>", "target": "xrechnung-ubl", "mapping": { … } }

For an export like this:

<erp:Export xmlns:erp="urn:example:altes-erp:export:1">
  <erp:Firma><erp:Name>Muster Software GmbH</erp:Name> …</erp:Firma>
  <erp:Rechnung nr="RE-1001" datum="2026-11-05">
    <erp:Kunde><erp:Name>Stadt Musterstadt</erp:Name> …</erp:Kunde>
    <erp:Positionen>
      <erp:Position><erp:Text>Beratung</erp:Text><erp:Menge einheit="HUR">10</erp:Menge><erp:Preis>95.00</erp:Preis><erp:USt>19</erp:USt></erp:Position>
    </erp:Positionen>
  </erp:Rechnung>
</erp:Export>

the mapping names the repeated invoice element, the repeated line element inside it and a path per field:

{
  "namespaces": { "e": "urn:example:altes-erp:export:1" },
  "invoice": "/e:Export/e:Rechnung",
  "lines": "e:Positionen/e:Position",
  "fields": {
    "id": "@nr",
    "issueDate": "@datum",
    "currency": { "value": "EUR" },
    "seller.name": "/e:Export/e:Firma/e:Name",
    "buyer.name": "e:Kunde/e:Name",
    "lines[].item.name": "e:Text",
    "lines[].quantity": "e:Menge",
    "lines[].unitCode": "e:Menge/@einheit",
    "lines[].price.net": "e:Preis",
    "lines[].vat.rate": "e:USt"
  }
}

The full mapping of this example is legacy-xml-mapping.json for legacy-export.xml.

  • Each element matched by invoice becomes one invoice, each element matched by lines inside it one line. invoice is a path from the document root (or relative to the root element); lines is relative to the invoice element.
  • Paths of invoice fields are relative to the invoice element; paths of lines[].… fields to the line element. A path starting with / is read from the document root, for data printed once in the file header (the seller). .. reaches the parent, for example ../../e:Kunde/e:Name from a line inside e:Positionen.
  • Supported steps: child elements (a/b), prefix:name, *, a position from 1 (e:Kontakt[2]), an attribute as the last step (@nr, @p:nr), text() (the element's own text) as the last step, . and ... Not supported: //, predicates other than a position, functions, axes. A field without a match is empty, like an empty CSV cell.
  • Names without a prefix match elements without a namespace, as in XPath 1.0. For a document with a default namespace (xmlns="…"), declare a prefix for it in namespaces and use it in every step. The dashboard lists every element and attribute path in the uploaded file with its count and a sample value.
  • decimal and dateFormat work as in CSV. Row numbers in the result are the lines of the XML file where the invoice element or the unreadable value is.
  • The file is checked like an e-invoice before it is read: no DOCTYPE, no entity declarations, UTF-8 only, at most 64 levels deep and 200,000 elements. Violations return forbidden_xml_construct, malformed_xml or xml_too_deep / xml_too_many_nodes.

What is calculated, and what is not

When the export does not carry them, the service calculates only what EN 16931 defines as arithmetic: line net = quantity × price (rounded to cents), the VAT breakdown per category and rate, and the document totals. These fields are listed in derived. Everything else — names, addresses, Leitweg-ID, VAT IDs — must come from the export or a fixed value; a missing value makes the invoice fail validation with the JSON fields named, exactly like creating from JSON.

Values that cannot be read (a word where a number is expected, an invalid date) skip that invoice and are reported with the row number (CSV and fixed width: line of the file; Excel: row of the sheet; XML: line of the file).

Result

{
  "object": "csv_generation",
  "source": { "kind": "xlsx", "sheet": "Rechnungen", "sheets": ["Hinweise", "Rechnungen"] },
  "summary": { "invoices": 2, "created": 1, "failed": 1 },
  "results": [
    { "key": "RE-1001", "rows": [4, 5], "status": "created", "invoiceId": null, "target": { … }, "document": "<?xml …", "derived": ["vatBreakdown", "totals.payable"] },
    { "key": "RE-1002", "rows": [6], "status": "skipped", "issues": [{ "row": 6, "field": "lines[].price.net", "message": "\"#N/A\" is not a number" }] }
  ]
}

object is xml_generation for XML. status is created, skipped (unreadable values, nothing was sent to the validator) or failed (the invoice did not pass validation; error.details.findings names the rules and fields).

Limits and billing

Up to 5 MB per file, 5,000 rows (Excel, CSV, fixed width) or 5,000 invoice and 5,000 line elements (XML), and 100 invoices per API request (200 in the dashboard). Excel files are unpacked only as far as needed (workbook, shared strings, the chosen sheet), at most 60 MB per part and 100 MB in total, and at most 1,000 columns are read; larger or encrypted archives are rejected as invalid_spreadsheet. Each created invoice counts as one document; skipped and failed invoices do not count.