Skip to content

agriffard/ReportEngine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReportEngine

A .NET library for generating dynamic reports and exports from EF Core entities, with support for filtering, sorting, pagination, and multiple export formats (CSV, Excel, JSON).

Features

  • 📊 Dynamic Reporting: Generate reports from any EF Core entity
  • 🔍 Filtering: Support for multiple filter operators (Eq, Gt, Gte, Lt, Lte, Contains, StartsWith, EndsWith)
  • 📈 Sorting: Sort by any column in ascending or descending order
  • 📄 Pagination: Built-in pagination support with customizable page sizes
  • 📁 Export Formats: CSV, Excel (.xlsx), and JSON
  • Performance: Optimized EF Core queries with AsNoTracking

Installation

Add the ReportEngine library to your project:

dotnet add reference path/to/ReportEngine.csproj

Quick Start

1. Register Services

using ReportEngine;

// In Program.cs
builder.Services.AddReportEngine<YourDbContext>();

2. Use the ReportService

using ReportEngine.Models;
using ReportEngine.Services;

public class ProductsController
{
    private readonly IReportService _reportService;

    public ProductsController(IReportService reportService)
    {
        _reportService = reportService;
    }

    public async Task<IActionResult> ExportProducts()
    {
        var request = new ReportRequest
        {
            Columns = ["Name", "Price", "Category", "Status"],
            Filters = [new Filter("Price", FilterOperator.Gte, 100)],
            Sorts = [new Sort("Name", SortDirection.Asc)],
            Pagination = new Pagination(1, 100),
            Format = ExportFormat.Excel
        };

        var bytes = await _reportService.GenerateReportAsync<Product>(request);
        var contentType = _reportService.GetContentType(request.Format);
        var fileName = $"products{_reportService.GetFileExtension(request.Format)}";
        
        return File(bytes, contentType, fileName);
    }
}

3. Query Data with Pagination

var request = new ReportRequest
{
    Filters = [new Filter("Category", FilterOperator.Eq, "Electronics")],
    Pagination = new Pagination(1, 10)
};

var result = await _reportService.QueryAsync<Product>(request);

// result.Data - List of products
// result.TotalCount - Total count before pagination
// result.Page - Current page
// result.PageSize - Items per page
// result.TotalPages - Total number of pages

API Reference

ReportRequest

Property Type Description
Columns string[]? Columns to include in the export. If null, all columns are included.
Filters Filter[]? Filters to apply to the query.
Sorts Sort[]? Sort specifications.
Pagination Pagination? Pagination settings.
Format ExportFormat Export format (Csv, Excel, Json).

Filter Operators

Operator Description
Eq Equal to
Neq Not equal to
Gt Greater than
Gte Greater than or equal
Lt Less than
Lte Less than or equal
Contains String contains
StartsWith String starts with
EndsWith String ends with

Sample Application

The samples/ReportEngine.Sample directory contains a Blazor application demonstrating:

  • Product listing with filtering, sorting, and pagination
  • Export to CSV and Excel formats
  • Interactive UI with Bootstrap styling

Running the Sample

cd samples/ReportEngine.Sample
dotnet run

Navigate to https://localhost:5001/products to see the demo.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages