protected void ExportToExcel(string FileType, string FileName)
    {
        Response.Clear();
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.HeaderEncoding = System.Text.Encoding.Default;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        StringWriter tw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(tw);
        GridView1.AllowPaging = false;
        Bind();
        GridView1.RenderControl(htw);
        Response.Write(tw.ToString());
        Response.End();
        GridView1.AllowPaging = true;
        Bind();
    }
 protected void txt_Out_Click(object sender, EventArgs e)
    {
        if (GridView1.Rows.Count < 1)
        {
            Response.Write("<script>alert('沒有資料')</script>");
            return;
        }

        ExportToExcel("application/ms-excel", "Data.xls");
    }

 

相关文章:

  • 2021-07-25
  • 2021-09-20
  • 2022-02-16
  • 2021-09-12
  • 2021-09-25
  • 2022-02-04
  • 2021-07-18
猜你喜欢
  • 2021-12-18
  • 2021-09-04
  • 2021-11-30
  • 2021-11-18
  • 2022-02-27
  • 2022-12-23
  • 2021-09-06
相关资源
相似解决方案