请教个VB.net在ASP中的问题
有个GRIDVIEW控件查询的数据导出EXCEL表,现在有C#的代码,想转成VB.net请大神给转下,C#代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
// <summary>
/// Excel数据导出函数
/// </summary>
/// <param name="ctl">需要导出数据的控件</param>
/// <param name="FileName">导出的Excel文件名</param>
private void ToExcel(Control ctl, string FileName)
{
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
gv.AllowPaging = false;//设置GridView控件不能分页
gv.AllowSorting = false;//设置GridView控件不能排序
gv.DataBind();
ToExcel(gv, "JWTYBH.xls");
gv.AllowPaging = true;//恢复GridView控件分页
gv.AllowSorting = true;//恢复GridView控件排序
gv.DataBind();//数据绑定函数
}
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for
}
}