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 to Excel

The data is the Grid is exporting to Excel with no problem.  My Grid data source is Dataset being populated from the backend database.
The exported data with columns headers are exported to Excel starting from A1.

I have two questions on that:

  1. How can I export data in Excel with columns headers from A3 instead of A1,
  2. How can I put a Report header Like 'Report Header' in excel at A1 and merge cells A1:H1. Also bold the report header
At the end the Exported Excel should like below image:

1 Reply

TS Thavasianand Sankaranarayanan Syncfusion Team March 30, 2017 05:09 PM UTC

Hi Munmun,  
Thanks for contacting Syncfusion support.  
We have analyzed your query and based on your requirement we have prepared a sample that can be downloaded from the below link.  
In this sample as per your requirement we have shown the header text in excel sheet at A1 and merge till D1. You can also merger it based on your purpose. Also we have shown the text in center position with Bold and we passed the grid header and rows starts at A3.  
Refer the code example.  
<ej:Grid ID="Grid" runat="server" AllowPaging="True"OnServerExcelExporting="Grid_ServerExcelExporting">  
        <ToolbarSettings ShowToolbar="true" ToolbarItems="excelExport"></ToolbarSettings>  
protected void Grid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)  
            ExcelExport exp = new ExcelExport();  
            ExcelEngine excel = new ExcelEngine();  
            IApplication application = excel.Excel;  
            IWorkbook workbook = application.Workbooks.Create(2);  
            workbook = exp.Export(Grid.Model, (IEnumerable)Grid.DataSource,"Export.xlsx", ExcelVersion.Excel2013, false, false, "default-theme", true);  
            workbook.ActiveSheet.InsertRow(1);    //inserted new row for adding title  
            workbook.ActiveSheet.InsertRow(2);     //inserted another row to display the rows and columns in A3  
            workbook.ActiveSheet.Range["A1:D1"].Merge();    //merger upto D1  
            workbook.ActiveSheet.Range["A1"].Text = "Excel Grid"; //displayed the text for the title  
            workbook.ActiveSheet.Range["A1"].CellStyle.Font.Bold = true //changed the font to bold  
            workbook.ActiveSheet.Range["A1"].CellStyle.HorizontalAlignment =ExcelHAlign.HAlignCenter;       //placed it in center position  
            workbook.SaveAs("Export.xls",HttpContext.Current.ApplicationInstance.Response, ExcelDownloadType.PromptDialog,ExcelHttpContentType.Excel2013);  

Refer the screenshot.  
Refer the documentation link.  
Please let us know if you need further assistance.  
Thavasianand S. 

Live Chat Icon For mobile
Up arrow icon