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

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - jenner

js 更改 onclick 事件 - jenner js 去除字符串中重复的字符 - jenner - 博客园 js 获取选中的checkbox的行的其他值 javactript关闭窗体,刷新父窗体....... - jenner - 博客园 js实现动态级联计分,级数无限制 - jenner - 博客园 winform dgv右键选择 - jenner - 博客园 DataGrid 二维表头 javascript 对datagrid的一些操作 - jenner - 博客园 DataView 属性操作 - jenner - 博客园 javascript 判断整数 javascript控制服务器控件-js操作CheckBoxList实现全选、反选 css控制字数(控制宽度) 网站变黑白 漂浮div窗体,带停止 111 test 使用QuickCHM软件轻松编译CHM格式的文件 遍历treeView的所有节点 TreeView第三种状态的另类实现
DataGrid导出到Excel or word
jenner · 2008-07-23 · via 博客园 - jenner

 //表头
   string strTitle = this.LiteralTitle.Text;
   //年月
   string strYearMonth = this.LiteralDate.Text;
   //填报人
   string strUserInfo = this.LiteralUserInfo.Text;
   Response.Clear();
          Response.Buffer = true;
          Response.Charset = "GB2312";   
   Response.AppendHeader("Content-Disposition", "online;filename=" + strYearMonth + strTitle + ".xls");
          Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");        
   Response.ContentType = "application/ms-excel";

   //关闭 ViewState
   this.EnableViewState = false ;
   System.IO.StringWriter tw = new System.IO.StringWriter();

   System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);
   //获取control的HTML
   dgrdList.RenderControl(hw);
   //把HTML写回浏览器
   
   StringBuilder html = new StringBuilder();
   html
    .Append("<table cellspacing = \"0\" border = \"1\" >")
    .Append("<tr align = Center style = \"height:24px;\"><td colSpan=\""+ ViewState["DgrdCellCount"].ToString() +"\">"+ strTitle +"</td></tr>")
    .Append("<tr align = Center style = \"height:24px;\"><td colSpan=\""+ ViewState["DgrdCellCount"].ToString() +"\">"+ strYearMonth +"</td></tr>")
    .Append("<tr align = left style = \"height:24px;\"><td colSpan=\""+ ViewState["DgrdCellCount"].ToString() +"\">"+ strUserInfo +"</td></tr>")
    .Append("</table>");
   Response.Write(html.ToString() + tw.ToString());
   Response.End();

----------------------------------------------------------------

from:http://www.zxbc.cn/html/20080516/34394.html

protected void btnToExcel_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.BufferOutput = true;
        //设定输出的字符集
        Response.Charset = "GB2312";
        //假定导出的文件名为FileName.xls
        Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        //设置导出文件的格式
        Response.ContentType = "application/ms-excel";
        //关闭ViewState
        EnableViewState = false;
        System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
        System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
        System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
        gvPersonList.RenderControl(textWriter);
        //把HTML写回浏览器
        Response.Write(stringWriter.ToString());
        Response.End();
    }
    //导出成Word文件
    protected void btnToWord_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.BufferOutput = true;
        //设定输出的字符集
        Response.Charset = "GB2312";
        //假定导出的文件名为FileName.doc
        Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.doc");
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        ////设置导出文件的格式
        Response.ContentType = "application/ms-word";
        //关闭ViewState
        gvPersonList.EnableViewState = false;
        System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
        System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
        System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
        gvPersonList.RenderControl(textWriter);
        // //把HTML写回浏览器
        Response.Write(stringWriter.ToString());
        Response.End();
    }