惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Cloudflare Blog
L
LangChain Blog
WordPress大学
WordPress大学
V
V2EX
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
Docker
Recent Announcements
Recent Announcements
GbyAI
GbyAI
博客园 - 叶小钗
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
雷峰网
雷峰网
The GitHub Blog
The GitHub Blog

博客园 - 泽来

java多线程---线程之间的通信 设计原则 适配器模式 java复习进程 java小点滴 转>java5.0新特性 面试题收集 我买的书 java编程思想中关于多态性的描述 javascipt正则表达式 - 泽来 - 博客园 javascript小代码 - 泽来 - 博客园 javascript高级教程 智力题收集 asp.net的TextBox回车触发事件 - 泽来 - 博客园 Builder生成器模式 单件模式(singleton) 是男人就坚持100下(强力益智,请留下战绩) XMLHTTP简介 - 泽来 - 博客园 多级无刷新联动(GB2312编码转换为UTF-8未取得满意效果) - 泽来 - 博客园
DataGrid数据在Execel中打开 - 泽来 - 博客园
泽来 · 2005-12-29 · via 博客园 - 泽来

public void ToExcel(System.Web.UI.Control ctl)  
        
{            
            HttpContext.Current.Response.AppendHeader(
"Content-Disposition","attachment;filename=DayReport.xls");
            HttpContext.Current.Response.Charset 
="UTF-8";                
            HttpContext.Current.Response.ContentEncoding 
=System.Text.Encoding.Default;
            HttpContext.Current.Response.ContentType 
="application/ms-excel";
            ctl.Page.EnableViewState 
=false;            
            System.IO.StringWriter  tw 
= new System.IO.StringWriter() ;
            System.Web.UI.HtmlTextWriter hw 
= new System.Web.UI.HtmlTextWriter (tw);
            ctl.RenderControl(hw);
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
        }

调用

ToExecel(DataGridName);

HttpContext.Current.Response.ContentType ="application/ms-excel";
HttpContext.Current.Response.AppendHeader(
"Content-Disposition","attachment;filename="+""+FileName+".xls");
System.IO.StringWriter  tw 
= new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw 
= new System.Web.UI.HtmlTextWriter(tw);
this.DataGrid1.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();