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

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security
N
News and Events Feed by Topic
量子位
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
Hugging Face - Blog
Hugging Face - Blog
S
Security Affairs
J
Java Code Geeks
Schneier on Security
Schneier on Security
Google Online Security Blog
Google Online Security Blog
TaoSecurity Blog
TaoSecurity Blog
小众软件
小众软件
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
博客园 - 聂微东
T
Tor Project blog
博客园 - Franky
C
CERT Recently Published Vulnerability Notes
Cyberwarzone
Cyberwarzone
罗磊的独立博客
博客园_首页
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
腾讯CDC
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
博客园 - 【当耐特】
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
博客园 - 司徒正美
AWS News Blog
AWS News Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
G
GRAHAM CLULEY
V
V2EX
L
LINUX DO - 最新话题
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家

博客园 - 搞IT的狐狸

ASP.Net动态使用CSS - 搞IT的狐狸 - 博客园 [转载]ROW_NUM实现分页 (转载)ASP.NET本地化 VS2005 TreeView 的 CheckBox 被点击时的引发页面回发事件 (转发) ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件) 什么是SHTML 如何使用IFRAM JS来刷新UpdatePanel 随即验证码实现(根据韩现龙代码修改) [北京]招聘 网站设计师 我这半个月的代码总结(小技巧,小代码)之二 我这半个月的代码总结(小技巧,小代码)之一 用Themes实现网站换肤 将数据控件(如GridView)的内容转化成Excel格式文件 ASP.NET新手实用技巧!(C#) 学历不高!写给自己!自勉! 一张笑死我又让我辛酸的图片!开发人员的辛酸! 服务器刚开,凑个沙发!.NET几点你应该知道的细节! 求动态绑定控件ID的值的方法!着急!
SqlDataReader或DATATABLE DATASET 到EXCEL
搞IT的狐狸 · 2008-06-17 · via 博客园 - 搞IT的狐狸

 public void GetExcel(System.Data.SqlClient.SqlDataReader dtData)
    {
        System.Web.UI.WebControls.GridView dgExport = null;
        // 当前对话
        System.Web.HttpContext curContext = System.Web.HttpContext.Current;
        // IO用于导出并返回excel文件
        System.IO.StringWriter strWriter = null;
        System.Web.UI.HtmlTextWriter htmlWriter = null;

        if (dtData != null)
        {
            // 设置编码和附件格式
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.GetEncoding("gb2312");

            curContext.Response.ContentType = "application/vnd.ms-excel";
            curContext.Response.AppendHeader("Content-Disposition", "attachment;filename=" +Session["Project_Id"]+ "项目名单.xls"); //定义输出文件和文件名
            curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;

            System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;

            curContext.Response.Charset = "";

            // 导出excel文件
            strWriter = new System.IO.StringWriter();
            htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);

            dgExport = new System.Web.UI.WebControls.GridView();
            dgExport.DataSource = dtData;
            dgExport.AllowPaging = false;
            dgExport.DataBind();

            dgExport.RenderControl(htmlWriter);
            curContext.Response.Write(strWriter.ToString());
            curContext.Response.End();
        }


    }