We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

MVC 6 Grid Excel Export Problem

Thread ID:

Created:

Updated:

Platform:

Replies:

123904 May 1,2016 04:30 AM UTC Jun 15,2016 12:41 PM UTC ASP.NET MVC 3
loading
Tags: Grid
Ajay
Asked On May 1, 2016 04:30 AM UTC

Hi,

I'm using MVC 6 in my project and i'm trying to export grid content using excel option. While debugging, the controller method is hit but nothing happens after the last line.

Kindly help.

Code:

        public async Task ExportToExcel(string GridModel)
        {
            //Declarations
            var exp = new ExcelExport();

            //Get User Detail
            var user = await GetCurrentUserAsync();

            //Get Grid Datasource
            var dataSource = _repo.GetUserList(user.TeamId);

            //Convert to Grid Object
            var obj = ConvertGridObject(GridModel);

            //Set Properties
            var properties = new GridExcelExport
            {
                FileName = "Export.xlsx",
                Excelversion = ExcelVersion.Excel2010,
                Theme = "flat-saffron",
                LocalSave = true
            };

            //Export Grid
            exp.Export(obj, dataSource, properties);
        }

 private static GridProperties ConvertGridObject(string gridProperty)
        {
            var serializer = new JavaScriptSerializer();
            var div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable));
            var gridProp = new GridProperties();
            foreach (KeyValuePair<string, object> ds in div)
            {
                var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
                if (property != null)
                {
                    var type = property.PropertyType;
                    var serialize = serializer.Serialize(ds.Value);
                    var value = serializer.Deserialize(serialize, type);
                    property.SetValue(gridProp, value, null);
                }
            }
            return gridProp;
        }

Thanks.

Balaji Marimuthu [Syncfusion]
Replied On May 2, 2016 03:09 PM UTC

Hi Ajay, 
 
Thanks for contacting Syncfusion support. 
 
The mentioned issue is occurred due to file access is denied when set the LocalSave option as true in GridExcelExport property, because by default file will be save into the C drive. So, if we set LocalSave as true, we suggest you to use the FilePath in GridExcelExport property. 
 
 
var properties = new GridExcelExport 
            { 
                 
                . . .  
                Theme = "flat-saffron", 
                FilePath = @"D:\incident", 
                LocalSave = true 
            }; 
 
 
 
 
Regards, 
Balaji Marimuthu 


Ajay
Replied On June 13, 2016 05:29 AM UTC

Hi,

Thank you. I'm facing another issue with the cell auto-width in exported excel. I've used autofit setting in the grid and hence while exporting the excel contains the cells with 0px width, I need to go to Format menu in Excel and set auto-format width to fix this issue.

Could you help me on this?

Thanks,
Ajay

Isuriya Rajan [Syncfusion]
Replied On June 15, 2016 12:41 PM UTC

Hi Ajay, 
We have analysed the reported issue with our sample. We are unable to reproduce the issue. 
Please share the following details to find the cause of the issue,   
   
1.           Can you please provide initial grid render and  controller excelexport method code snippets ?  
2.           Can you please provide the issue reproduced excel sheet? 
3.           Can you please revert us by modifying the sample based on your application along with the replication procedure? 
 
This would be helpful for us to serve you. 
We have created a sample with exporting and attached for your reference, 
 
Regards, 
Isuriya R. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;