Demo Buttons
- Export To Preformatted Excel - Shows the new functionality in action, Grid exported to Workbook and merged with a Preformatted Template Excel file. To check the empty template file, use the 'Download Template' button
- Export to Excel - Shows the default out-of-the-box export functionality of the Grid. The same as calling .ExportToExcel() or clicking the built-in 'Export To Excel' button
- Download Template - Downloads the empty Excel file that has pre-defined formulas, sheets and styles. This is the empty template file where the Grid data will be populated when using 'Export To Preformatted Excel' button
Description
This is a practical demonstration of the improved GenerateXlsxWorkbook() method provided
by the grid. It can be utilized further for different scenarios where you need the Excel XLSX output even
without actually exporting anything.
The new overloads for the GenerateXlsxOutput<T>() method, introduced in R1 2021, allow the method to return a boxed object which you can cast to a Workbook, byte[] or a string depending on the generic T type you have passed.
C#
// alias for the using used for shorter definition of the Workbook type
using xlsx = Telerik.Windows.Documents.Spreadsheet.Model;
// various ways to use the GenerateXlsxOutput() method
byte[] outputAsByteArray = RadGrid1.MasterTableView.GenerateXlsxOutput<byte[]>() as byte[];
xlsx.Workbook outputAsWorkbook = RadGrid1.MasterTableView.GenerateXlsxOutput<xlsx.Workbook>() as xlsx.Workbook;
string outputAsString = RadGrid1.MasterTableView.GenerateXlsxOutput<string>() as string;
string outputAsString2 = RadGrid1.MasterTableView.GenerateXlsxOutput();
VB
' alias for the Import used for shorter definition of the Workbook type
Imports xlsx = Telerik.Windows.Documents.Spreadsheet.Model
' various ways to use the GenerateXlsxOutput() method
Dim outputAsByteArray As Byte() = TryCast(RadGrid1.MasterTableView.GenerateXlsxOutput(Of Byte())(), Byte())
Dim outputAsWorkbook As xlsx.Workbook = TryCast(RadGrid1.MasterTableView.GenerateXlsxOutput(Of xlsx.Workbook)(), xlsx.Workbook)
Dim outputAsString As String = TryCast(RadGrid1.MasterTableView.GenerateXlsxOutput(Of String)(), String)
Dim outputAsString2 As String = RadGrid1.MasterTableView.GenerateXlsxOutput()