http://www.google.cn/search?client=aff-cs-worldbrowser&forid=1&ie=utf-8&oe=UTF-8&hl=zh-CN&q=%E6%80%8E%E6%A0%B7%E5%B0%86DataGrid%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5Excel%E4%B8%AD+
解决方案 »
- *height:110px; min-height:110px; 加个星花有什么作用啊
- ASP.NET web打印时去掉IE的页眉和页脚
- 才开始学习三层架构时,数据库连接这地方出错了!。。。。
- GRIDVIEW高级篇
- WebHtmlEditor 1.7图片上传的方式问题,急啊,求大家帮助
- 客户端关闭浏览器之后Session自动变为空吗?
- 动态生成checkbox再获取值的问题?
- 在Asp中用Server.CreateObject建立的对象 现用 C# 怎么建立 呀?
- 问一个路径转换的问题
- 散分,熟悉asp.net书籍的请进,不够再加分。
- asp.net 配置出错?
- ASP.Net(C#),请大家介绍好的画图控件或是开源代码!!
{
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.ContentEncoding=System.Text.Encoding.GetEncoding("UTF-8");//设置输出流为简体中文
Response.AppendHeader("Content-Disposition","attachment;filename=test.xls");
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 this.EnableViewState = false;
CultureInfo myCItrad = new CultureInfo("ZH-CN",true);
HtmlGenericControl div=new HtmlGenericControl();
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
div.InnerHtml = oStringWriter.ToString();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
// 下载页面显示的
DataGrid1.RenderControl(oHtmlTextWriter); // LZ 注意此处DataGrid1
div.InnerHtml =oStringWriter.ToString();
Response.Write(div.InnerText);
Response.End();
}
catch( Exception ex)
{
MsgBox("",ex.Message);
}
MsgBox是我自己写的一个类,用于弹出对话框.
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
string FileName = "XXXX.xls";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.UTF8Encoding.UTF8).ToString());
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-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(); }有点要注意,DG不能带分页和按钮列,建议最好重新绑定个不带分页和按钮列的DG导入