|
[Startup.cs]
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSyncfusionBlazor();
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
services.AddSingleton<OrderDataAccessLayer>();
}
|
|
[Startup.cs]
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddRazorPages();
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
}
|
|
public class Orders
{
...
[JsonProperty("OrderID")]
public long OrderID { get; set; }
[JsonProperty("CustomerID")]
public string CustomerID { get; set; }
...
}
|
|
SfGrid<Orders> Grid;
public void ToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Id == "Grid_excelexport")
{
ExcelExportProperties ExportProperties = new ExcelExportProperties();
ExportProperties.ExportType = ExportType.AllPages;
var columns = (List<GridColumn>)this.Grid.Columns; //get the columns available in Grid
foreach (var col in columns)
{
var NewColName = col.Field.Substring(0, 1).ToLower() + col.Field.Substring(1); //modify the field name value
col.Field = NewColName; //Assign modified field name as export grid's field name
}
ExportProperties.Columns = columns;
this.Grid.ExcelExport(ExportProperties);
}
}
|
We are running into this same issue even after applying all of the fixes listed here.
Exporting grids in WASM is resulting in Excel (.xlsx) and CSV files that appear blank/empty. The grid's DataSource is an in-memory collection and the grid itself is rendering in the UI will all of the data fine. Just getting empty files. Its worth noting, exporting from a grid with 3 records reuslts in a smaller csv file and exporting wfrom a grid showing a large number of records creates a bigger CSV file with more carriage returns and white space characters.
Examining the CSV in notepad, its just a bunch of single white space character separated by carriage returns
Hi Chris,
Based on the reported problem,
we suspect that have used the template column, so we suggest including the
template columns in the exported Excel file. To do this, set the
IncludeTemplateColumn property of ExcelExportProperties to true. Here’s a
code snippet that demonstrates how to achieve this. Please refer to the code
snippet and documentation below for your reference.
|
public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) { if (args.Item.Id == "Grid_excelexport") //Id is combination of Grid's ID and itemname { ExcelExportProperties ExcelProperties = new ExcelExportProperties(); ExcelProperties.IncludeTemplateColumn = true; await this.DefaultGrid.ExcelExport(ExcelProperties); } }
|
UG: https://blazor.syncfusion.com/documentation/datagrid/template-excel-export#exporting-with-column-template
Regards,
Prathap Senthil
This corrected my issue! Thank you!
I had seen the boolean flag in the documentation but misunderstood what it was going to do. I thought it was going to try to render my render fragment inside the Excel cells so I avoided it. I didn't realize it's essentially "export columns even if I defined a template for them"
Thanks for the update, we glad to hear that the
provide solution resolved your issue.
Note: The IncludeTemplateColumn set to True determines whether
columns using templates should be included in the export.