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

推荐订阅源

月光博客
月光博客
Martin Fowler
Martin Fowler
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog
O
OpenAI News
云风的 BLOG
云风的 BLOG
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
V
Vulnerabilities – Threatpost
P
Privacy & Cybersecurity Law Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
博客园 - 三生石上(FineUI控件)
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News | PayPal Newsroom
The Register - Security
The Register - Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cisco Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Vercel News
Vercel News
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
S
Security Affairs
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
T
Tor Project blog
大猫的无限游戏
大猫的无限游戏
L
Lohrmann on Cybersecurity
aimingoo的专栏
aimingoo的专栏
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 【当耐特】
V
V2EX
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
LINUX DO - 最新话题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Schneier on Security
Schneier on Security
小众软件
小众软件
PCI Perspectives
PCI Perspectives

博客园 - 搞IT的狐狸

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

// 注意,在Visual Studio2005平台下,如果使用GridView导出文件,

        //就必须重载VerifyRenderingInServerForm方法

        public override void VerifyRenderingInServerForm(Control control)

        {

        }

        /// <summary>

        ///  导出到文件的方法,

        /// </summary>

        /// <param name="Model">Model=1:导出为ExeclModel=2:导出为Word</param>

        private void toFiles(int Model)

        {

            string strFileName = DateTime.Now.ToString("yyyyMMdd-hhmmss");

            System.Web.HttpContext HC = System.Web.HttpContext.Current;

             HC.Response.Clear();

             HC.Response.Buffer = true;

             HC.Response.ContentEncoding = System.Text.Encoding.UTF8;//设置输出流为简体中文

            if (Model == 1)

            {

                //---导出为Excel文件

                 HC.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8) + ".xls");

                 HC.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。

            }

            else

            {

                //--- 导出为Word文件

                 HC.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8) + ".doc");

                 HC.Response.ContentType = "application/ms-word";//设置输出文件类型为Word文件。

            }

            System.IO.StringWriter sw = new System.IO.StringWriter();

            System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);

            this.GridView1.RenderControl(htw);

             HC.Response.Write(sw.ToString());

             HC.Response.End();

        }

        //-导出为Excel文件

        protected void ToExecl_Click(object sender, EventArgs e)

        {

            toFiles(1);

        }

        //-导出为Word文件

        protected void Button1_Click(object sender, EventArgs e)

        {

            toFiles(2);

        }