Dim cmd As New DataBean
Dim ds As New DataSet
Dim gvexcel As New GridView
Dim i As Integer
Dim str As String = "SQL语句"
cmd.ConnOracle()
ds = cmd.GetDataSet(str)
cmd.CloseConn()
gvexcel.DataSource = ds.Tables(0)
gvexcel.DataBind()
For i = 0 To gvexcel.Rows.Count - 1 Step 1
gvexcel.Rows(i).Attributes.Add("style", "vnd.ms-excel.numberformat:@;")
Next
''定义头部信息
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.AddHeader("Content-Disposition", "attachment;filename=CSU Shipping Part's Shipment Qty.xls")
Response.ContentEncoding = System.Text.Encoding.UTF8
Response.ContentType = "application/ms-excel"
''导出
Dim cultureInfo As New System.Globalization.CultureInfo("ZH-CN", True)
Dim strWriter As New System.IO.StringWriter(cultureInfo)
Dim htw As New HtmlTextWriter(strWriter)
gvexcel.RenderControl(htw)
Response.Output.Write(strWriter.ToString)
Response.Flush()
Response.End()
ds = Nothing
以上是导出的基本代码,你也可以根据自己的需求进行修改,总之让它属于自己的东东!