Skip to content

Latest commit

 

History

History
 
 

export-to-xlsx-hierarchy

Telerik Grid - Export To Excel (Hierarchy)

This project demonstrates how you can implement an export to excel functionality that supports hierarchy.

Description

For the time being, Telerik Grid doesn't contain a native export to excel funtionaly, that being said, it doesn't mean it cannot be done. The following example demonstrates how such a functionality can be implemented using SpreadStreamProcessing library.

For this project SpreadStreamProcessing library was chosen over SpreadProcessing for performance purposes, it has a limited API but much faster performance. This can be especially useful for WASM scenarios where performance and memory management are still problematic in the framework.

Implementation

As shown in Index.razor.cs you have to initialize an instance of ExportHelper class and then call ExportCurrentData() method to export your data to excel.

This will generically detect your data model type (and its detail models) at run-time and generate columns, then dynamically fill in the rows from the provided datasource respectively.

The project includes the following main methods:

  • async Task ExportToExcel(): Method used in Index.razor.cs and is called to initiate the export functionality to excel/csv.
  • async Task<bool> ExportCurrentData(): Method used in ExportHelper that handles the functionality of creating and the downloading the created document.
  • byte[] GenerateDocument(): Generates a document of type byte[] from the provided datasource.
  • async Task Save(): Uses JSRuntime to call a JavaScript function named saveFile to download the document created.

Thanks

This contribution was made by Hüssam Elvani.