A Python project that reads XML files from Electronic Invoices (NFe), extracts product information, and generates an organized Excel (.xlsx) table.
- π Reads all
.xmlfiles from a directory. - π Extracts the following information from each NFe:
- Emission Date
- Product
- Quantity
- Unit Value
- Total Value
- π Creates a consolidated Excel file with a separate sheet for each NFe.
- β Displays the Emission Date only in the first row of each sheet.
- Python 3.10 or higher
- Required libraries:
pip install pandas openpyxlxml_to_excel/
βββ main.py # Main script
βββ requirements.txt # Dependencies
βββ README.md # Project documentation
- Clone the repository
git clone https://github.com/your-username/xml-to-excel.git
cd xml-to-excel- Install dependencies
pip install -r requirements.txt- Run the script
python main.py <your/xml/files/directory>- Output:
- The
output.xlsxfile will be generated in the specified directory, with a sheet for each processed XML file.
| Date | Product | Quantity | Unit Value | Total Value |
|---|---|---|---|---|
| 2024-02-07T14:30:00 | Product A | 2 | 50.00 | 100.00 |
| Product B | 1 | 30.00 | 30.00 | |
| Product C | 5 | 10.00 | 50.00 |
If you need to adjust the extracted fields, edit the find calls inside the loop that processes products in the XML.
- Ensure the XML files follow the NFe standard and contain the correct namespaces.
- Each sheet name in the Excel file is based on the XML file name (limited to 31 characters).
This project is licensed under the MIT License.