.net - How to format excel file cells when data exported from SQL Server database -
i'm exporting data have in database excel. although below code works fine, know how manipulate headers, colours, , way cells look?
page.aspx
<asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:connectionstring %>" selectcommand="select id, number, title, name requests"> <selectparameters> <asp:querystringparameter defaultvalue="" name="id" querystringfield="id" type="int32" /> </selectparameters> </asp:sqldatasource> <asp:detailsview id="detailsview1" runat="server" height="50px" width="125px" autogeneraterows="false" datakeynames="requestid" datasourceid="sqldatasource1"> <fields> <asp:boundfield datafield="id" headertext="id" sortexpression="id" insertvisible="false" readonly="true" /> <asp:boundfield datafield="number" headertext="number" sortexpression="number" /> <asp:boundfield datafield="title" headertext="title" sortexpression="title" /> <asp:boundfield datafield="name" headertext="name" sortexpression="name" />
page.aspx.vb
dim tw new system.io.stringwriter() dim hw new system.web.ui.htmltextwriter(tw) dim dggrid new detailsview() dggrid.datasource = sqldatasource1 hw.writeline("<b>title here</b>") dggrid.headerstyle.font.bold = true dggrid.databind() dggrid.rendercontrol(hw) response.addheader("content-disposition", "attachment;filename=reportouput.xls") response.contenttype = "application/vnd.ms-excel" me.enableviewstate = false response.write(tw.tostring()) response.end()
i use following set number format. search mso-number-format find more information.
string style = @" .text { mso-number-format:\@; } ";
Comments
Post a Comment