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.
Unfortunately, activation email could not send to your email. Please try again.

Grid Export Formatting

Thread ID:

Created:

Updated:

Platform:

Replies:

123892 Apr 29,2016 06:47 AM May 2,2016 07:54 AM ASP.NET MVC 1
loading
Tags: Grid
Prasanth
Asked On April 29, 2016 06:47 AM

Hi there,
Is it possible to format export (excel or pdf) by changing the background colour, header background colour font, adding group header etc?
I have a requirement to group the list by certain column (also providing group header )
Regards
Prasanth

Balaji Marimuthu [Syncfusion]
Replied On May 2, 2016 07:54 AM

Hi Prasanthan, 
 
Thanks for contacting Syncfusion support. 
 
To customize the Grid we suggest you to use the AutoFormat Class. The AutoFormat Class can be used to customize the styles or themes applied to the exported grid. With the autoFormat class, you can provide required color to the grid content, alt row background or border color. 
 
 
 
private GridProperties ConvertGridObject(string gridProperty) 
        { 
            JavaScriptSerializer serializer = new JavaScriptSerializer(); 
            IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable)); 
            GridProperties 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) 
                { 
                    Type type = property.PropertyType; 
                    string serialize = serializer.Serialize(ds.Value); 
                    object value = serializer.Deserialize(serialize, type); 
                    property.SetValue(gridProp, value, null); 
                } 
            } 
            AutoFormat auto = new AutoFormat(); 
 
            auto.FontFamily = "Arial"; 
 
            auto.ContentBorderColor = Color.Brown; 
 
            auto.ContentFontSize = 10; 
 
            auto.GCaptionBorderColor = Color.Cornsilk; 
 
            auto.GContentFontColor = Color.DarkBlue; 
 
            auto.HeaderFontSize = 12; 
 
            auto.HeaderBorderColor = Color.Red; 
 
            auto.ContentBgColor = Color.Wheat; 
 
            auto.GHeaderBgColor = Color.Crimson; 
 
            auto.AltRowBgColor = Color.LightCyan; 
 
            gridProp.AutoFormat = auto; 
 
            return gridProp; 
        } 
 
public void ExportToExcel(string GridModel) 
        { 
            ExcelExport exp = new ExcelExport(); 
            var DataSource = new NorthwindDataContext().OrdersViews.Take(30).ToList(); 
            GridProperties obj = ConvertGridObject(GridModel); 
            exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "none"); 
        } 
 
 
 
Refer to the Sample and help document in following link. 
 
Sample: Sample-123892 
 
 
 
 
Regards, 
Balaji Marimuthu 


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.

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.

;