dimanche 29 mars 2015

Export WebGrid data to Excel in MVC4

I want to export WebGrid data to excel with formatting.


I have written below code which export WebGrid data to Excel.



WebGrid grid = new WebGrid(source: listReport, canPage: false, canSort: false);

string gridData = grid.GetHtml(
columns: grid.Columns(
grid.Column("ID", "ID"),
grid.Column("Name", "Name"),
grid.Column("Summary", "Summary"),
grid.Column("Detail", "Detail"),
grid.Column("ProjectName", "Project Name")
)
).ToString();


Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=CustomerInfo.xls");
Response.ContentType = "application/excel";
Response.Write(gridData);
Response.End();


I want to do formatting in excel. Is it possible to export data with formatting?


Also it gives me below error when i open the generated excel


enter image description here


Aucun commentaire:

Enregistrer un commentaire