C# for .NET NuGet Free Community edition

The .NET Reporting Tool for C#

sgcReports is a .NET reporting tool and C# report generator: build reports in code, show them in WinForms, WPF and Avalonia, export PDF and Excel.

Fluent C# builder and JSON layouts Designer for WinForms, WPF, Avalonia PDF/UA, PDF/A-3, XLSX and CSV Headless in services and on Linux

See pricing →   .NET downloads and demos →

Shift report built with sgcReports and shown in the report preview: an A4 page with OEE, availability, performance and quality boxes, a production by hour chart, downtime by cause bars and a batch barcode

Reports Built with sgcReports

Grouped lists, invoices, tables and catalogs, prepared once by the report engine and shown in a preview or written to PDF, Excel, CSV and images.

How to Create a Report in C#

Give the report its data with a TsgcReportDataTableSource over a DataTable, describe the layout with the fluent TsgcReportBuilder, and save it. The builder creates and owns its own report and report engine. Every type is in the esegece.sgcReports namespace, with the same class names as the Delphi edition.

SalesReport.cs
using esegece.sgcReports;

public static class SalesReport
{
    // aSales: a TsgcReportDataTableSource named "Sales" over a DataTable
    // with the columns Region, Customer and Amount, sorted by Region
    public static TsgcReportBuilder Build(TsgcReportDataSource aSales)
    {
        TsgcReportBuilder oBuilder = new TsgcReportBuilder();
        oBuilder.Title("Sales by region").Units(TsgcReportUnits.ruMillimeters)
            .Style("Group").Font("Arial", 11).Bold().BackColor(0xEEEEEE).EndStyle()
            .Page().Paper(TsgcReportPaperSize.rpsA4).Margins(15)
            .ReportTitle(14)
            .Text("Sales by region", 0, 0, 180, 10).Bold().EndBand()
            // one header per region, one line per sale, a total per region
            .GroupHeader("Sales.Region", 9).Style("Group")
            .Text("Region: [Sales.Region]", 0, 1, 180, 7).EndBand()
            .MasterData("Sales", 6)
            .Text("[Sales.Customer]", 2, 0, 120, 6)
            .Text("[Sales.Amount]", 130, 0, 50, 6).AlignRight().Format("#,0.00").EndBand()
            .GroupFooter(9)
            .Text("Region total [FormatFloat('#,0.00', Sum(Sales.Amount))]", 80, 1, 100, 6)
            .AlignRight().Bold().EndBand()
            .EndPage().Data(aSales);
        return oBuilder;
    }
}

Fill a DataTable from your database or your objects, hand it to the data source and save the report. PDF output is tagged PDF/UA by default, and the same prepared pages go to Excel and CSV.

Program.cs
using System.Data;
using esegece.sgcReports;

DataTable oTable = new DataTable("Sales");
oTable.Columns.Add("Region", typeof(string));
oTable.Columns.Add("Customer", typeof(string));
oTable.Columns.Add("Amount", typeof(double));
oTable.Rows.Add("East", "Acme Corp", 1450.00);
oTable.Rows.Add("East", "Blue Harbor", 600.00);
oTable.Rows.Add("North", "Nordic Labs", 2100.75);

using (TsgcReportDataTableSource oSales = new TsgcReportDataTableSource())
{
    oSales.SourceName = "Sales";
    oSales.DataTable = oTable;
    using (TsgcReportBuilder oBuilder = SalesReport.Build(oSales))
    {
        // tagged PDF/UA by default, the same pages as an Excel workbook and a CSV file
        oBuilder.SaveToPDF("sales.pdf");
        oBuilder.SaveToXLSX("sales.xlsx");
        oBuilder.SaveToCSV("sales.csv");
        // PDF/A-3 on request, for archiving
        oBuilder.PDFExport.PDFA = TsgcReportPDFAMode.rpaA3b;
        oBuilder.SaveToPDF("sales-archive.pdf");
        // keep the layout as a JSON report definition
        sgcReports_Definition.sgcReportSaveToJSONFile(oBuilder.Report, "sales.json");
    }
}

The builder also adds page headers and footers, column headers, detail bands, tables, check boxes, barcodes, report parameters and bookmarks. See the TsgcReportBuilder help topic and the getting started guide.

Report Designer and Viewer for WinForms, WPF and Avalonia

Each UI package has a report preview and a ready-made end-user report designer, so your users can open, change and save report layouts inside your application. The designers have a toolbar, Design and Preview tabs, the Toolbox, Outline and Data trees, a property inspector, rulers, undo and redo, and a script editor. The three hosts share one platform neutral designer model.

WinForms

The esegece.sgcReports.WinForms package: the report preview control, TsgcWinFormsReportDesigner (a UserControl), the modal TsgcWinFormsReportDesignerForm and sgcReports_Designer_WinForms.sgcShowReportDesigner.

WPF

The esegece.sgcReports.Wpf package: TsgcWpfReportPreview with page navigation, zoom, printing and PDF saving, TsgcWpfReportDesigner (a DockPanel) and the modal TsgcWpfReportDesignerWindow.

Avalonia

The esegece.sgcReports.Avalonia package: TsgcAvaloniaReportPreview with page navigation, zoom and PDF saving, TsgcAvaloniaReportDesigner and sgcShowReportDesignerAsync with asynchronous file pickers.

The previews have a find bar, page thumbnails, the PDF outline, an Export menu with eleven formats, a Cancel button while a long report is prepared and a prompt for the report parameters. The previews are in every edition, the designer classes are in the Registered edition. The designers also import ReportBuilder .rtm templates as new reports. See the .NET designer help.

SalesForm.cs
using System.Data;
using System.Windows.Forms;
using esegece.sgcReports;

public class SalesForm : Form
{
    TsgcReportDataTableSource FSales;
    TsgcReportBuilder FBuilder;
    TsgcReportPreviewVCL FPreview;

    public SalesForm(DataTable aSales)
    {
        Width = 1000;
        Height = 760;
        FSales = new TsgcReportDataTableSource();
        FSales.SourceName = "Sales";
        FSales.DataTable = aSales;
        FBuilder = SalesReport.Build(FSales);
        // the preview: page navigation, zoom, find, thumbnails, print and export
        FPreview = new TsgcReportPreviewVCL();
        FPreview.Dock = DockStyle.Fill;
        Controls.Add(FPreview);
        Button oDesign = new Button();
        oDesign.Text = "Design...";
        oDesign.Dock = DockStyle.Top;
        oDesign.Click += (s, e) =>
        {
            // the end-user designer (Registered edition) as a modal window
            if (sgcReports_Designer_WinForms.sgcShowReportDesigner(FBuilder.Engine, FSales))
            {
                sgcReports_Definition.sgcReportSaveToJSONFile(FBuilder.Engine.Report, "sales.json");
                FPreview.Prepare();
            }
        };
        Controls.Add(oDesign);
        FPreview.Engine = FBuilder.Engine;
        FPreview.Prepare();
    }
}
DesignerWindow.cs
using System.Windows;
using esegece.sgcReports;

public class DesignerWindow : Window
{
    public DesignerWindow(TsgcReportEngine aEngine, TsgcReportDataSource aSales)
    {
        Title = "Report designer";
        TsgcWpfReportDesigner oDesigner = new TsgcWpfReportDesigner();
        Content = oDesigner;
        oDesigner.Engine = aEngine;
        oDesigner.AddDataSource(aSales);
        oDesigner.LoadFromFile("sales.json");
        Closed += (s, e) => oDesigner.Dispose();
    }
}

public class PreviewWindow : Window
{
    public PreviewWindow(TsgcReportEngine aEngine)
    {
        TsgcWpfReportPreview oPreview = new TsgcWpfReportPreview();
        Content = oPreview;
        oPreview.Engine = aEngine;
        oPreview.Prepare();
    }
}

Bands, Groups, Master Detail and Expressions

sgcReports is a banded C# report generator: pages hold bands, bands hold items, and the engine prints each band at the right time for your data.

Bands

Report title and summary, page header and footer, column header, group header and footer, master data and detail data bands, each with its own height, style and items.

Groups and totals

A group header starts a new group each time its expression changes, and a group footer prints subtotals with aggregate functions such as Sum and Count.

Master detail

Link a detail source to its master with MasterSource, MasterFields and DetailFields, as an invoice links its lines to the invoice.

Expressions

Fields and functions in square brackets inside text items, such as [Sales.Customer] or [FormatFloat('#,0.00', Sum(Sales.Amount))], plus highlights that change the style of an item when a condition is true.

Tables and crosstabs

Table items with header, data and footer rows, merged cells and rows that grow with their text, and crosstab tables with several measures and totals.

Parameters, scripts and inheritance

Typed report parameters with a prompt, a small script language stored in the report, and reports that inherit from a base layout such as a letterhead.

Data comes from a TsgcReportDataTableSource over a DataTable, or from a TsgcReportJSONSource over a JSON array of objects. Rich text, watermarks, barcodes, check boxes and bookmarks are in every edition. Chart, sparkline, gauge and pivot table items come with the Registered sgcCharts, sgcGauges and sgcPivotGrid bridge packages. See the sgcReports feature matrix.

Export a Report to PDF and Excel in C#

The engine prepares the pages once, and each export writes them in its own format. PDF output uses the sgcPDF engine, so sgcPDF is required in every configuration.

FormatDetails.NET Community (free)
PDF/UATagged PDF/UA-1 by default, with a reading order, alternative text for images and marked headings. PDF/UA-2 on request.✓
PDF/APDF/A-3 (rpaA3b, rpaA3a) for archives and e-invoices with the invoice XML embedded, and PDF/A-4.✓
XLSX and CSVExcel workbooks and CSV files from the same prepared pages.✓
PNG, SVG, ODS, HTML and textOne image per page, OpenDocument spreadsheets, HTML and plain text.✓
DOCX, ODT and RTFWord documents, OpenDocument text and Rich Text Format.−
Signed PDFThe sgcSign bridge package signs the PDF exports (PAdES).✓

Generate Reports in Services, ASP.NET Core and on Linux

The engine and the exports need no UI, so the same report runs in a Windows service, a web API or a Linux daemon. Load a JSON report definition saved by your code or by the designer, attach the data and write the file.

ReportJob.cs
using System.Data;
using esegece.sgcReports;

public static class ReportJob
{
    public static void Run(DataTable aSales, string aFileName)
    {
        using (TsgcReport oReport = new TsgcReport())
        using (TsgcReportEngine oEngine = new TsgcReportEngine())
        using (TsgcReportDataTableSource oSales = new TsgcReportDataTableSource())
        using (TsgcReportPDFExport oPDF = new TsgcReportPDFExport())
        {
            // the layout comes from a JSON definition, the data from your code
            sgcReports_Definition.sgcReportLoadFromJSONFile(oReport, "sales.json");
            oSales.SourceName = "Sales";
            oSales.DataTable = aSales;
            oEngine.Report = oReport;
            oEngine.AddDataSource(oSales);
            TsgcReportPreparedPages oPages = oEngine.Prepare();
            oPDF.SaveToFile(oPages, aFileName);
        }
    }
}

Reports over HTTP

TsgcReportHTTPEndpoint serves registered reports (RegisterReport) as PDF, XLSX, CSV, HTML and other files, and the esegece.sgcReports.HTML and esegece.sgcReports.AspNetCore packages host its routes in ASP.NET Core.

One engine per thread

A server prepares concurrent reports with one engine and one set of data sources per thread. The .NET demos include a LinuxDaemon and an HTTPServer project.

Install the .NET Reporting Tool from NuGet

esegece.sgcReports holds the builder, the data sources, the engine and the exports. Add the package of your UI framework for the preview and the designer, and the HTML and ASP.NET Core packages to serve reports on the web.

dotnet add package esegece.sgcReports
dotnet add package esegece.sgcReports.WinForms
dotnet add package esegece.sgcReports.Wpf
dotnet add package esegece.sgcReports.Avalonia
dotnet add package esegece.sgcReports.AspNetCore

For the free Community edition, use the same package ids with the .Community suffix, for example dotnet add package esegece.sgcReports.Community. The full list of packages is on the sgcReports download page, and the .NET overview explains the components. The .NET demos are Invoice, Groups, JSONDefinition, PDFUA, Exports, Fluent, HTTPServer, LinuxDaemon, DatabaseSQL and MobileMAUI.

Community and Registered Editions

The free Community packages include the engine, the exports and the previews. The Registered edition adds the end-user designers, the DOCX, ODT and RTF exports and the chart, gauge and pivot table bridges.

Feature.NET Community (free)Registered
Fluent builder, report model and JSON definitions✓✓
Bands, groups, master detail and expressions✓✓
PDF/UA and PDF/A-3 export✓✓
XLSX, CSV, PNG, ODS, SVG, HTML and plain text export✓✓
WinForms, WPF and Avalonia previews✓✓
Headless engine for services and Linux✓✓
End-user report designer for WinForms, WPF and Avalonia−✓
DOCX, ODT and RTF export−✓
Chart, sparkline, gauge and pivot table items−✓

Community, free

The .Community packages are free for individuals and organizations under EUR 1M annual gross revenue with no more than 5 developers. Organizations at or above either threshold need a Registered license.

esegece.sgcReports.Community on NuGet →

Registered

Every feature and the commercial license. Single, Team and Site licenses, each with full source code, 1 year of updates and a 50% to 70% renewal discount.

sgcReports .NET pricing →

sgcReports .NET

€199

Single, Team and Site licenses available.

  • Engine, exports and the WinForms, WPF and Avalonia packages
  • HTML and ASP.NET Core packages
  • Full source code
  • 1 year of updates

.NET Reporting Questions

Yes. sgcReports has a report preview and an end-user report designer for WinForms (esegece.sgcReports.WinForms), WPF (esegece.sgcReports.Wpf) and Avalonia (esegece.sgcReports.Avalonia). The previews show the pages with navigation, zoom, find, thumbnails and export. The engine and the exports are in the core esegece.sgcReports package and work without any UI.

Add the esegece.sgcReports NuGet package (or esegece.sgcReports.Community), wrap your DataTable in a TsgcReportDataTableSource, describe pages, bands and items with the fluent TsgcReportBuilder and call SaveToPDF, SaveToXLSX or SaveToCSV, as in the create a report sample. You can also load the layout from a JSON report definition.

Yes, with the Registered edition. TsgcWinFormsReportDesigner, TsgcWpfReportDesigner and TsgcAvaloniaReportDesigner are designers you place in your own window, and sgcShowReportDesigner opens one as a modal window. Users drag items and fields onto bands, edit properties, tables and scripts, preview the result and save the layout as a JSON definition that your server can run headless.

Yes. SaveToPDF writes tagged PDF/UA by default, PDFExport.PDFA switches to PDF/A-3, and SaveToXLSX writes an Excel workbook from the same prepared pages. CSV, PNG, SVG, ODS, HTML and plain text are in every edition, and DOCX, ODT and RTF in the Registered edition.

Yes. The headless engine and the exports run on Windows and on Linux, in services and daemons, and the .NET demos include a LinuxDaemon project. For the web, the esegece.sgcReports.AspNetCore package integrates the report endpoint with ASP.NET Core, which serves reports as PDF, XLSX, CSV, HTML and other files.

Yes. Every sgcReports NuGet package also ships as a free Community edition with the .Community suffix, with the engine, the exports and the previews. It is free for individuals and organizations under EUR 1M annual gross revenue with no more than 5 developers. The end-user designers and the DOCX, ODT and RTF exports need a Registered license, see sgcReports pricing.

Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Add Reports to Your .NET Application

Build reports in C#, show them in WinForms, WPF and Avalonia, and export PDF and Excel with one NuGet package.