File name issue when exporting excel using context menu

Hi

I can't speak English. So I use Google Translate.
Please understand if the explanation is not natural.

When you export excel using the context menu in the grid, the file name is "Export.xlsx". Can I change the file name?
I tried to change the file name when selecting the excel export using the ContextMenuItemClicked event of the grid, but the file was downloaded twice.

Any help would be appreciated.

3 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team September 24, 2020 05:55 AM UTC

Hi JaeHyeong, 
 
Thanks for contacting Syncfusion support.  
 
Query: “I tried to change the file name when selecting the excel export using the ContextMenuItemClicked event of the grid, but the file was downloaded twice 
 
We have analyzed your query and we are able to reproduce the reported behavior at our end while trying to export Grid data to excel file with custom name using contextMenu item. We suggest you to achieve your requirement by rendering the Excel Export Button as custom menu item in Grid.  
 
Refer the below code example.  
 
<SfGrid @ref="Grid" DataSource="@Orders" AllowSorting="true" AllowPaging="true" AllowExcelExport="true" ContextMenuItems="@(new List<object>() { new ContextMenuItemModel { Text = "Export", Id = "Export", Items = new List<ContextMenuItem> { new ContextMenuItem { Text = "Excel Export", Id = "Excel Export" } } }"FirstPage""PrevPage""LastPage""NextPage","Copy""AutoFit""AutoFitAll""SortAscending""SortDescending" })"> 
    <GridEvents ContextMenuItemClicked=" OnContextMenuItemClicked" TValue="Order"></GridEvents> 
    <GridEditSettings AllowEditing="true" AllowDeleting="true"></GridEditSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
    </GridColumns> 
</SfGrid> 
  
@code{ 
    SfGrid<Order> Grid { getset; } 
    public List<Order> Orders { getset; } 
    public void OnContextMenuItemClicked(ContextMenuClickEventArgs<Order> Args) 
    { 
        if (Args.Item.Id == "Excel Export") 
        { 
            ExcelExportProperties ExcelProperties = new ExcelExportProperties(); 
            ExcelProperties.FileName = "new.xlsx"; 
            this.Grid.ExcelExport(ExcelProperties); 
        } 
    } 
 
 
For your convenience we have prepared a sample using above solution.  
 
 
Refer our UG documentation for your reference 
 
 
Kindly get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 


Marked as answer

JJ JaeHyeong Jang September 28, 2020 02:01 AM UTC

You are very kind.
This works perfectly.
Thank you very much.


VN Vignesh Natarajan Syncfusion Team September 28, 2020 04:23 AM UTC

Hi JaeHyeong,  

Thanks for the update.  

We are glad to hear that you have achieved your query using our solution. 

Kindly get back to us if you have further queries. 

Regards,
Vignesh Natarajan   


Loader.
Up arrow icon