将datagrid的数据源到出导excel
点击次数:23 次 发布日期:2008-11-06 08:10:52 作者:源代码网
|
"first let"s clean up the response.object response.Clear() response.Charset = "" "set the response mime type for excel response.ContentType = "application/vnd.ms-excel" "create a string 网络 Dim stringWrite As New System.IO.StringWriter "create an htmltext网络 which uses the string网络 Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite) "instantiate a datagrid Dim dg As New System.Web.UI.WebControls.DataGrid "set the datagrid datasource to the dataset passed in dg.DataSource = ds.Tables(0) "bind the datagrid dg.DataBind() "tell the datagrid to render itself to our htmltext网络 dg.RenderControl(htmlWrite) "all that"s left is to output the html response.Write(stringWrite.ToString) response.End() End Sub 源代码网推荐 源代码网供稿. |
