Best way to bring GroupCaption into the Excel Export

Hello,

iam using a customized Group Caption Format.

GroupCaptionFormat: "{{:field}}: {{:key}} - {{:count}} {{if count == 1}}Material{{else}}Materialien{{/if}}",

When i export my grid to excel the group caption raw code output is in the excel file.

Iam using Server Export. 

 

3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 2, 2018 01:28 PM UTC

Hi Customer,  
 
By default, GroupCaptionFormat values will not be updated to the server-end while exporting in the earlier version. However, it has been fixed in the Volume 2, 2018 Service Pack 1 v16.2.0.46. So, we suggest to upgrade to the latest release using following steps. 
 
        1) Download and install the Essential Studio v16.2.0.46  from the below link.   
   
      2)   Replace the Syncfusion scripts, and CSS in your project from the following location. 
 
             Scripts and CSS: C:\Program Files (x86)\Syncfusion\Essential Studio\XX.X.X.XX\JavaScript\assets 
 
Here XX.X.X.XX denotes the product version(v16.2.0.46). 
 
If you are not interested to upgrade to the latest release, please refer to the following Help Document.  
 
 
Update the GroupCaptionFormat key of the ej.Grid.Locale and export which will get the text that we expect. 
 
Regards,  
Seeni Sakthi Kumar S. 



MK mk August 8, 2018 02:41 PM UTC

Hello 

thats what i did.

        ej.Grid.Locale["de-DE"] = {
            EmptyRecord: "Keine Aufzeichnungen angezeigt",
            GroupDropArea: "Ziehen Sie eine Spaltenüberschrift hier",
            DeleteOperationAlert: "Keine Einträge für Löschvorgang ausgewählt",
            EditOperationAlert: "Keine Einträge für Bearbeiten Betrieb ausgewählt",
            SaveButton: "Speichern",
            CancelButton: "stornieren",
            EditFormTitle: "Korrektur von",
            GroupCaptionFormat: "{{:field}}: {{:key}} - {{:count}} {{if count == 1}}Material{{else}}Materialien{{/if}}",
            UnGroup: "Klicken Sie hier, um die Gruppierung aufheben"
        };

My excel output:

Coilnummer: Coil22 - 26  {{if count == 1}}Material{{else}}Materialien{{/if}s




SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 9, 2018 11:26 AM UTC

Hi Kamp,  
 
Thanks for contacting Syncfusion Support.  
 
Cause of the problem is Item has been replaced with the Material text in the GoupCaptionFormat. In order handle this kind of cases, we have provided the ServerExcelGroupCaptionInfo event for the Excel Exporting. Refer to the following code example.  
 

  @(Html.EJ().Grid<object>("FlatGrid") 
                                    .Datasource((IEnumerable<object>)ViewBag.DataSource) 
                                    .AllowPaging() 
                                    .AllowGrouping() 
                                      .ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items => 
                                      { 
                                          items.AddTool(ToolBarItems.ExcelExport); 
                                      })) 
                                    .Locale("de-DE") 
                       . .  
) 
</div> 
 
<script> 
    ej.Grid.Locale["de-DE"] = { 
                . . . 
                   . ..  
        GroupCaptionFormat: "{{:field}}: {{:key}} - {{:count}} {{if key == 1}}Material{{else}}Materialien{{/if}}", 
    }; 
 
 
</script> 
 
[CS] 

public class GridController : Controller 
    { 
        // 
        // GET: /Grid/ 
        public ActionResult GridFeatures() 
        { 
            var DataSource = new NorthwindDataContext().OrdersViews.ToList(); 
 
            ViewBag.datasource = DataSource; 
 
            return View(); 
 
        } 
        public void ExportToExcel(string GridModel) 
 
       { 
            GridExcelExport exp1 = new GridExcelExport(); 
            ExcelExport exp = new ExcelExport(); 
           var DataSource = new NorthwindDataContext().OrdersViews.ToList(); 
 
            GridProperties obj = (GridProperties)Syncfusion.JavaScript.Utils.DeserializeToModel(typeof(GridProperties), GridModel); 
            obj.ServerExcelGroupCaptionInfo = captioninfo; 
            exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
 
        } 
        protected void captioninfo(object obj) { 
            CaptionFormatEventArgs e = (CaptionFormatEventArgs)obj; 
 
            if((int)e.Context.Key == 1) 
            { 
                e.GroupCaptionTemplate = e.GroupedColum.Field + ":" + e.Context.Key + "-" + e.Context.Count + " Material"; 
 
            } 
            else 
                e.GroupCaptionTemplate = e.GroupedColum.Field + " :" + e.Context.Key + "-" + e.Context.Count + " Materialien"; 
 
        } 
    } 
} 
   

 
 
Regards,  
Seeni Sakthi Kumar S. 


Loader.
Up arrow icon