zoukankan      html  css  js  c++  java
  • 输出GridView到Word中编辑或打印

      通过Response对象输出数据,在输出的过程中设置输出的类型,从而实现将GridView控件中显示的数据导入到Word文档。

     protected void btnPut_Click(object sender, EventArgs e)
        {
            //添加HTTP头信息
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("report.doc", Encoding.UTF8).ToString());
            //修改输出流的MIME类型
            Response.ContentType = "application/ms-word";      
            this.EnableViewState = false;
            StringWriter tw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            GridView1.RenderControl(hw);
            Response.Write(tw.ToString());
            Response.End();
        }
    
    // 确认在运行时为制定的ASP.NET服务控件呈现<form id="form1" runat="server">标记
    public override void VerifyRenderingInServerForm(Control control) { }
  • 相关阅读:
    中国大陆地区用户请特别注意:请勿存放违反当地法律法规文件
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
  • 原文地址:https://www.cnblogs.com/chirifengye/p/2834073.html
Copyright © 2011-2022 走看看