asp.net - What is the best way to create .xls from datatable in asp .Net c#? -
i have datatable , want export excel that, datatable contains unicode characters (persian characters) , want convert .xls files correctly. wonder possible stimulsoft?
this common method use
public void exportdetails(datatable tempdatatable, string filename) { try { system.io.stringwriter objstringwriter1 = new system.io.stringwriter(); system.web.ui.webcontrols.gridview gridview1 = new system.web.ui.webcontrols.gridview(); system.web.ui.htmltextwriter objhtmltextwriter1 = new system.web.ui.htmltextwriter(objstringwriter1); httpcontext.current.response.clearcontent(); httpcontext.current.response.clearheaders(); httpcontext.current.response.contenttype = "application/vnd.ms-excel"; httpcontext.current.response.charset = ""; httpcontext.current.response.addheader("content-disposition", "attachment;filename=" + filename); httpcontext.current.response.contentencoding = system.text.encoding.unicode; response.binarywrite(system.text.encoding.unicode.getpreamble()); gridview1.datasource = tempdatatable; gridview1.databind(); gridview1.headerstyle.font.bold = true; gridview1.headerstyle.backcolor = system.drawing.color.gray; gridview1.rendercontrol(objhtmltextwriter1); gridview1.dispose(); httpcontext.current.response.write(objstringwriter1.tostring()); httpcontext.current.response.end(); } catch (exception ex) { } }
Comments
Post a Comment