c# - How to Export Multiple Data Tables to Multiple Worksheets Inside a Single Excel File -
below c# code export single table data, need export 3 tables data 1 single excel file. need export multiple data tables multiple worksheets inside single excel file.
protected void lnkbtn_submit_click(object sender, eventargs e) { datetime fromdate = datetime.parseexact(txt_fromdate.text, "mm/dd/yyyy", cultureinfo.invariantculture); datetime todate = datetime.parseexact(txt_todate.text, "mm/dd/yyyy", cultureinfo.invariantculture); bo.dateused = fromdate; bo.dateused2 = todate; datatable dt = bl.get_registrationdetailsbydate(bo); gv_regdetails.datasource = dt; gv_regdetails.databind(); session["fromdate"] = txt_fromdate.text; session["todate"] = txt_todate.text; if (gv_regdetails.rows.count > 0) { session["registrationtable_date"] = dt; btnexport.visible = true; } else { session["registrationtable_date"] = null; btnexport.visible = false; } } protected void button1_click(object sender, imageclickeventargs e) { datagrid dg = new datagrid(); if (session["registrationtable_date"] != null) { dg.datasource = (datatable)session["registrationtable_date"]; dg.databind(); system.web.httpcontext.current.response.clear(); system.web.httpcontext.current.response.addheader("content-disposition", "attachment;filename=totalregistrationdetails.xls"); system.web.httpcontext.current.response.charset = ""; system.web.httpcontext.current.response.cache.setcacheability(httpcacheability.nocache); system.web.httpcontext.current.response.contenttype = "application/vnd.xls"; system.io.stringwriter stringwrite = new system.io.stringwriter(); system.web.ui.htmltextwriter htmlwrite = new htmltextwriter(stringwrite); dg.rendercontrol(htmlwrite); system.web.httpcontext.current.response.write(stringwrite.tostring()); system.web.httpcontext.current.response.end(); session.remove("registrationtable_date"); } } }
my stored procedure script:
alter procedure [dbo].[get_registrationdetailsbydate] ( @fromdate datetime, @todate datetime ) begin select name,email,mobile,submissiondate registration (convert(varchar(50), submissiondate, 101) between @fromdate , @todate) end
thank in advance.
you might take @ codeproject link, describes exporting dataset multiple excel sheets
http://www.codeproject.com/articles/31516/export-dataset-to-multiple-excel-sheets
the above link available in so question
please find so question on how create excel file using c#
Comments
Post a Comment