Introduction
In modern web applications, exporting data is a standard requirement. Whether it is reports, invoices, logs, or summaries, developers often need to generate Word (.docx), Excel (.xlsx), and PDF files from an ASP.NET Core API.
This article gives you a complete, practical, production-ready guide with:
ASP.NET Core service and controller code
Using OpenXML for Word & Excel
Using iText7 / QuestPDF for PDF
Download API
ER diagram
Architecture diagram
Sequence diagram
Flowchart
When Do We Need File Generation?
This technique is required in:
Invoice and report generation
Exporting search results
Audit summaries
Certificate generation
Payroll & attendance exports
Data backup in Excel
Technologies Used
ASP.NET Core 8 API
OpenXML SDK (for Word & Excel)
QuestPDF (for PDF)
Angular (for downloading files – optional)
ER Diagram (Simple Export Log)
+------------------+ +------------------------+
| ExportLog | 1 ∞ | ExportLogDetail |
+------------------+ +------------------------+
| LogId (PK) |-------| DetailId (PK) |
| FileName | | LogId (FK) |
| FileType | | FieldName |
| CreatedBy | | OldValue |
| CreatedDate | | NewValue |
+------------------+ +------------------------+
Architecture Diagram (Visio Style Text Format)
+---------------------+ +-------------------------+
| Angular App | <------> | ASP.NET Core API |
| (Download buttons) | | Controllers + Services |
+---------------------+ +-------------------------+
|
v
+-----------------------------+
| Document Generation Layer |
| - WordService (OpenXML) |
| - ExcelService (OpenXML) |
| - PdfService (QuestPDF) |
+-----------------------------+
|
v
+-----------------------------+
| Database (ExportLog tables) |
+-----------------------------+
Sequence Diagram (Generate File)
User → Angular: Click "Export PDF"
Angular → API: GET /export/pdf
API → PdfService: Generate PDF
PdfService → API: PDF bytes
API → Angular: Return file
Angular → User: Download file
Flowchart (File Generation Flow)
[Start]
|
v
[User requests export]
|
v
[API reads data]
|
v
[Generate file (Word/Excel/PDF)?]
|
|--- Word → WordService
|--- Excel → ExcelService
|--- PDF → PdfService
|
v
[Store log in DB]
|
v
[Return file]
|
v
[End]
Part 1: Generate Word (.docx) Using OpenXML
Install package
dotnet add package DocumentFormat.OpenXml

Join the conversation! Your thoughts help the community grow.