如何将girdview导入execl??

来源:百度知道 编辑:UC知道 时间:2024/06/10 04:34:21
如题,请大家给些代码,网上有些多代码,但是我看不懂,大家给代码的时候能加点注释。
谢谢,不过那个execl文件默认是放在哪里的呢?
那保存路径是怎么写的呢?

private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView2.RenderControl(hw);(这里的GridView2换成你的girdview的名字)
Response.Write(tw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "审计费付费清单.xls");
}
全部代码.就上面的注释和按钮那里注意下,剩下的复制进去就