I have asp.net MVC app in c# and I get query results(from Entity Framework) and I need to put the data in Excel sheet which user can download. So this is what I am trying to do and I want to know how to write each row of data into excel sheet? Any other approach I should take is welcome too.
var certs = CertificateService.ReadAllSentCertificates();
Application excel = new Application();
string filePath = "C:/ToDoList/SentStats_" + DateTime.Now.ToString() + ".xls";
Workbook mybook = excel.Workbooks.Add();
excel.Visible = true;
try
{
mybook.Activate();
Worksheet mysheet = mybook.Worksheets.Add();
foreach (var x in certs)
{
// How to write each row in excel??
}
//mybook.SaveAs(Filename: filepath);
mybook.Save();
}
catch (Exception ex)
{
}
finally
{
mybook.Close();
}