请问如何将页面保存为excel文件? 如何将页面保存为excel文件? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的问题是不是有点矛盾啊,一个网页的页面怎么可能保存存为EXCEL文件呢,只有EXCEL 可以插入到网页中。 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(); 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();} http://dotnet.aspx.cc/ShowDetail.aspx?id=8A4CBF47-B888-4832-3389-ED3A3A3C8AAB 问个简单的问题 谁用过VS2008,不知道那个怎么样! 验证控件的问题 用IP访问asp.net程序,网站没法使用!求救! 如何在html代码视图中写asp.net代码? 讨论:用VS2003开发网站,关于布局的最佳方式 DataSet插入问题!!急啊! 百分求教:treeview只展开到第二层的问题? discuz nt的项目设置问题 关于不规则表格显示数据的问题,请高手们看看! 一个奇怪问题,同时我的描述也是对有志于成为项目经理们的一个小小的考验——打开新窗口对图片格式的数据无效! 在TABLE的SELECT条件中,如何实现单字节筛选?
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();
{
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();
}