S95.Blazor.Export 1.0.3

dotnet add package S95.Blazor.Export --version 1.0.3
                    
NuGet\Install-Package S95.Blazor.Export -Version 1.0.3
                    
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="S95.Blazor.Export" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="S95.Blazor.Export" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="S95.Blazor.Export" />
                    
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 S95.Blazor.Export --version 1.0.3
                    
#r "nuget: S95.Blazor.Export, 1.0.3"
                    
#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 S95.Blazor.Export@1.0.3
                    
#: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=S95.Blazor.Export&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=S95.Blazor.Export&version=1.0.3
                    
Install as a Cake Tool

Blazor.Export

Blazor.Export is a lightweight and flexible NuGet package that enables exporting table data from Blazor applications into various formats.

The package is designed to work seamlessly with both Blazor Server and Blazor WebAssembly projects. It allows developers to easily convert and export data from any table component with minimal configuration and high performance. Blazor.Export helps you integrate professional document export functionality into your Blazor apps with just a few lines of code.

Features

  • Export to: CSV (.csv), Excel (.xlsx), PDF (.pdf) & Word (.docx).
  • Blazor Server and WebAssembly support
  • Localized columns: Customize column names as you wish.
  • Minimal dependencies

How to use

  1. Install the Blazor.Export NuGet package in your Blazor project.
  2. In Program.cs (Server) add: builder.Services.AddExportServices();
  3. Add this JavaScript code:
function saveAsFile(filename, bytesBase64, contentType) {
    const link = document.createElement('a');
    link.download = filename;
    link.href = `data:${contentType};base64,${bytesBase64}`;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}
  1. Inject IExportService into your component and call the desired export method.
private async Task ExportAsync(ExportFormat format)
{
    var data = new List<T> { };

    var bytes = format switch
    {
        ExportFormat.Csv => ExportService.ExportToCsv(data),
        ExportFormat.Excel => ExportService.ExportToExcel(data),
        ExportFormat.Pdf => ExportService.ExportToPdf(data),
        ExportFormat.Word => ExportService.ExportToWord(data),
        _ => ExportService.ExportToCsv(data)
    };

    var (fileName, contentType) = format switch
    {
        ExportFormat.Csv => ($"File_{DateTime.Now:yyyy-MM-dd_HH-mm}.csv", "text/csv"),
        ExportFormat.Excel => ($"File_{DateTime.Now:yyyy-MM-dd_HH-mm}.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
        ExportFormat.Pdf => ($"File_{DateTime.Now:yyyy-MM-dd_HH-mm}.pdf", "application/pdf"),
        ExportFormat.Word => ($"File_{DateTime.Now:yyyy-MM-dd_HH-mm}.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
        _ => ($"File_{DateTime.Now:yyyy-MM-dd_HH-mm}.csv", "text/csv")
    };

    await JSRuntime.InvokeVoidAsync("saveAsFile", fileName, Convert.ToBase64String(bytes), contentType);
}
  1. If you using WebAssembly then add ExportController on Server:
public class ExportController(IExportService exportService) : ControllerBase
{
    private readonly IExportService ExportService = exportService;

    [HttpPost("csv")]
    public FileContentResult ExportToCsv([FromBody] List<ExportData> data)
    {
        var bytes = ExportService.ExportToCsv<ExportData>(data);
        return File(bytes, "text/csv", "export.csv");
    }

    [HttpPost("excel")]
    public FileContentResult ExportToExcel([FromBody] List<ExportData> data)
    {
        var bytes = ExportService.ExportToExcel<ExportData>(data);
        return File(bytes,
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            "export.xlsx");
    }

    [HttpPost("pdf")]
    public FileContentResult ExportToPdf([FromBody] List<ExportData> data)
    {
        var bytes = ExportService.ExportToPdf<ExportData>(data);
        return File(bytes, "application/pdf", "export.pdf");
    }

    [HttpPost("word")]
    public FileContentResult ExportToWord([FromBody] List<ExportData> data)
    {
        var bytes = ExportService.ExportToWord<ExportData>(data);
        return File(bytes,
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            "export.docx");
    }
}

Licence

Project is licensed under the MIT License

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 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 is compatible.  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 is compatible.  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.3 478 1/23/2026
1.0.2 301 10/22/2025
1.0.1 228 10/21/2025
1.0.0 225 10/8/2025