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. Image for the cookie policy date
close icon

Grid Export Formatting

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

1 Reply

BM Balaji Marimuthu Syncfusion Team May 2, 2016 11:54 AM UTC

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 


Loader.
Live Chat Icon For mobile
Up arrow icon