请教个VB.net在ASP中的问题

chenhuan129cn 2019-08-07 12:22:29
有个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
}

}
...全文
65 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenhuan129cn 2019-08-07
  • 打赏
  • 举报
回复
已经解决了 Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Web Imports System.Web.UI.WebControls Partial Class _Default Inherits System.Web.UI.Page Private Sub ToExcel(ByVal ctl As Control, ByVal FileName As String) 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 Dim tw As System.IO.StringWriter = New System.IO.StringWriter() Dim hw As HtmlTextWriter = New HtmlTextWriter(tw) ctl.RenderControl(hw) HttpContext.Current.Response.Write(tw.ToString()) HttpContext.Current.Response.[End]() End Sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click gv.AllowPaging = False gv.AllowSorting = False gv.DataBind() ToExcel(gv, "JWTYBH.xls") gv.AllowPaging = True gv.AllowSorting = True gv.DataBind() End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub End Class
ManBOyyy 2019-08-07
  • 打赏
  • 举报
回复
http://converter.telerik.com/

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧