在VB中如何实现使SQL Server数据库表中的数据导出为Excel等格式的数据文件?

来源:百度知道 编辑:UC知道 时间:2024/05/17 21:51:15
在VB中,要编程实现SQL Server数据库表的数据能导出为Excel等格式的数据文件,方便用户处理。

可以参考以下语句: 都比较简单

Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
int nCur = dgShow.CurrentPageIndex;
int nSize = dgShow.PageSize;

dgShow.AllowPaging = false;
BindData();

dgShow.Columns[7].Visible =false;
dgShow.RenderControl(hw);
dgShow.Columns[7].Visible =true;

//以下恢复分页
dgShow.AllowPaging = true;
dgShow.CurrentPageIndex = nCur;
dgShow.PageSize = nSize;
BindData();
Response.Write(sw.ToString());
Response.End();