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

推荐订阅源

Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
D
Darknet – Hacking Tools, Hacker News & Cyber Security
V2EX - 技术
V2EX - 技术
Security Archives - TechRepublic
Security Archives - TechRepublic
Cisco Talos Blog
Cisco Talos Blog
T
Tor Project blog
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
宝玉的分享
宝玉的分享
小众软件
小众软件
博客园_首页
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Spread Privacy
Spread Privacy
I
InfoQ
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
M
MIT News - Artificial intelligence
爱范儿
爱范儿
The Cloudflare Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Tenable Blog
S
Securelist
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
Webroot Blog
Webroot Blog
The Hacker News
The Hacker News
O
OpenAI News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
C
CERT Recently Published Vulnerability Notes
PCI Perspectives
PCI Perspectives
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Threat Research - Cisco Blogs
L
LINUX DO - 热门话题
I
Intezer
Scott Helme
Scott Helme
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cybersecurity and Infrastructure Security Agency CISA
Google Online Security Blog
Google Online Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Security Affairs
AI
AI
AWS News Blog
AWS News Blog
Security Latest
Security Latest

博客园 - joyous jeny

Log4Net advanced pattern tips SQLServer的TDE加密 Forrest Gump frontend learning site JDK JRE区别 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 转:jQuery设计思想 marked ASP.NET 页面对象模型 3种方法从Html中取文本 图片的存取 WebResource - joyous jeny - 博客园 让DropDownlist显示ToolTip(两部分) - joyous jeny - 博客园 Tech tips(回发、显示名称、DataView过滤前10条记录) - joyous jeny ASP脚本里加事务 Make a mark of Gates .net 20 callback example 比较经典的日期判断 - joyous jeny - 博客园
导出Datagrid里所有数据到excel - joyous jeny - 博客园
joyous jeny · 2008-06-16 · via 博客园 - joyous jeny

    /// <summary>
    /// 导出Datagrid里所有数据到Office
    /// </summary>
    /// <param name="oGridView">要导出的DataGrid</param>
    /// <param name="oBindDataSet">DataGrid的数据源</param>
    public void ExportDataGridToExcel(GridView oGridView, DataSet oBindDataSet)
    {
        oGridView.AllowPaging = false;   //设置不能分页
        oGridView.DataSource = oBindDataSet.Tables[0].DefaultView;  //重新绑定数据源
        oGridView.DataBind();

        //常规导出方法
        System.IO.StringWriter SW = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter HTW = new System.Web.UI.HtmlTextWriter(SW);
        oGridView.RenderControl(HTW);

        //Page为要导出的对象,当前是Page,如果是DataGrid,DataList等都可以
        Response.Buffer = true;
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.ContentType = "application/vnd.ms-excel";
        //Response.ContentType是输出流的 HTTP MIME 类型
        //Response.ContentType     --- word文件
        //application/vnd.ms-excel --- excel文件
        //...
        Response.Charset = "utf-8";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
        Response.AddHeader("Content-Disposition", "attachment;filename=QueryCustomer.xls");
        //attachment --- 作为附件下载
        //inline --- 在线打开
        //filename如过是中文,则可以用HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8)
        //进行进行编码,以解决文件名乱码的问题
        Response.Write(SW.ToString());
        Response.Flush();
        Response.Close();
    }