Jrockhub.ExportExcel.NETCore 1.0.0

dotnet add package Jrockhub.ExportExcel.NETCore --version 1.0.0
NuGet\Install-Package Jrockhub.ExportExcel.NETCore -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="Jrockhub.ExportExcel.NETCore" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jrockhub.ExportExcel.NETCore --version 1.0.0
#r "nuget: Jrockhub.ExportExcel.NETCore, 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.
// Install Jrockhub.ExportExcel.NETCore as a Cake Addin
#addin nuget:?package=Jrockhub.ExportExcel.NETCore&version=1.0.0

// Install Jrockhub.ExportExcel.NETCore as a Cake Tool
#tool nuget:?package=Jrockhub.ExportExcel.NETCore&version=1.0.0

Jrockhub Excel Export

You can easily generate Excel/CSV Report in ASP.NET Core or MVC.

To export/download the List<T> Or IEnumerable<T> data as an excel file, add action method in your controller as shown below. Return the data as ExcelResult<T>/CSVResult<T> by passing filtered/ordered data, sheet name and file name. ExcelResult/CSVResult Action Result that I have added in the Nuget package. This will take care of converting your data as excel/csv file and return it back to browser.

Note: Please see example for downloading/exporting excel/csv from Asp.Net Core 6.0 Backend.

Columns

Name

Column names in Excel Export can be configured using the below attributes

  • [Display(Name = "")]
  • [DisplayName(“”)]

Report Setup

To customize the Excel Column display in your report, use the following attribute

  • [IncludeInReport]
  • [NestedIncludeInReport]

And here are the options,

Option Type Example Description
Order int [IncludeInReport(Order = N)] To control the order of columns in Excel Report

NuGet:

Package Manager:

PM> Install-Package Jrockhub.ExportExcel.NETCore

.NET CLI:

> dotnet add package Jrockhub.ExportExcel.NETCore

Main Model

public class ExportExcel
{
    public int Id { get; set; }

    [IncludeInReport(Order = 1)]
    public string Name { get; set; }

    [IncludeInReport(Order = 2)]
    public string Position { get; set; }

    [NestedIncludeInReport]
    public NestedLevelOne NestedLevelOne { get; set; }
}

Nested Level One Model:

public class NestedLevelOne
{
    [IncludeInReport(Order = 3)]
    public short? Experience { get; set; }

    [DisplayName("Extn")]
    [IncludeInReport(Order = 4)]
    public int? Extension { get; set; }

    [NestedIncludeInReport]
    public NestedLevelTwo NestedLevelTwos { get; set; }
}

Nested Level Two Model:

public class NestedLevelTwo
{
    [DisplayName("Start Date")]
    [IncludeInReport(Order = 5)]
    public DateTime? StartDates { get; set; }

    [IncludeInReport(Order = 6)]
    public long? Salary { get; set; }
}

Action Method

public async Task<IActionResult> GetExcel()
{
    // Get you IEnumerable<T> data
    var results = await _fromDatabaseService.GetDataAsync();
    return new ExcelResult<ExportExcel>(results, "Export Sheet Name", "Jrockhub_Guid");
}

public async Task<IActionResult> GetCSV()
{
    // Get you IEnumerable<T> data
    var results = await _fromDatabaseService.GetDataAsync();
    return new CSVResult<ExportExcel>(results, "Jrockhub_Guid");
}

Page Handler

public async Task<IActionResult> OnGetExcelAsync()
{
     // Get you IEnumerable<T> data
    var results = await _fromDatabaseService.GetDataAsync();
    return new ExcelResult<ExportExcel>(results, "Export Sheet Name", "Jrockhub_Guid");
}

public async Task<IActionResult> OnGetCSVAsync()
{
     // Get you IEnumerable<T> data
    var results = await _fromDatabaseService.GetDataAsync();
    return new CSVResult<ExportExcel>(results, "Jrockhub_Guid");
}

Target Platform

  • .Net Standard 6.0

Tools Used

  • Visual Studio Community 2022

Other Nuget Packages Used

  • ClosedXML (0.97.0) - For Generating Excel Bytes
  • Microsoft.AspNetCore.Mvc.Abstractions (2.2.0) - For using IActionResult
  • NETStandard.Library (2.0.3) - For standard .NET APIs that are prescribed to be used and supported together
  • System.ComponentModel.Annotations (5.0.0) - For Reading Column Names from Annotations

Author

  • Jrockhub - Software Development.

Contributions

Feel free to submit a pull request if you can add additional functionality or find any bugs (to see a list of active issues), visit the Issues section. Please make sure all commits are properly documented.

License

Jrockhub ExportExcel NETCore is release under the MIT license. You are free to use, modify and distribute this software, as long as the copyright header is left intact.

Enjoy!

Sponsors

I'm happy to help you with my Nuget Package. Support this project, Please pay us on (https://www.paypalobjects.com/webstatic/mktg/Logo/pp-logo-100px.png)](https://paypal.me/jrockhub)

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Jrockhub.ExportExcel.NETCore:

Package Downloads
Jrockhub.DataTablesServerSide.NETCore

Jrockhub Datatables Server Side NETCore is mainly used for Jquery DataTables with Asp.Net Core as backend. It provides a quick way to implement dynamic multiple column searching and sorting along with pagination and excel export at the server side.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 1,173 10/30/2022

You can easly generate .NETCore Export Excel V1.0.0 with the help of this nuget packages.
If you have any issue to use or upgrade version release then please write us to nuget.support@jrockhub.com