如何将页面保存为excel文件?

解决方案 »

  1.   

    你的问题是不是有点矛盾啊,一个网页的页面怎么可能保存存为EXCEL文件呢,只有EXCEL 可以插入到网页中。
      

  2.   

    Response.Clear(); 
    Response.Buffer= true; 
    Response.Charset="GB2312";    
    Response.AppendHeader("Content-Disposition","attachment;filename=FileName.xls"); 
    Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
    Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
    this.EnableViewState = false;    
    System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); 
    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
    this.DataGrid1.RenderControl(oHtmlTextWriter); //此处改动一下即可
    Response.Write(oStringWriter.ToString());
    Response.End();
      

  3.   

    private void Button1_Click(object sender, System.EventArgs e)
    {
    this.Button1 .Dispose ();
    Response.ContentType = "application/vnd.ms-excel";

    Response.Charset = ""; //关闭 ViewState
    EnableViewState = false;
    System.IO.StringWriter tw = new System.IO.StringWriter();//将信息写入字符串
    System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);//在WEB窗体页上写出一系列连续的HTML特定字符和文本。
    //此类提供ASP.NET服务器控件在将HTML内容呈现给客户端时所使用的格式化功能
    //获取control的HTML
    this.DataGrid1.RenderControl (hw);//将DATAGRID中的内容输出到HtmlTextWriter对象中
    // 把HTML写回浏览器

    Response.Write(tw.ToString());
    Response.End();
    }
      

  4.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=8A4CBF47-B888-4832-3389-ED3A3A3C8AAB