User1724605321 posted
Hi ayushagarwal181,
You can also use the EPPlus package, which you can install via Nuget. It allows you to load data onto an Excel worksheet directly
from your datatable, and write back to client for downloading like :
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.Buffer = true;
response.Charset = "";
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
response.AddHeader("content-disposition", "attachment;filename=ExcelData.xlsx");
response.BinaryWrite(package.GetAsByteArray());
In mvc ,you can try below code sample :
https://stackoverflow.com/a/40523078/5751404
Or you can use OpenXml library :
https://www.aspsnippets.com/Articles/Create-and-download-Excel-file-in-ASPNet.aspx
Best Regards,
Nan Yu