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

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - 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();
    }