Madhav Sharma

Madhav Sharma

  • 889
  • 899
  • 39.3k

How to export the web grid data in excel in formatted manner

Nov 24 2017 6:07 AM
How to export the web grid data in excel with formatted manner
 
After importing excel data is not coming in formatted manner
  1. WebGrid grid = new WebGrid(model.TicketReportDataModel, rowsPerPage: model.PageSize, canPage: true);  
  2. string gridData = grid.GetHtml(  
  3. columns: grid.Columns(  
  4. grid.Column(columnName: "ticketNo", header: "Ticket No", canSort: false),  
  5. grid.Column(columnName: "Summary", header: "Title", canSort: false),  
  6. grid.Column(columnName: "Contact_Name", header: "Contact", canSort: false),  
  7. grid.Column(columnName: "SR_Status", header: "Status", canSort: false),  
  8. grid.Column(columnName: "Site_Name", header: "Site Name", canSort: false),  
  9. grid.Column(columnName: "SR_Type_Description", header: "Type", canSort: false),  
  10. grid.Column(columnName: "Company", header: "Company", canSort: false),  
  11. grid.Column(columnName: "Board", header: "Board", canSort: false),  
  12. grid.Column(columnName: "Discussion", header: "Discussion", canSort: false),  
  13. grid.Column(columnName: "Resolution", header: "Resolution", canSort: false),  
  14. grid.Column(columnName: "SubType_Description", header: "SubType", canSort: false),  
  15. grid.Column(columnName: "Date_Entered", header: "Date Entered", canSort: false))).ToString();  
  16. //ExcelPackage pk = new ExcelPackage();  
  17. Response.ClearContent();  
  18. Response.AddHeader("content-disposition""attachment; filename=TicketList.xls"); //Response.ContentType = "applicatiom/vnd.ms-excel";  
  19. Response.ContentType = "application/octet-stream";  
  20. Response.Write(gridData);  
  21. Response.End();

Answers (1)