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

推荐订阅源

I
Intezer
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
N
News | PayPal Newsroom
T
Tenable Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
P
Privacy International News Feed
IT之家
IT之家
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
博客园_首页
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
NISL@THU
NISL@THU
I
InfoQ
D
DataBreaches.Net
有赞技术团队
有赞技术团队
K
Kaspersky official blog
Security Latest
Security Latest
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic

博客园 - IT-民工

Sqlsever Kill locked process Linked Server Dependencies C# PDF添加水印 Excel Vlookup多条件查询 , 列转行 C# 编写ActiveX Microsoft.Office.Interop.Excel error: 80070005 C# Linq 分页查询模板 SQLServer 查询 Excel ISO 纸张尺寸定义 检测SQLSERVER 连接 刷新SQLserver 视图 Sql Server 邮件日志 操作 常用连接 Asp.net 多国语言-注意点 SqlServer 行列互转 SqlServer 备份数据库语法 SqlServer To SqlServer 建立 链接服务器 Linked Server sqlserver 根据内容,查询表和列名字 Sqlserver 2005 修改数据库默认排序
导出Excel
IT-民工 · 2012-08-27 · via 博客园 - IT-民工

直接代码:

        

public static void ExportExcel(GridView gv, HttpContext context)
        {
            gv.HeaderStyle.BackColor = System.Drawing.Color.FromArgb(2552550); //rgb(243, 243, 243)
            for (int i = 0; i < gv.Rows.Count; i++)
            {
                for (int j = 0; j < gv.Rows[i].Cells.Count; j++)
                {
                    gv.Rows[i].Cells[j].Attributes.Add("style""vnd.ms-excel.numberformat:@");
                }
            }
            HttpResponse resp = context.Response;
            resp.Charset = "GB2312";
            resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            string fileName = "ExportData.xls";
            if (string.IsNullOrEmpty(gv.ToolTip) == false) fileName = gv.ToolTip+".xls";
            resp.AppendHeader("Content-Disposition""attachment;filename=" +
                HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8).ToString());
            resp.ContentType = "application/ms-excel";
            StringWriter tw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            gv.RenderControl(hw); //输出结构
            string content = "<html><head><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\">";
            content += tw.ToString();
            content += "</body></html>";
            resp.Output.Write(content);
            resp.Flush();
            resp.End();
        } 

posted @ 2012-08-27 15:04  IT-民工  阅读(129)  评论()    收藏  举报