Skip to content

.NET Core library for defining (From JSON or a dotnet object) and generate reports (Excel, PDF, CSV, etc) from any IEnumerable datasource.

License

Notifications You must be signed in to change notification settings

BartoGabriel/SimpleExporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleExporter

Simple Exporter is an easy report library that generate reports (Excel, CSV, PDF, etc) from any IEnumerable datasource. Simple Exporter allows defining the structure of the reports from a simple JSON or a dotnet object.

This project started with the source from DoddleReport. It was a good project to start from.

A Quick Example

SimpleExporter is installed from NuGet.

Install-Package SimpleExporter
Install-Package SimpleExporter.Writer.XlsxReportWriter
Install-Package SimpleExporter.Writer.PdfReportWriter

Report Definition (JSON):

{
  "cultureName": "es-AR",
  "body": [
    {
      "type": "TextBlock",
      "text": "Title"
    },
    {
      "type": "Table",
      "dataSourceId": "datasource",
      "columns": [
        {
          "field": "Name",
          "title": "Nombre"
        },
        {
          "field": "Description",
          "title": "Descripción"
        },
        {
          "field": "Price",
          "title": "Precio",
          "FormatSpecifier": "C"
        }
      ]
    }
  ],
  "writersSettings": {
    "delimitedTextReportWriter": {
      "delimiter": ";"
    },
    "xlsxReportWriter": {
      "formatTranslators": [
        {
          "from": "C",
          "to": "$###,###,##0.00"
        }
      ]
    }
  }
}

Export to txt and xlsx:

       public static void Export()
        {
            var query = ProductRepository.GetAll();

            var reportDataSource = query.ToReportDataSource("Products");
            var reportDefinition = ReportDefinition.FromJson(GetResourceTextFile("reportDefinition.json"));
            
            var report = SimpleExporter.CreateReport(reportDefinition, reportDataSource);

            //CSV
            using (var fs = File.Create("Sample1.csv"))
            {
                var writer = new DelimitedTextReportWriter();
                report.WriteReport(fs, writer);
                Console.WriteLine("(CSV) Sample 1 created: {0}", fs.Name);

            }

            //Xlsx
            using (var fs = File.Create("Sample1.xlsx"))
            {
                var writer = new XlsxReportWriter();
                report.WriteReport(fs, writer);
                Console.WriteLine("(Xlsx) Sample 1 created: {0}", fs.Name);
            }

            //PDF
            using (var fs = File.Create("Sample1.pdf"))
            {
                var writer = new PdfReportWriter();
                report.WriteReport(fs, writer);
                Console.WriteLine("(PDF) Sample 1 created: {0}", fs.Name);
            }
        }

About

.NET Core library for defining (From JSON or a dotnet object) and generate reports (Excel, PDF, CSV, etc) from any IEnumerable datasource.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages