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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid Export to Excel

Thread ID:

Created:

Updated:

Platform:

Replies:

129709 Mar 29,2017 08:04 PM UTC Mar 30,2017 05:09 PM UTC ASP.NET Web Forms 1
loading
Tags: Grid
MUNMUN GUHA
Asked On March 29, 2017 08:04 PM UTC

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:



Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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>  
        <Columns>  
                ...                 
            </Columns>  
        </ej:Grid>  
  
[Default.aspx.cs]  
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.  
 
Regards,  
Thavasianand S. 


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

;