RG.DataExporter 1.0.0

dotnet add package RG.DataExporter --version 1.0.0
                    
NuGet\Install-Package RG.DataExporter -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RG.DataExporter" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RG.DataExporter" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="RG.DataExporter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RG.DataExporter --version 1.0.0
                    
#r "nuget: RG.DataExporter, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RG.DataExporter@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RG.DataExporter&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=RG.DataExporter&version=1.0.0
                    
Install as a Cake Tool

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
  • PDF
  • 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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