RG.DataExporter
1.0.0
dotnet add package RG.DataExporter --version 1.0.0
NuGet\Install-Package RG.DataExporter -Version 1.0.0
<PackageReference Include="RG.DataExporter" Version="1.0.0" />
<PackageVersion Include="RG.DataExporter" Version="1.0.0" />
<PackageReference Include="RG.DataExporter" />
paket add RG.DataExporter --version 1.0.0
#r "nuget: RG.DataExporter, 1.0.0"
#:package RG.DataExporter@1.0.0
#addin nuget:?package=RG.DataExporter&version=1.0.0
#tool nuget:?package=RG.DataExporter&version=1.0.0
RG.DataExporter
RG.DataExporter is a simple and reusable .NET 8 NuGet package used to export API or database data into multiple file formats.
You can convert JSON data into:
- Excel
- CSV
- Word
Package use in Api Flow and Instraction
Usage Flow
Get Data from API / Database ↓ Convert Data to JSON ↓ Call RG.DataExporter Method ↓ Return File from API ↓ Download Excel / CSV / PDF / Word
Installation
Install package using .NET CLI:
dotnet add package RG.DataExporter --version
Register Service in Program.cs Add the following namespaces:
using JsonToExcel.Core.Interfaces; using JsonToExcel.Core.Services;
Register the package service:
Program.cs
builder.Services.AddScoped<IJsonToExcelService, JsonTodocExporterService>();
Inject Service in Your Controller
private readonly IJsonToExcelService _exportService; public YourController(IJsonToExcelService exportService) { _exportService = exportService; }
How to Use
First, get data from your API, database, or any list.
Example:
var data = await _context.Persons.ToListAsync();
Convert your data into JSON:
var json = JsonConvert.SerializeObject(data);
Export JSON to Excel
var fileBytes = _exportService.ConvertJsonToExcel(json); return File( fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Data.xlsx" );
Export JSON to CSV
var fileBytes = _exportService.ConvertJsonToCsv(json); return File( fileBytes, "text/csv", "Data.csv" );
Export JSON to PDF
var fileBytes = _exportService.ConvertJsonToPdf(json); return File( fileBytes, "application/pdf", "Data.pdf" );
Export JSON to Word
var fileBytes = _exportService.ConvertJsonToWord(json); return File( fileBytes, "application/msword", "Data.doc" );
Example API Endpoint
[HttpGet("download-excel")] public async Task<IActionResult> DownloadExcel() { var data = await _context.Persons.ToListAsync();
var json = JsonConvert.SerializeObject(data);
var fileBytes = _exportService.ConvertJsonToExcel(json);
return File(
fileBytes,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"Persons.xlsx"
);
}
You can use the same pattern for CSV, PDF, and Word.
📄 RG.DataExporter Usage For Direct JSON (Without API)
🔹 Step 1: Add Namespace
📂 File: Program.cs / Controller.cs
using RG.DataExporter; using Newtonsoft.Json;
🔹 Step 2: Create DataExporter Instance
📂 File: Controller.cs
var exporter = new DataExporter();
📊 JSON To Excel
🔹 Example
📂 File: Controller.cs
[HttpPost("export/excel")] public IActionResult ExportExcel([FromBody] object data) { var exporter = new DataExporter();
string json = JsonConvert.SerializeObject(data);
byte[] fileBytes = exporter.ConvertJsonToExcel(json);
return File(
fileBytes,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"Employees.xlsx");
}
📄 JSON To PDF
🔹 Example
📂 File: Controller.cs
[HttpPost("export/pdf")] public IActionResult ExportPdf([FromBody] object data) { var exporter = new DataExporter();
string json = JsonConvert.SerializeObject(data);
byte[] fileBytes = exporter.ConvertJsonToPdf(json);
return File(
fileBytes,
"application/pdf",
"Employees.pdf");
}
📑 JSON To CSV
🔹 Example
📂 File: Controller.cs
[HttpPost("export/csv")] public IActionResult ExportCsv([FromBody] object data) { var exporter = new DataExporter();
string json = JsonConvert.SerializeObject(data);
byte[] fileBytes = exporter.ConvertJsonToCsv(json);
return File(
fileBytes,
"text/csv",
"Employees.csv");
}
📝 JSON To Word
🔹 Example
📂 File: Controller.cs
[HttpPost("export/word")] public IActionResult ExportWord([FromBody] object data) { var exporter = new DataExporter();
string json = JsonConvert.SerializeObject(data);
byte[] fileBytes = exporter.ConvertJsonToWord(json);
return File(
fileBytes,
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"Employees.docx");
}
🧪 Example Flow
User sends JSON data API receives request RG.DataExporter converts JSON File generated in requested format API returns downloadable file
📌 Methods
Method Return Type ConvertJsonToExcel byte[] ConvertJsonToPdf byte[] ConvertJsonToCsv byte[] ConvertJsonToWord byte[]
Important Notes
- JSON must be array format
- Invalid JSON may throw exception
- Large datasets supported
- Recommended for ASP.NET Core APIs
📊 Sample Output
| Id | Name | Department | Salary |
|---|---|---|---|
| 1 | Raj | IT | 50000 |
| 2 | Aman | HR | 45000 |
👨💻 Author
Raj Gupta
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- ClosedXML (>= 0.105.0)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 124 | 5/22/2026 |