Articles in this section
Category / Section

How to improve performance in Excel Exporting in ASP.NET MVC Grid?

2 mins read

Grid Excel Exporting will slow down while the record count is more. This is because the cells excel will be set to fit based on content given to them. Setting the theme to the excel file also slow down the Excel generation.

 

Solution:

To improve the performance of the Excel file Exporting, disable the IsAutoFit, IsAutoFitRows and set Theme to ‘none’.

 

MVC or .Net core Controller:

 
    public class HomeController : Controller
    { 
        public void ExportToExcel(string GridModel)
        {
            ExcelExport exp = new ExcelExport();
            var DataSource = OrderRepository.GetAllRecords();
            GridProperties obj = ConvertGridObject(GridModel); 
 
            //define other properties using GridExcelExport 
            GridExcelExport gridExport = new GridExcelExport();
            gridExport.FileName = "Export.xlsx";
            gridExport.Excelversion = ExcelVersion.Excel2010;
 
            /*Disable the Theme; IsAutoFit; IsAutoFitRows*/
            gridExport.Theme = "none";
            gridExport.IsAutoFit = false;
            gridExport.IsAutoFitRows = false;
            /*End of Solution*/
 
            exp.Export(obj, DataSource, gridExport);
        }
        private GridProperties ConvertGridObject(string gridProperty)
        {
            GridProperties gridProp = new GridProperties();
            gridProp = (GridProperties)JsonConvert.DeserializeObject(gridProperty, typeof(GridProperties));
            return gridProp;
        }
    }

 

Asp.Net WebForms Code Behind:

    public partial class _Default : Page
    {
        protected void FlatGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
        {
            ExcelExport exp = new ExcelExport();
            
            //define other properties using GridExcelExport
            GridExcelExport gridExport = new GridExcelExport();
 
            gridExport.FileName = "Export.xlsx";
            gridExport.Excelversion = ExcelVersion.Excel2010;
 
            /*Disable the Theme; IsAutoFit; IsAutoFitRows*/
            gridExport.Theme = "none";
            gridExport.IsAutoFit = false;
            gridExport.IsAutoFitRows = false;
            /*End of Solution*/
 
            exp.Export(FlatGrid.Model, (IEnumerable)FlatGrid.DataSource, gridExport);
        }
    }

 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied