How to Read NF-e XML Files and Turn Them Into a Spreadsheet
How Brazilian NF-e and NFC-e XML files are structured, what the 44-digit access key means, how to check totals and how to export many invoices to Excel.

Every sale of goods between companies in Brazil generates an NF-e, an electronic invoice in XML. Accountants, buyers and small businesses receive hundreds of them, and the PDF DANFE that comes along is only a summary. Reading the XML directly is the way to check what was really invoiced. This guide explains the structure and shows how to analyse files with the free NF-e and NFC-e XML Viewer and Bulk Export.
NF-e and NFC-e
- NF-e (model 55): the electronic invoice for sales of goods, used between companies and in many sales to consumers.
- NFC-e (model 65): the electronic consumer invoice used in retail, replacing the old paper coupon.
Both are XML files digitally signed by the issuer and authorised by the state tax authority (SEFAZ), which returns a protocol.
The access key
Every NF-e has a 44-digit access key:
| Digits | Content |
|---|---|
| 1-2 | State code (35 for São Paulo, 31 for Minas Gerais...) |
| 3-6 | Year and month of issue |
| 7-20 | Issuer's CNPJ |
| 21-22 | Model, 55 or 65 |
| 23-25 | Series |
| 26-34 | Invoice number |
| 35 | Emission type |
| 36-43 | Random numeric code |
| 44 | Check digit |
The check digit uses modulus 11 with weights 2 to 9 from right to left. A wrong digit means the key was typed incorrectly.
Inside the XML
The main blocks are:
- ide: identification of the invoice: nature of the operation, model, series, number, date, entry or exit.
- emit: issuer: CNPJ, name, address, state registration (IE) and tax regime.
- dest: receiver: CNPJ or CPF, name and address.
- det: one block per item, with code, description, NCM classification, CFOP, quantity, unit price, total and the taxes ICMS, IPI, PIS and COFINS.
- total: totals of products, discount, freight, ICMS, ICMS-ST, IPI, PIS, COFINS and the invoice.
- protNFe: the authorisation protocol, with status 100 for authorised.
Checking an invoice
The viewer checks:
- The access key check digit.
- That the products total equals the sum of items.
- That the invoice total equals products minus discount plus ICMS-ST, freight and IPI.
- That there is an authorisation protocol with status 100.
How to use the tool
- Click "Add XML files" and select one or many NF-e or NFC-e XMLs.
- Read the summary of the selected invoice: issuer, receiver, items, taxes and totals.
- Print a DANFE-style summary if needed.
- Review the table of all invoices, with duplicates flagged by access key.
- Export to CSV or Excel for your accounting or spreadsheet.
- Use the box at the bottom to check any 44-digit access key.
Example
The sample invoice, number 12345 from a São Paulo distributor to a store in Minas Gerais, has two items: coffee and paper filters. Products total R$1,200, minus R$20 of discount, plus R$45 of freight and R$15 of IPI, giving R$1,240. The access key is valid and the protocol shows the invoice as authorised.
Why the XML matters
- It is the legal document for crediting ICMS, PIS and COFINS.
- Tax authorities compare the XMLs with your bookkeeping.
- Companies must keep the XMLs for at least five years.
Confirming status
The viewer does not query the SEFAZ. To confirm that an invoice is still valid and not cancelled, consult the access key on the national NF-e portal or your state's portal.
Tax reform
From 2026, invoices include test fields for the CBS and IBS of the consumption tax reform. The summary shows the traditional taxes; the new fields remain in the XML.
Limits
CT-e, MDF-e and NFS-e are not covered. Not tax advice.



