c# - How to Export data into MS Excel from ASP.NET MVC -
this question has answer here:
- how export excel? 3 answers
i trying export data excel mvc. don't understand why;
public void downloadasexcelorderreports() { try { var list = _reportwork.getlist(); gridview gv = new gridview(); gv.datasource = list; gv.databind(); response.clearcontent(); response.buffer = true; response.contentencoding = system.text.encoding.utf32; response.addheader("content-disposition", "attachment; filename=marklist.xls"); response.contenttype = "application/ms-excel"; response.charset = ""; using (stringwriter sw = new stringwriter()) { using (htmltextwriter htw = new htmltextwriter(sw)) { gv.rendercontrol(htw); response.output.write(sw.tostring()); response.flush(); response.end(); } } } catch (exception ex) { } }
this code found online.i output this. has fill in table automatically excel.i can't see, missed.
gridview webcontrol. put data (databind) , emits html (rendercontrol) supposed sent browser , browser show table (tr , td tags).
in case you're trying show html code within excel document , makes no sense.
the best i've found use epplus, can nuget package manager. have tie data want excel doc like. it's bit fiddly there's no alternative.
Comments
Post a Comment