需导入using System.Text;在以下按钮单击事件中实现:private void Button1_Click(object sender, System.EventArgs e)
{
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "inline;filename="
+ HttpUtility.UrlEncode("下载文件.xls",Encoding.UTF8 ) );
//如果输出为Word,修改为以下代码
//Response.ContentType = "application/ms-word"
//Response.AddHeader("Content-Disposition", "inline;filename=test.doc")
StringBuilder sb=new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
sb.Append("<html><body>");
DataGrid1.RenderControl(hw);
sb.Append("</body></html>");
Response.Write(sb.ToString());
Response.End();
}
请大家帮帮忙!!谢谢大家了
{
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "inline;filename="
+ HttpUtility.UrlEncode("下载文件.xls",Encoding.UTF8 ) );
//如果输出为Word,修改为以下代码
//Response.ContentType = "application/ms-word"
//Response.AddHeader("Content-Disposition", "inline;filename=test.doc")
StringBuilder sb=new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
sb.Append("<html><body>");
DataGrid1.RenderControl(hw);
sb.Append("</body></html>");
Response.Write(sb.ToString());
Response.End();
}
请大家帮帮忙!!谢谢大家了
解决方案 »
- 给位,请问Global.asax文件可不可以调用BLL(业务逻辑层)层里面的方法啊?
- asp.net(vb)中如何使用支付宝接口
- 求一个简单的正则表达式!!!
- datagird最下面一行实现个统计怎么做?
- VS2005+ASP.NET 2.0开发的网站,为什么总是提示"连接到SQL2005出错",但我实际上是要连到SQL2000
- 请高手推荐vb.net写的提供源码的中文的bbs!
- dataset绑定gridview
- 郁闷啊!本地能浏览、操作一切正常,上传到空间时就不行了!!!
- 逼上梁山了,倾家荡产求助
- 点击CheckBox时如何使服务器Table的某行换色
- ASP.NET中怎样弹出保存对话窗口
- 如何随机取出一条数据行
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Buffer = true;
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
string FileNames = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileNames);
Response.ContentType = "application/ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
这个是我的导出excel
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");没错
再BS下楼主
搞定了也应该给分啊~!
最少证明下人家的劳动成果吧~!