將FormView,GridView匯出到word
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim name As String = "attachment;filename="
name += Request.QueryString("name") + ".doc"
Response.Clear()
Response.AddHeader("content-disposition", name)
Response.Charset = "UTF-8"
Response.ContentType = "application/vnd.ms-word"
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
FormView1.RenderControl(htmlWrite) '<--非GridView1請更改為要輸出名稱
Response.Write(stringWrite.ToString)
Response.End()
End Sub
留言列表