This project demonstrates how you can implement an export to excel functionality that supports hierarchy.
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.
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 inIndex.razor.cs
and is called to initiate the export functionality to excel/csv.async Task<bool> ExportCurrentData()
: Method used inExportHelper
that handles the functionality of creating and the downloading the created document.byte[] GenerateDocument()
: Generates a document of typebyte[]
from the provided datasource.async Task Save()
: UsesJSRuntime
to call a JavaScript function namedsaveFile
to download the document created.
This contribution was made by Hüssam Elvani.