第一步,给页面上的gridview赋数据源,然后调用下面方法

public void outExcel()
        {
            string name = returnName();

            string style = @"<style>.text{mso-number-format:\@;}</style>";

            Response.ClearContent();

            Response.Buffer = true;
            Response.Charset = "gb2312";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

            Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(name, System.Text.Encoding.UTF8) + ".xls");

            Response.ContentType = "application/excel";

            StringWriter sw = new StringWriter();

            HtmlTextWriter htw = new HtmlTextWriter(sw);

            GridView1.RenderControl(htw);

            Response.Write(style);

            Response.Write(sw.ToString());

            Response.End();
        }

相关文章:

  • 2021-12-08
  • 2021-06-11
  • 2021-05-19
  • 2021-09-10
  • 2022-01-28
  • 2021-12-12
  • 2021-12-12
猜你喜欢
  • 2021-10-13
  • 2021-05-15
  • 2021-06-05
  • 2021-11-25
  • 2021-08-23
  • 2022-12-23
相关资源
相似解决方案