Click here to Skip to main content
15,747,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

I need some guidance on how export data i gather from my model and export this to excel, without displaying it on my view. Basically i have a date to and from and when the user click on submit, i want to go fetch the data and bring it back to pre defined excel template

i am new to MVC and any guidance on this would be much appreciate

What I have tried:

Ok so i am using closexml, i have the data writing to excel ok, now my only query that i have now, i want to write the same data to a template that i have created, instead of writing to a blank template each time, can this be achieved?

public ActionResult ExportToExcel(string datepicker, string datepicker1)
           List<Checks_Records> getCheckRecords;

           var startDate = DateTime.Parse(datepicker).AddHours(7);
           var endDate = DateTime.Parse(datepicker1).AddHours(7);

           getCheckRecords = CheckRecords.GetListofRecordsForExcelReport(startDate, endDate);

           var gv = new GridView();
           gv.DataSource = getCheckRecords;
           Response.Buffer = true;
           Response.AddHeader("content-disposition", "attachment; filename=DemoExcel.xls");
           Response.ContentType = "application/ms-excel";
           Response.Charset = "";
           var objStringWriter = new StringWriter();
           var objHtmlTextWriter = new HtmlTextWriter(objStringWriter);

           return View("Report");
Updated 15-Nov-17 5:24am
Karthik_Mahalingam 15-Nov-17 9:03am    
i will go with closedxml- one of the best library for processing excel files
Member 11596389 15-Nov-17 9:04am    
Hey, can you used pre defined excel templates to write the data into.

Have you got any sample code of how this works?
Member 11596389 15-Nov-17 11:26am    
I Have made some changes to the question, basically i have the data writing to excel ok, but i want to write it to a specific template, can you advise?
Karthik_Mahalingam 15-Nov-17 11:29am    
show the template (screenshot)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900