<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); } |