word excel 文件下载一个都不能少Public Class WebForm9
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim OleDbConnection1 As System.Data.OleDb.OleDbConnection
Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
Dim objTestLink As New DataSet()
Dim objtable As DataTable
Dim strcmd As String
Dim strconn As String
strconn = "Provider=SQLOLEDB.1;User ID=sa;pwd=freeme;Initial Catalog=Test;Data Source=QIYANG;"
strcmd = "SELECT * FROM Link "
OleDbConnection1 = New System.Data.OleDb.OleDbConnection(strconn)
OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter(strcmd, OleDbConnection1)
OleDbDataAdapter1.Fill(objTestLink, "Link")
DataGrid1.DataSource = objTestLink.Tables("Link").DefaultView
DataGrid1.DataBind() If Request.QueryString("bExcel") = "1" Then
Response.ContentType = "application/vnd.ms-excel"
'使用excel的界面打开网页
'Response.ContentType = "application/msword"
'使用word的界面打开网页
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False '下载文件
'Response.ContentType = "application/ms-word"
'Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
'Response.AppendHeader("Content-Disposition", "attachment;filename=filename.doc")
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw) ' Get the HTML for the control.
DataGrid1.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End() End If
End SubEnd Class你用winopen打开这个页面
这个是.aspx.vb的内容
aspx里面就一个datagride
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim OleDbConnection1 As System.Data.OleDb.OleDbConnection
Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
Dim objTestLink As New DataSet()
Dim objtable As DataTable
Dim strcmd As String
Dim strconn As String
strconn = "Provider=SQLOLEDB.1;User ID=sa;pwd=freeme;Initial Catalog=Test;Data Source=QIYANG;"
strcmd = "SELECT * FROM Link "
OleDbConnection1 = New System.Data.OleDb.OleDbConnection(strconn)
OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter(strcmd, OleDbConnection1)
OleDbDataAdapter1.Fill(objTestLink, "Link")
DataGrid1.DataSource = objTestLink.Tables("Link").DefaultView
DataGrid1.DataBind() If Request.QueryString("bExcel") = "1" Then
Response.ContentType = "application/vnd.ms-excel"
'使用excel的界面打开网页
'Response.ContentType = "application/msword"
'使用word的界面打开网页
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False '下载文件
'Response.ContentType = "application/ms-word"
'Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
'Response.AppendHeader("Content-Disposition", "attachment;filename=filename.doc")
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw) ' Get the HTML for the control.
DataGrid1.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End() End If
End SubEnd Class你用winopen打开这个页面
这个是.aspx.vb的内容
aspx里面就一个datagride
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货